Skip to content

Commit 7433f25

Browse files
committed
Fix calendars to be gregorian
1 parent 359e918 commit 7433f25

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Sources/SwiftYMD/Date.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
extension YM {
44
public init(_ date: Date, timeZone: TimeZone = .current) {
5-
let calendar: Calendar = .current
5+
let calendar: Calendar = .init(identifier: .gregorian)
66
let components = calendar.dateComponents(in: timeZone, from: date)
77
guard
88
let y = components.year,
@@ -21,7 +21,7 @@ extension YM {
2121

2222
extension YMD {
2323
public init(_ date: Date, timeZone: TimeZone = .current) {
24-
let calendar: Calendar = .current
24+
let calendar: Calendar = .init(identifier: .gregorian)
2525
let components = calendar.dateComponents(in: timeZone, from: date)
2626
guard
2727
let y = components.year,
@@ -42,12 +42,12 @@ extension YMD {
4242

4343
extension Date {
4444
public init(_ ym: YM, timeZone: TimeZone = .current) {
45-
let dateComponents = DateComponents(calendar: .current, timeZone: timeZone, year: ym.year.rawValue, month: ym.month.rawValue)
45+
let dateComponents = DateComponents(calendar: Calendar(identifier: .gregorian), timeZone: timeZone, year: ym.year.rawValue, month: ym.month.rawValue)
4646
self = dateComponents.date!
4747
}
4848

4949
public init(_ ymd: YMD, timeZone: TimeZone = .current) {
50-
let dateComponents = DateComponents(calendar: .current, timeZone: timeZone, year: ymd.year.rawValue, month: ymd.month.rawValue, day: ymd.day)
50+
let dateComponents = DateComponents(calendar: Calendar(identifier: .gregorian), timeZone: timeZone, year: ymd.year.rawValue, month: ymd.month.rawValue, day: ymd.day)
5151
self = dateComponents.date!
5252
}
5353
}

Tests/SwiftYMDTests/FoundationTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class FoundationTests: XCTestCase {
66
// It rarely fails when the date changes during its execution
77
func testCurrent() {
88
let date: Date = .init()
9-
let calendar: Calendar = .current
9+
let calendar: Calendar = .init(identifier: .gregorian)
1010

1111
let ym: YM = .current()
1212
XCTAssertEqual(ym.year.rawValue, calendar.component(.year, from: date))

0 commit comments

Comments
 (0)