<commit_before>import Foundation

extension Date: NodeConvertible {
    public func makeNode(context: Context = EmptyNode) throws -> Node {
        return .number(.double(self.timeIntervalSince1970))
    }
    
    public init(node: Node, in context: Context) throws {
        switch node {
        case .number(let number):
            self = Date(timeIntervalSince1970: number.double)
            
        case .string(let dateString):
            if let dateMySQL = dateFormatterMySQL.date(from: dateString) {
                self = dateMySQL
            } else if let dateRFC1123 = dateFormatterRFC1123.date(from: dateString) {
                self = dateRFC1123
            } else {
                throw NodeError.unableToConvert(
                    node: node,
                    expected: "MySQL DATETIME or RFC1123 formatted date."
                )
            }
            
        default:
            throw NodeError.unableToConvert(
                node: node,
                expected: "\(String.self), \(Int.self) or \(Double.self))"
            )
        }
    }
}

// DateFormatter init is slow, need to reuse. Reusing two DateFormatters is
// significantly faster than toggling the formatter's `dateFormat` property.
// On Linux, toggling is actually slower than initializing DateFormatter.
private var _dfMySQL: DateFormatter?
private var dateFormatterMySQL: DateFormatter {
    if let df = _dfMySQL {
        return df
    }
    
    let df = DateFormatter()
    df.timeZone = TimeZone(abbreviation: "UTC")
    df.dateFormat = "yyyy-MM-dd HH:mm:ss"
    _dfMySQL = df
    return df
}

private var _dfRFC1123: DateFormatter?
private var dateFormatterRFC1123: DateFormatter {
    if let df = _dfRFC1123 {
        return df
    }
    
    let df = DateFormatter()
    df.dateFormat = "EEE, dd MMM yyyy HH:mm:ss z"
    _dfRFC1123 = df
    return df
}<commit_msg>date convertible for extraction<commit_after>import Foundation

extension Date: NodeConvertible {
    public func makeNode(context: Context = EmptyNode) throws -> Node {
        return .date(self)
    }
    
    public init(node: Node, in context: Context) throws {
        guard case let .date(date) = node else {
            throw NodeError(node: node, expectation: "\(Date.self)", key: nil)
        }
        self = date
    }
}
{'fraction_non_alphanumeric': 0.0852076124567474, 'fraction_numerical': 0.01730103806228374, 'mean_word_length': 2.1088709677419355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1077197', 'n_tokens_mistral': 692, 'n_tokens_neox': 648, 'n_words': 191}