Skip to content

Commit

Permalink
Add test for whole difference issue
Browse files Browse the repository at this point in the history
  • Loading branch information
davedelong committed Apr 11, 2024
1 parent 1c82c66 commit b652fe1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
9 changes: 9 additions & 0 deletions Sources/Time/Documentation.docc/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

A brief history of **Time**.

## 1.0.2

11 April, 2024

- Fixed an issue where differences in whole values could produce values that were off by one unit
- Fixed an issue where Fixed values created without an era would crash when attempting to access their ``Fixed/era``

- [Github release](https://github.com/davedelong/time/releases/tag/1.0.2)

## 1.0.1

10 March, 2024
Expand Down
35 changes: 25 additions & 10 deletions Tests/TimeTests/FixedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import XCTest
@testable import Time

class FixedTests: XCTestCase {

static var allTests = [
("testInitializingGregorianDateWithoutEraSucceeds", testInitializingGregorianDateWithoutEraSucceeds),
("testInitializingGregorianDateWithEraSucceeds", testInitializingGregorianDateWithEraSucceeds),
Expand Down Expand Up @@ -41,43 +41,43 @@ class FixedTests: XCTestCase {
let year = try! Fixed<Year>(region: .posix, era: 1, year: 2020)
let lastMonth = year.lastMonth
let expectedlastMonth = try! Fixed<Month>(region: .posix, era:1, year: 2020, month: 12)

XCTAssertEqual(lastMonth, expectedlastMonth)
}

func testLastDayOfMonth() {

let month = try! Fixed<Month>(region: .posix, era: 1, year: 2020, month: 2)
let lastDay = month.lastDay
let expectedLastDay = try! Fixed<Day>(region: .posix, era:1, year: 2020, month: 2, day: 29)

XCTAssertEqual(lastDay, expectedLastDay)
}

func testLastHourOfDay() {

let day = try! Fixed<Day>(region: .posix, era: 1, year: 2020, month: 2, day: 29)
let lastHour = day.lastHour
let expectedlastHour = try! Fixed<Hour>(region: .posix, era:1, year: 2020, month: 2, day: 29, hour: 23)

XCTAssertEqual(lastHour, expectedlastHour)
}

func testLastMinuteOfHour() {

let hour = try! Fixed<Hour>(region: .posix, era: 1, year: 2020, month: 2, day: 29, hour: 13)
let lastMinute = hour.lastMinute
let expectedlastMinute = try! Fixed<Minute>(region: .posix, era:1, year: 2020, month: 2, day: 29, hour: 13, minute: 59)

XCTAssertEqual(lastMinute, expectedlastMinute)
}

func testLastSecondOfMinute() {

let minute = try! Fixed<Minute>(region: .posix, era: 1, year: 2020, month: 2, day: 29, hour: 13, minute: 31)
let lastSecond = minute.lastSecond
let expectedlastSecond = try! Fixed<Second>(region: .posix, era:1, year: 2020, month: 2, day: 29, hour: 13, minute: 31, second: 59)

XCTAssertEqual(lastSecond, expectedlastSecond)
}

Expand All @@ -103,6 +103,21 @@ class FixedTests: XCTestCase {
XCTAssertEqual(minuteOfFirstSecond, minuteOfSecondSecond)
}

func testTotalMinutesCalculations() throws {
let today = Clocks.system.today

var start = try today.firstMinute.setting(hour: 7, minute: 30)
var end = try today.firstMinute.setting(hour: 20, minute: 45)
XCTAssertEqual(start.differenceInWholeMinutes(to: end).minutes, 795)

start = try start.setting(hour: 11, minute: 0)
end = try end.setting(hour: 17, minute: 0)
XCTAssertEqual(start.differenceInWholeMinutes(to: end).minutes, 360)

end = try end.setting(hour: 11, minute: 30)
XCTAssertEqual(start.differenceInWholeMinutes(to: end).minutes, 30)
}

func testRounding() throws {
let t = try! Fixed<Nanosecond>(region: .posix, era: 1, year: 2024, month: 2, day: 3, hour: 14, minute: 27, second: 43, nanosecond: 499_000_000)

Expand Down

0 comments on commit b652fe1

Please sign in to comment.