<commit_before>//
//  NSDateTransformer.swift
//  StockX
//
//  Created by <NAME> on 11/18/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public class NSDateTransformer: Transformer<NSDate, String> {
    
    public typealias ObjectType = NSDate
    public typealias JSONType = Any
    
    public enum DateFormat: String {
        case ISO8601Full    = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
        case RSS            = "EEE, d MMM yyyy HH:mm:ss ZZZ"
        case AltRSS         = "d MMM yyyy HH:mm:ss ZZZ"
        case Extended       = "eee dd-MMM-yyyy GG HH:mm:ss.SSS ZZZ"
    }
    
    let formatter: NSDateFormatter
    
    public init(format: String? = DateFormat.ISO8601Full.rawValue) {
        self.formatter = NSDateFormatter()
        formatter.dateFormat = format
        //formatter.dateFormat = "yyyyy-MM-dd HH:mm:ss"
        formatter.timeZone = NSTimeZone(name: "UTC")
    }
    
    public override func toObject(from: String?) throws -> NSDate {
        
        if let value = from {
            if let date = self.formatter.dateFromString(value) {
                return date
            }
        }<commit_msg>Guard against a bad unwrap.<commit_after>//
//  NSDateTransformer.swift
//  StockX
//
//  Created by <NAME> on 11/18/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public class NSDateTransformer: Transformer<NSDate, String> {
    
    public typealias ObjectType = NSDate
    public typealias JSONType = Any
    
    public enum DateFormat: String {
        case ISO8601Full    = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
        case RSS            = "EEE, d MMM yyyy HH:mm:ss ZZZ"
        case AltRSS         = "d MMM yyyy HH:mm:ss ZZZ"
        case Extended       = "eee dd-MMM-yyyy GG HH:mm:ss.SSS ZZZ"
    }
    
    let formatter: NSDateFormatter
    
    public init(format: String? = DateFormat.ISO8601Full.rawValue) {
        self.formatter = NSDateFormatter()
        formatter.dateFormat = format
        formatter.timeZone = NSTimeZone(name: "UTC")
    }
    
    public override func toObject(from: String?) throws -> NSDate {
        
        if let value = from {
            if value.characters.count > 0 {
                if let date = self.formatter.dateFromString(value) {
                    return date
                }
            }
        }
{'fraction_non_alphanumeric': 0.0976027397260274, 'fraction_numerical': 0.015839041095890412, 'mean_word_length': 1.9470365699873897, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '2000745', 'n_tokens_mistral': 784, 'n_tokens_neox': 734, 'n_words': 190}