<commit_before>//
//  CalendarAPI.swift
//  PennMobile
//
//  Created by <NAME> on 11/16/18.
//  Copyright © 2018 PennLabs. All rights reserved.
//

import Foundation
import SwiftyJSON

class CalendarAPI: Requestable {
    
    static let instance = CalendarAPI()
    private init() {}
    
    let calendarUrl = "https://api.pennlabs.org/calendar/"
    
    var calendarEvents: [CalendarEvent]?
    
    func fetchCalendar(_ completion: @escaping (_ events: [CalendarEvent]?) -> Void) {
        
        getRequest(url: calendarUrl) { (dict, _, _) in
            guard let dict = dict else {
                completion(nil)
                return
            }
            let json = JSON(dict)
            if let jsonArray = json["calendar"].array {
                var events = [CalendarEvent]()
                for json in jsonArray {
                    let name = json["name"].stringValue

                    //set time to 6 am EST
                    let start = "\(json["start"].stringValue) 6:00 AM"
                    let end = "\(json["end"].stringValue) 6:00 AM"
                    
                    let dateFormatter = DateFormatter()
                    dateFormatter.dateFormat = "yyyy-MM-dd h:mm a"
                    dateFormatter.timeZone = TimeZone(abbreviation: "EST")

                    let startDate = dateFormatter.date(from: start)!
                    let endDate = dateFormatter.date(from: end)!
                    
                    let event = CalendarEvent(name: name, start: startDate, end: endDate)
                    events.append(event)
                }
                self.calendarEvents = events
                completion(events)
            }
        }
    }

}<commit_msg>Fixed bug caused by date parsing<commit_after>//
//  CalendarAPI.swift
//  PennMobile
//
//  Created by <NAME> on 11/16/18.
//  Copyright © 2018 PennLabs. All rights reserved.
//

import Foundation
import SwiftyJSON

class CalendarAPI: Requestable {
    
    static let instance = CalendarAPI()
    private init() {}
    
    let calendarUrl = "https://api.pennlabs.org/calendar/"
    
    var calendarEvents: [CalendarEvent]?
    
    func fetchCalendar(_ completion: @escaping (_ events: [CalendarEvent]?) -> Void) {
        
        getRequest(url: calendarUrl) { (dict, _, _) in
            guard let dict = dict else {
                completion(nil)
                return
            }
            let json = JSON(dict)
            if let jsonArray = json["calendar"].array {
                var events = [CalendarEvent]()
                for json in jsonArray {
                    let name = json["name"].stringValue

                    //set time to 6 am EST
                    let start = "asdf\(json["start"].stringValue) 6:00 AM"
                    let end = "\(json["end"].stringValue) 6:00 AM"
                    
                    let dateFormatter = DateFormatter()
                    dateFormatter.dateFormat = "yyyy-MM-dd h:mm a"
                    dateFormatter.timeZone = TimeZone(abbreviation: "EST")

                    if let startDate = dateFormatter.date(from: start),
                       let endDate = dateFormatter.date(from: end) {
                        let event = CalendarEvent(name: name, start: startDate, end: endDate)
                        events.append(event)
                    }
                    

                }
                self.calendarEvents = events
                completion(events)
            }
        }
    }

}
{'fraction_non_alphanumeric': 0.0982626032469382, 'fraction_numerical': 0.00968385075477072, 'mean_word_length': 1.4104323953328757, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3863371', 'n_tokens_mistral': 965, 'n_tokens_neox': 869, 'n_words': 236}