Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DateInRegion(milliseconds:) to work with actual milliseconds #573

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftDate/DateInRegion/DateInRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public struct DateInRegion: DateRepresentable, Decodable, Encodable, CustomStrin
/// - interval: seconds since the Unix Epoch timestamp.
/// - region: region in which the date must be expressed, `nil` uses the default region at UTC timezone
public init(milliseconds interval: Int, region: Region = Region.UTC) {
self.date = Date(timeIntervalSince1970: TimeInterval(interval / 1000))
self.date = Date(timeIntervalSince1970: TimeInterval(interval) / 1000)
self.region = region
}

Expand Down
4 changes: 4 additions & 0 deletions Tests/SwiftDateTests/TestDateInRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class TestDateInRegion: XCTestCase {
XCTAssert( (msecsFromEpochInRegion.date.timeIntervalSince1970 == 5), "Failed to create DateInRegion from epoch time and fixed region / different date")
XCTAssert( (msecsFromEpochInRegion.region == regionBerlin), "Failed to create DateInRegion from epoch time and fixed region / different date")

// Init with fraction of seconds
let msecsLessThanSeconds = DateInRegion(milliseconds: 10)
XCTAssertEqual(round(msecsLessThanSeconds.date.timeIntervalSince1970 * 1000), 10)

}

func testDateInRegion_InitFromComponents() {
Expand Down