<commit_before>//
//  DateViewOperatorsTests.swift
//  Datez
//
//  Created by <NAME> on 11/7/15.
//  Copyright © 2015 kitz. All rights reserved.
//

import XCTest
@testable import Datez


class DateViewOperatorsTests: XCTestCase {

    let anyDate = DateView(
        forCalendarComponents: CalendarComponents(
            year: 2013,
            month: 4,
            day: 12,
            hour: 15,
            minute: 2
        ),
        inCalendar: Calendar.gregorian
    )
    
    func testAddingComponents() {
        
        let expectedDate = anyDate.update(year: 2015, day: 19)
        XCTAssertEqual(anyDate + 2.years + 7.days, expectedDate)
    }
    
    func testSubtractingComponents() {
        
        let expectedDate = anyDate.update(month: 1, day: 19)
        XCTAssertEqual(anyDate - 2.months - 24.days, expectedDate)
    }
    
    func testAddingComponentsWithOverflow() {
        
        let expectedDate = anyDate.update(month: 5, day: 19)
        XCTAssertEqual(anyDate + 37.days, expectedDate)
    }
    
    func testDateViewOffsetOnDSTDay() {
        
        // DST affected time zone
        let timeZone = TimeZone(identifier: "America/Los_Angeles")!
        NSTimeZone.default = timeZone
        
        // DST switch date
        let dstSwitch = DateView(
            forCalendarComponents: CalendarComponents(year: 2015, month: 11, day: 1),
            inCalendar: Calendar.gregorian
        )
        
        // 1 hour will be eaten by spending 2 AM twice
        let expectedDate = DateView(
            forCalendarComponents: CalendarComponents(year: 2015, month: 11, day: 1, hour: 2),
            inCalendar: Calendar.gregorian
        )
        
        let dstOffset = dstSwitch + 3.hours
        XCTAssertEqual(dstOffset, expectedDate)
        
        NSTimeZone.default = TimeZone.current
    }
    
    func testDateViewOffsetCrossingDSTDay() {
        
        // DST affected time zone
        let timeZone = TimeZone(identifier: "America/Los_Angeles")!
        NSTimeZone.default = timeZone
        
        let preDst = DateView(
            forCalendarComponents: CalendarComponents(year: 2015, month: 10, day: 29),
            inCalendar: Calendar.gregorian
        )
        
        let postDst = DateView(
            forCalendarComponents: CalendarComponents(year: 2015, month: 11, day: 3),
            inCalendar: Calendar.gregorian
        )
        
        // DST compatibile timeZone
        let dateFormatter = DateFormatter()
        dateFormatter.calendar = Calendar.gregorian
        dateFormatter.dateStyle = .short
        dateFormatter.timeStyle = .short
        
        let crossDstForward = preDst + 121.hours
        XCTAssertEqual(crossDstForward, postDst)
        
        let crossDstBackwards = postDst - 121.hours
        XCTAssertEqual(crossDstBackwards, preDst)
        
        NSTimeZone.default = TimeZone.current<commit_msg>Fix TimeZone tests<commit_after>//
//  DateViewOperatorsTests.swift
//  Datez
//
//  Created by <NAME> on 11/7/15.
//  Copyright © 2015 kitz. All rights reserved.
//

import XCTest
@testable import Datez


class DateViewOperatorsTests: XCTestCase {

    let anyDate = DateView(
        forCalendarComponents: CalendarComponents(
            year: 2013,
            month: 4,
            day: 12,
            hour: 15,
            minute: 2
        ),
        inCalendar: Calendar.gregorian
    )
    
    func testAddingComponents() {
        
        let expectedDate = anyDate.update(year: 2015, day: 19)
        XCTAssertEqual(anyDate + 2.years + 7.days, expectedDate)
    }
    
    func testSubtractingComponents() {
        
        let expectedDate = anyDate.update(month: 1, day: 19)
        XCTAssertEqual(anyDate - 2.months - 24.days, expectedDate)
    }
    
    func testAddingComponentsWithOverflow() {
        
        let expectedDate = anyDate.update(month: 5, day: 19)
        XCTAssertEqual(anyDate + 37.days, expectedDate)
    }
    
    func testDateViewOffsetOnDSTDay() {
        
        // DST affected time zone
        let timeZone = TimeZone(identifier: "America/Los_Angeles")!
        NSTimeZone.default = timeZone
        
        // DST switch date
        let dstSwitch = DateView(
            forCalendarComponents: CalendarComponents(year: 2015, month: 11, day: 1),
            inCalendar: Calendar(identifier: .gregorian)
        )
        
        // 1 hour will be eaten by spending 2 AM twice
        let expectedDate = DateView(
            forCalendarComponents: CalendarComponents(year: 2015, month: 11, day: 1, hour: 2),
            inCalendar: Calendar(identifier: .gregorian)
        )
        
        let dstOffset = dstSwitch + 3.hours
        XCTAssertEqual(dstOffset, expectedDate)
        
        NSTimeZone.default = TimeZone.current
    }
    
    func testDateViewOffsetCrossingDSTDay() {
        
        // DST affected time zone
        let timeZone = TimeZone(identifier: "America/Los_Angeles")!
        NSTimeZone.default = timeZone
        
        let preDst = DateView(
            forCalendarComponents: CalendarComponents(year: 2015, month: 10, day: 29),
            inCalendar: Calendar(identifier: .gregorian)
        )
        
        let postDst = DateView(
            forCalendarComponents: CalendarComponents(year: 2015, month: 11, day: 3),
            inCalendar: Calendar(identifier: .gregorian)
        )

        // DST compatibile timeZone
        let dateFormatter = DateFormatter()
        dateFormatter.calendar = Calendar.gregorian
        dateFormatter.dateStyle = .short
        dateFormatter.timeStyle = .short
        
        let crossDstForward = preDst + 121.hours
        XCTAssertEqual(crossDstForward, postDst)
        
        let crossDstBackwards = postDst - 121.hours
        XCTAssertEqual(crossDstBackwards, preDst)
        
        NSTimeZone.default = TimeZone.current
{'fraction_non_alphanumeric': 0.08031308490726562, 'fraction_numerical': 0.02620384549940446, 'mean_word_length': 1.9822425164890918, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4553311', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1625, 'n_words': 397}