<commit_before>//
//  NSDate+RFC3339Extention.swift
//  KVLArounder
//
//  Created by <NAME> on 9/18/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

public extension NSDate
{
    
    //This is most common format
    private static var RFC3339DateFormat1 = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'";
    private static var RFC3339DateFormat2 = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ms'Z'";
    private static var RFC3339DateFormat3 = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'-'HH':'mm'";
    
    private class func getRFC3339DateFormatter(format: String) -> NSDateFormatter
    {
        let enUSPOSIXLocale: NSLocale? = NSLocale(localeIdentifier: "en_US_POSIX")
        assert(enUSPOSIXLocale != nil, "enUSPOSIXLocale must not be nil")
        
        let dateFormatter:NSDateFormatter? = NSDateFormatter()
        assert(dateFormatter != nil, "dateFormatter must not be nil")
        
        dateFormatter!.locale = enUSPOSIXLocale;
        dateFormatter!.dateFormat = format
        dateFormatter!.timeZone = NSTimeZone(forSecondsFromGMT:0);
        
        return dateFormatter!;
    }
    
    
    
    // Returns a user-visible date time string that corresponds to the
    // specified RFC 3339 date time string. Note that this does not handle
    // all possible RFC 3339 date time strings, just some of the most common
    // styles.
    @objc
    public class func userVisibleDateFromRFC3339DateTimeString(rfc3339DateTimeString: String!) -> NSDate?
    {
        let format1Date = getRFC3339DateFormatter(RFC3339DateFormat1).dateFromString(rfc3339DateTimeString);
        if (format1Date != nil)
        {
            return format1Date
        }
        
        let format2Date = getRFC3339DateFormatter(RFC3339DateFormat2).dateFromString(rfc3339DateTimeString);
        if (format2Date != nil)
        {
            return format2Date
        }
        return getRFC3339DateFormatter(RFC3339DateFormat3).dateFromString(rfc3339DateTimeString);
    }
    
    
    
    
    @objc
    public class func userVisibleDateTimeStringForRFC3339FromDate(date: NSDate!) -> String!
    {
        return getRFC3339DateFormatter(RFC3339DateFormat1).stringFromDate(date)
    }
    
    
    
    @objc
    public class func userVisibleStringForRFC3339FromCurrentDate() -> String!
    {
        return NSDate.userVisibleDateTimeStringForRFC3339FromDate(NSDate())
    }
}<commit_msg>Changed NSDate to accept and return nullables<commit_after>//
//  NSDate+RFC3339Extention.swift
//  KVLArounder
//
//  Created by <NAME> on 9/18/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

public extension NSDate
{
    
    //This is most common format
    private static var RFC3339DateFormat1 = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'";
    private static var RFC3339DateFormat2 = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ms'Z'";
    private static var RFC3339DateFormat3 = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'-'HH':'mm'";
    
    private class func getRFC3339DateFormatter(format: String) -> NSDateFormatter
    {
        let enUSPOSIXLocale: NSLocale? = NSLocale(localeIdentifier: "en_US_POSIX")
        assert(enUSPOSIXLocale != nil, "enUSPOSIXLocale must not be nil")
        
        let dateFormatter:NSDateFormatter? = NSDateFormatter()
        assert(dateFormatter != nil, "dateFormatter must not be nil")
        
        dateFormatter!.locale = enUSPOSIXLocale;
        dateFormatter!.dateFormat = format
        dateFormatter!.timeZone = NSTimeZone(forSecondsFromGMT:0);
        
        return dateFormatter!;
    }
    
    
    
    // Returns a user-visible date time string that corresponds to the
    // specified RFC 3339 date time string. Note that this does not handle
    // all possible RFC 3339 date time strings, just some of the most common
    // styles.
    @objc
    public class func userVisibleDateFromRFC3339DateTimeString(rfc3339DateTimeString: String?) -> NSDate?
    {
        if (rfc3339DateTimeString == nil)
        {
            return nil;
        }
        let format1Date = getRFC3339DateFormatter(RFC3339DateFormat1).dateFromString(rfc3339DateTimeString!);
        if (format1Date != nil)
        {
            return format1Date
        }
        
        let format2Date = getRFC3339DateFormatter(RFC3339DateFormat2).dateFromString(rfc3339DateTimeString!);
        if (format2Date != nil)
        {
            return format2Date
        }
        return getRFC3339DateFormatter(RFC3339DateFormat3).dateFromString(rfc3339DateTimeString!);
    }
    
    
    
    
    @objc
    public class func userVisibleDateTimeStringForRFC3339FromDate(date: NSDate?) -> String?
    {
        if (date == nil)
        {
            return nil;
        }
        return getRFC3339DateFormatter(RFC3339DateFormat1).stringFromDate(date!)
    }
    
    
    
    @objc
    public class func userVisibleStringForRFC3339FromCurrentDate() -> String?
    {
        let currentDate: NSDate? = NSDate();
        if (currentDate == nil)
        {
            return nil;
        }
        return NSDate.userVisibleDateTimeStringForRFC3339FromDate(currentDate!)
    }
}
{'fraction_non_alphanumeric': 0.09760878087024696, 'fraction_numerical': 0.04586436691493532, 'mean_word_length': 2.6765129682997117, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '2767748', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1558, 'n_words': 333}