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

import Foundation

struct TimeChunk {
    
    enum Size {
        case second
        case minute
        case hour
        case day
        case week
        case month
        case year
    }
    
    
    // MARK: - Variables
    
    var seconds = 0
    var minutes = 0
    var hours = 0
    var days = 0
    var weeks = 0
    var months = 0
    var years = 0
    
    init() {
    
    }
    
    init(size: Size, amount: Int) {
        switch size {
        case .second:
            seconds += amount
        case .minute:
            minutes += amount
        case .hour:
            hours += amount
        case .day:
            days += amount
        case .week:
            weeks += amount
        case .month:
            months += amount
        case .year:
            years += amount
        }
    }
    
    
    // MARK: - Comparisons
    
    func equals(chunk: TimeChunk) -> Bool {
        return (seconds == chunk.seconds && minutes == chunk.minutes && hours == chunk.hours && days == chunk.days && weeks == chunk.weeks && months == chunk.months && years == chunk.years)
    }
    
    
    //MARK: - Lengthen / Shorten
    
    func lengthen(by chunk: TimeChunk) -> TimeChunk {
        var newChunk = TimeChunk()
        newChunk.seconds = seconds + chunk.seconds
        newChunk.minutes = minutes + chunk.minutes
        newChunk.hours = hours + chunk.hours
        newChunk.days = days + chunk.days
        newChunk.weeks = weeks + chunk.weeks
        newChunk.months = months + chunk.months
        newChunk.years = years + chunk.years
        
        return newChunk
    }
    
    func shorten(by chunk: TimeChunk) -> TimeChunk {
        var newChunk = TimeChunk()
        newChunk.seconds = seconds - chunk.seconds
        newChunk.minutes = minutes - chunk.minutes
        newChunk.hours = hours - chunk.hours
        newChunk.days = days - chunk.days
        newChunk.weeks = weeks - chunk.weeks
        newChunk.months = months - chunk.months
        newChunk.years = years - chunk.years
        
        return newChunk
    }
    
    
    // MARK: - Mutation
    
    mutating func lengthened(by chunk: TimeChunk) {
        seconds += chunk.seconds
        minutes += chunk.minutes
        hours += chunk.hours
        days += chunk.days
        weeks += chunk.weeks
        months += chunk.months
        years += chunk.years
    }
    
    mutating func shortened(by chunk: TimeChunk) {
        seconds -= chunk.seconds
        minutes -= chunk.minutes
        hours -= chunk.hours
        days -= chunk.days
        weeks -= chunk.weeks
        months -= chunk.months
        years -= chunk.years
    }
    
    
    // MARK: - Operator Overloads
    
    static func +(leftAddend: TimeChunk, rightAddend: TimeChunk) -> TimeChunk {
        return leftAddend.lengthen(by: rightAddend)
    }
    
    static func -(minuend: TimeChunk, subtrahend: TimeChunk) -> TimeChunk {
        return minuend.shorten(by: subtrahend)
    }
    
    static func ==(left: TimeChunk, right: TimeChunk) -> Bool {
        return left.equals(chunk: right)
    }
}<commit_msg>- Added prefix overload to support negative time chunks<commit_after>//
//  TimeBlock.swift
//  DateTools
//
//  Created by <NAME> on 8/19/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

struct TimeChunk {
    
    enum Size {
        case second
        case minute
        case hour
        case day
        case week
        case month
        case year
    }
    
    
    // MARK: - Variables
    
    var seconds = 0
    var minutes = 0
    var hours = 0
    var days = 0
    var weeks = 0
    var months = 0
    var years = 0
    
    init() {
    
    }
    
    init(size: Size, amount: Int) {
        switch size {
        case .second:
            seconds += amount
        case .minute:
            minutes += amount
        case .hour:
            hours += amount
        case .day:
            days += amount
        case .week:
            weeks += amount
        case .month:
            months += amount
        case .year:
            years += amount
        }
    }
    
    
    // MARK: - Comparisons
    
    func equals(chunk: TimeChunk) -> Bool {
        return (seconds == chunk.seconds && minutes == chunk.minutes && hours == chunk.hours && days == chunk.days && weeks == chunk.weeks && months == chunk.months && years == chunk.years)
    }
    
    
    //MARK: - Lengthen / Shorten
    
    func lengthen(by chunk: TimeChunk) -> TimeChunk {
        var newChunk = TimeChunk()
        newChunk.seconds = seconds + chunk.seconds
        newChunk.minutes = minutes + chunk.minutes
        newChunk.hours = hours + chunk.hours
        newChunk.days = days + chunk.days
        newChunk.weeks = weeks + chunk.weeks
        newChunk.months = months + chunk.months
        newChunk.years = years + chunk.years
        
        return newChunk
    }
    
    func shorten(by chunk: TimeChunk) -> TimeChunk {
        var newChunk = TimeChunk()
        newChunk.seconds = seconds - chunk.seconds
        newChunk.minutes = minutes - chunk.minutes
        newChunk.hours = hours - chunk.hours
        newChunk.days = days - chunk.days
        newChunk.weeks = weeks - chunk.weeks
        newChunk.months = months - chunk.months
        newChunk.years = years - chunk.years
        
        return newChunk
    }
    
    
    // MARK: - Mutation
    
    mutating func lengthened(by chunk: TimeChunk) {
        seconds += chunk.seconds
        minutes += chunk.minutes
        hours += chunk.hours
        days += chunk.days
        weeks += chunk.weeks
        months += chunk.months
        years += chunk.years
    }
    
    mutating func shortened(by chunk: TimeChunk) {
        seconds -= chunk.seconds
        minutes -= chunk.minutes
        hours -= chunk.hours
        days -= chunk.days
        weeks -= chunk.weeks
        months -= chunk.months
        years -= chunk.years
    }
    
    
    // MARK: - Operator Overloads
    
    static func +(leftAddend: TimeChunk, rightAddend: TimeChunk) -> TimeChunk {
        return leftAddend.lengthen(by: rightAddend)
    }
    
    static func -(minuend: TimeChunk, subtrahend: TimeChunk) -> TimeChunk {
        return minuend.shorten(by: subtrahend)
    }
    
    static func ==(left: TimeChunk, right: TimeChunk) -> Bool {
        return left.equals(chunk: right)
    }
    
    static prefix func -(chunk: TimeChunk) -> TimeChunk {
        var invertedChunk = chunk;
        invertedChunk.seconds = -chunk.seconds
        invertedChunk.minutes = -chunk.minutes
        invertedChunk.hours = -chunk.hours
        invertedChunk.days = -chunk.days
        invertedChunk.weeks = -chunk.weeks
        invertedChunk.months = -chunk.months
        invertedChunk.years = -chunk.years
        return invertedChunk
    }

}
{'fraction_non_alphanumeric': 0.09590222861250898, 'fraction_numerical': 0.004601006470165349, 'mean_word_length': 1.5984310795666792, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, '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': '4520463', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1914, 'n_words': 537}