<commit_before>//
//  TimePeriod.swift
//  DateTools
//
//  Created by <NAME> on 8/17/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation



/**
 # TimePeriod
 
 In DateTools, time periods are represented by the TimePeriod protocol. Required variables and method impleementations are bound below. An inheritable implementation of the TimePeriodProtocol is available through the TimePeriodClass
 
 [Visit our github page](https://github.com/MatthewYork/DateTools#time-periods) for more information.
 */
public protocol TimePeriodProtocol {
    
    // MARK: - Variables
    
    /**
     The start date for a TimePeriod representing the starting boundary of the time period
     */
    var beginning: Date? {get set}
    
    /**
     *  The end date for a TimePeriod representing the ending boundary of the time period
     */
    var end: Date? {get set}
}

public extension TimePeriodProtocol {
    
    
    // MARK: - Information
    
    var isMoment: Bool {
        return self.beginning == self.end
    }
    
    var years: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.yearsEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var weeks: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.weeksEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var days: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.daysEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var hours: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.hoursEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var minutes: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.minutesEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var seconds: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.secondsEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var chunk: TimeChunk {
        return TimeChunk(seconds: seconds, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
    }
    
    var duration: TimeInterval {
        if self.beginning != nil && self.end != nil {
            return abs(self.beginning!.timeIntervalSince(self.end!))
        }
        return TimeInterval(DBL_MAX)
    }
    
    
    // MARK: - Time Period Relationships
    
    func relation(to period: TimePeriodProtocol) -> Relation {
        //Make sure that all start and end points exist for comparison
        if (self.beginning != nil && self.end != nil && period.beginning != nil && period.end != nil) {
            //Make sure time periods are of positive durations
            if (self.beginning!.earlier(than: self.end!) && period.beginning!.earlier(than: period.end!)) {
                <commit_msg>Fix TimePeriod.swift to be compatible with Linux (where DBL_MAX is not defined)<commit_after>//
//  TimePeriod.swift
//  DateTools
//
//  Created by <NAME> on 8/17/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation



/**
 # TimePeriod
 
 In DateTools, time periods are represented by the TimePeriod protocol. Required variables and method impleementations are bound below. An inheritable implementation of the TimePeriodProtocol is available through the TimePeriodClass
 
 [Visit our github page](https://github.com/MatthewYork/DateTools#time-periods) for more information.
 */
public protocol TimePeriodProtocol {
    
    // MARK: - Variables
    
    /**
     The start date for a TimePeriod representing the starting boundary of the time period
     */
    var beginning: Date? {get set}
    
    /**
     *  The end date for a TimePeriod representing the ending boundary of the time period
     */
    var end: Date? {get set}
}

public extension TimePeriodProtocol {
    
    
    // MARK: - Information
    
    var isMoment: Bool {
        return self.beginning == self.end
    }
    
    var years: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.yearsEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var weeks: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.weeksEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var days: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.daysEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var hours: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.hoursEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var minutes: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.minutesEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var seconds: Int {
        if self.beginning != nil && self.end != nil {
            return self.beginning!.secondsEarlierThan(self.end!)
        }
        return Int.max
    }
    
    var chunk: TimeChunk {
        return TimeChunk(seconds: seconds, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
    }
    
    var duration: TimeInterval {
        if self.beginning != nil && self.end != nil {
            return abs(self.beginning!.timeIntervalSince(self.end!))
        }
        #if os(Linux)
            return TimeInterval(Double.greatestFiniteMagnitude)
        #else
            return TimeInterval(DBL_MAX)
        #endif
    }
    
    
    // MARK: - Time Period Relationships
    
    func relation(to period: TimePeriodProtocol) -> Relation {
        //Make sure that all start and end points exist for comparison
        if (self.beginning != nil && self.end != nil && period.beginning != nil && period.end != nil) {
            //Make sure time periods are of positive durations
            if (self.beginning!.earlier(than: self.end!) && period.beginning!.earlier(than: period.end!)) {
                
{'fraction_non_alphanumeric': 0.10287664553876158, 'fraction_numerical': 0.0048756704046806435, 'mean_word_length': 2.0048828125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7189466', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1699, 'n_words': 521}