<commit_before>import Foundation

/// DatabaseDateComponents reads and stores DateComponents in the database.
public struct DatabaseDateComponents : DatabaseValueConvertible, StatementColumnConvertible {

    public static var useScanfStrategy = true
    
    /// The available formats for reading and storing date components.
    public enum Format : String {
        
        /// The format "yyyy-MM-dd".
        case YMD = "yyyy-MM-dd"
        
        /// The format "yyyy-MM-dd HH:mm".
        ///
        /// This format is lexically comparable with SQLite's CURRENT_TIMESTAMP.
        case YMD_HM = "yyyy-MM-dd HH:mm"
        
        /// The format "yyyy-MM-dd HH:mm:ss".
        ///
        /// This format is lexically comparable with SQLite's CURRENT_TIMESTAMP.
        case YMD_HMS = "yyyy-MM-dd HH:mm:ss"
        
        /// The format "yyyy-MM-dd HH:mm:ss.SSS".
        ///
        /// This format is lexically comparable with SQLite's CURRENT_TIMESTAMP.
        case YMD_HMSS = "yyyy-MM-dd HH:mm:ss.SSS"
        
        /// The format "HH:mm".
        case HM = "HH:mm"
        
        /// The format "HH:mm:ss".
        case HMS = "HH:mm:ss"
        
        /// The format "HH:mm:ss.SSS".
        case HMSS = "HH:mm:ss.SSS"
        
        var hasYMDComponents: Bool {
            switch self {
            case .YMD, .YMD_HM, .YMD_HMS, .YMD_HMSS:
                return true
            case .HM, .HMS, .HMSS:
                return false
            }
        }
    }
    
    // MARK: - NSDateComponents conversion
    
    /// The date components
    public let dateComponents: DateComponents
    
    /// The database format
    public let format: Format
    
    /// Creates a DatabaseDateComponents from a DateComponents and a format.
    ///
    /// The result is nil if and only if *dateComponents* is nil.
    ///
    /// - parameters:
    ///     - dateComponents: An optional DateComponents.
    ///     - format: The format used for storing the date components in
    ///       the database.
    /// - returns: An optional DatabaseDateComponents.
    public init?(_ dateComponents: DateComponents?, format: Format) {
        guard let dateComponents = dateComponents else {
            return nil
        }
        self.format = format
        self.dateComponents = dateComponents
    }
    
    // MARK: - StatementColumnConvertible adoption
    
    public init(sqliteStatement: SQLiteStatement, index: Int32) {
        guard DatabaseDateComponents.useScanfStrategy else {
            let dbValue = DatabaseValue(sqliteStatement: sqliteStatement, index: index)
            guard let components = DatabaseDateComponents.fromDatabaseValue(dbValue) else {
                fatalError("could not convert database value \(dbValue) to DatabaseDateComponents")
            }
            self.dateComponents = components.dateComponents
            self.format = components.format
            return<commit_msg>Documentation<commit_after>import Foundation

/// DatabaseDateComponents reads and stores DateComponents in the database.
public struct DatabaseDateComponents : DatabaseValueConvertible, StatementColumnConvertible {

    public static var useScanfStrategy = true
    
    /// The available formats for reading and storing date components.
    public enum Format : String {
        
        /// The format "yyyy-MM-dd".
        case YMD = "yyyy-MM-dd"
        
        /// The format "yyyy-MM-dd HH:mm".
        ///
        /// This format is lexically comparable with SQLite's CURRENT_TIMESTAMP.
        case YMD_HM = "yyyy-MM-dd HH:mm"
        
        /// The format "yyyy-MM-dd HH:mm:ss".
        ///
        /// This format is lexically comparable with SQLite's CURRENT_TIMESTAMP.
        case YMD_HMS = "yyyy-MM-dd HH:mm:ss"
        
        /// The format "yyyy-MM-dd HH:mm:ss.SSS".
        ///
        /// This format is lexically comparable with SQLite's CURRENT_TIMESTAMP.
        case YMD_HMSS = "yyyy-MM-dd HH:mm:ss.SSS"
        
        /// The format "HH:mm".
        case HM = "HH:mm"
        
        /// The format "HH:mm:ss".
        case HMS = "HH:mm:ss"
        
        /// The format "HH:mm:ss.SSS".
        case HMSS = "HH:mm:ss.SSS"
        
        var hasYMDComponents: Bool {
            switch self {
            case .YMD, .YMD_HM, .YMD_HMS, .YMD_HMSS:
                return true
            case .HM, .HMS, .HMSS:
                return false
            }
        }
    }
    
    // MARK: - NSDateComponents conversion
    
    /// The date components
    public let dateComponents: DateComponents
    
    /// The database format
    public let format: Format
    
    /// Creates a DatabaseDateComponents from a DateComponents and a format.
    ///
    /// The result is nil if and only if *dateComponents* is nil.
    ///
    /// - parameters:
    ///     - dateComponents: An optional DateComponents.
    ///     - format: The format used for storing the date components in
    ///       the database.
    /// - returns: An optional DatabaseDateComponents.
    public init?(_ dateComponents: DateComponents?, format: Format) {
        guard let dateComponents = dateComponents else {
            return nil
        }
        self.format = format
        self.dateComponents = dateComponents
    }
    
    // MARK: - StatementColumnConvertible adoption
    
    /// Returns a value initialized from a raw SQLite statement pointer.
    ///
    /// - parameters:
    ///     - sqliteStatement: A pointer to an SQLite statement.
    ///     - index: The column index.
    public init(sqliteStatement: SQLiteStatement, index: Int32) {
        guard DatabaseDateComponents.useScanfStrategy else {
            let dbValue = DatabaseValue(sqliteStatement: sqliteStatement, index: index)
            guard let components = DatabaseDateComponents.fromDatabaseValue(dbValue) else {
                fatalError("could not convert database value \(dbValue) to DatabaseDateComponents")
            }
            self.dateComponents = components.dateComponents
            self.format = components.format
            return
{'fraction_non_alphanumeric': 0.09307679657950994, 'fraction_numerical': 0.000657786548265088, 'mean_word_length': 1.8001841620626151, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '253438', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1612, 'n_words': 487}