From e5acc9b0d03dc5f7dff801a2f1c7de71257218e6 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Tue, 14 Aug 2018 09:53:44 +0200 Subject: [PATCH] Fix DateInRegion(milliseconds:) --- Sources/SwiftDate/DateInRegion/DateInRegion.swift | 2 +- Tests/SwiftDateTests/TestDateInRegion.swift | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftDate/DateInRegion/DateInRegion.swift b/Sources/SwiftDate/DateInRegion/DateInRegion.swift index 18afebee..309b04dd 100644 --- a/Sources/SwiftDate/DateInRegion/DateInRegion.swift +++ b/Sources/SwiftDate/DateInRegion/DateInRegion.swift @@ -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 } diff --git a/Tests/SwiftDateTests/TestDateInRegion.swift b/Tests/SwiftDateTests/TestDateInRegion.swift index 02d9b531..6c563877 100644 --- a/Tests/SwiftDateTests/TestDateInRegion.swift +++ b/Tests/SwiftDateTests/TestDateInRegion.swift @@ -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() {