Skip to content

Commit b652fe1

Browse files
committed
Add test for whole difference issue
1 parent 1c82c66 commit b652fe1

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

Sources/Time/Documentation.docc/ReleaseNotes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
A brief history of **Time**.
44

5+
## 1.0.2
6+
7+
11 April, 2024
8+
9+
- Fixed an issue where differences in whole values could produce values that were off by one unit
10+
- Fixed an issue where Fixed values created without an era would crash when attempting to access their ``Fixed/era``
11+
12+
- [Github release](https://github.com/davedelong/time/releases/tag/1.0.2)
13+
514
## 1.0.1
615

716
10 March, 2024

Tests/TimeTests/FixedTests.swift

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import XCTest
22
@testable import Time
33

44
class FixedTests: XCTestCase {
5-
5+
66
static var allTests = [
77
("testInitializingGregorianDateWithoutEraSucceeds", testInitializingGregorianDateWithoutEraSucceeds),
88
("testInitializingGregorianDateWithEraSucceeds", testInitializingGregorianDateWithEraSucceeds),
@@ -41,43 +41,43 @@ class FixedTests: XCTestCase {
4141
let year = try! Fixed<Year>(region: .posix, era: 1, year: 2020)
4242
let lastMonth = year.lastMonth
4343
let expectedlastMonth = try! Fixed<Month>(region: .posix, era:1, year: 2020, month: 12)
44-
44+
4545
XCTAssertEqual(lastMonth, expectedlastMonth)
4646
}
47-
47+
4848
func testLastDayOfMonth() {
4949

5050
let month = try! Fixed<Month>(region: .posix, era: 1, year: 2020, month: 2)
5151
let lastDay = month.lastDay
5252
let expectedLastDay = try! Fixed<Day>(region: .posix, era:1, year: 2020, month: 2, day: 29)
53-
53+
5454
XCTAssertEqual(lastDay, expectedLastDay)
5555
}
56-
56+
5757
func testLastHourOfDay() {
5858

5959
let day = try! Fixed<Day>(region: .posix, era: 1, year: 2020, month: 2, day: 29)
6060
let lastHour = day.lastHour
6161
let expectedlastHour = try! Fixed<Hour>(region: .posix, era:1, year: 2020, month: 2, day: 29, hour: 23)
62-
62+
6363
XCTAssertEqual(lastHour, expectedlastHour)
6464
}
65-
65+
6666
func testLastMinuteOfHour() {
6767

6868
let hour = try! Fixed<Hour>(region: .posix, era: 1, year: 2020, month: 2, day: 29, hour: 13)
6969
let lastMinute = hour.lastMinute
7070
let expectedlastMinute = try! Fixed<Minute>(region: .posix, era:1, year: 2020, month: 2, day: 29, hour: 13, minute: 59)
71-
71+
7272
XCTAssertEqual(lastMinute, expectedlastMinute)
7373
}
74-
74+
7575
func testLastSecondOfMinute() {
7676

7777
let minute = try! Fixed<Minute>(region: .posix, era: 1, year: 2020, month: 2, day: 29, hour: 13, minute: 31)
7878
let lastSecond = minute.lastSecond
7979
let expectedlastSecond = try! Fixed<Second>(region: .posix, era:1, year: 2020, month: 2, day: 29, hour: 13, minute: 31, second: 59)
80-
80+
8181
XCTAssertEqual(lastSecond, expectedlastSecond)
8282
}
8383

@@ -103,6 +103,21 @@ class FixedTests: XCTestCase {
103103
XCTAssertEqual(minuteOfFirstSecond, minuteOfSecondSecond)
104104
}
105105

106+
func testTotalMinutesCalculations() throws {
107+
let today = Clocks.system.today
108+
109+
var start = try today.firstMinute.setting(hour: 7, minute: 30)
110+
var end = try today.firstMinute.setting(hour: 20, minute: 45)
111+
XCTAssertEqual(start.differenceInWholeMinutes(to: end).minutes, 795)
112+
113+
start = try start.setting(hour: 11, minute: 0)
114+
end = try end.setting(hour: 17, minute: 0)
115+
XCTAssertEqual(start.differenceInWholeMinutes(to: end).minutes, 360)
116+
117+
end = try end.setting(hour: 11, minute: 30)
118+
XCTAssertEqual(start.differenceInWholeMinutes(to: end).minutes, 30)
119+
}
120+
106121
func testRounding() throws {
107122
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)
108123

0 commit comments

Comments
 (0)