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

Fixed wrong timezone while setup a different SwiftDate.defaultRegion #725

Merged
merged 2 commits into from
Sep 15, 2020
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
4 changes: 2 additions & 2 deletions Sources/SwiftDate/Supports/Commons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public struct DateFormats {
/// This is the built-in list of all supported formats for auto-parsing of a string to a date.
internal static let builtInAutoFormat: [String] = [
DateFormats.iso8601,
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'",
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'",
"yyyy'-'MM'-'dd'T'HH':'mm':'ssZ",
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "52D6D9851BEFF229002C0205"
BuildableName = "SwiftDate-iOS Tests.xctest"
BlueprintName = "SwiftDate-iOS Tests"
ReferencedContainer = "container:SwiftDate.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
13 changes: 7 additions & 6 deletions Tests/SwiftDateTests/TestDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class TestDate: XCTestCase {
print(result)
}

func testDifferenceBetweenDates() {
let date = Date()
let date2 = "2019-01-05".toDate()!.date
let result = date.difference(in: .day, from: date2)
print(result!)
}
func testDifferenceBetweenDates() {
let date = Date()
let date2 = "2019-01-05".toDate()!.date
let result = date.difference(in: .day, from: date2)
print(result!)
}

func testPositionInRange() {
let regionRome = Region(calendar: Calendars.gregorian, zone: Zones.europeRome, locale: Locales.italian)
Expand All @@ -53,4 +53,5 @@ class TestDate: XCTestCase {
let testDate4 = "2018-06-01 03:00:00".toDate(dateFormat, region: regionLondon)!.date
XCTAssertNil( testDate4.positionInRange(date: lowerBound, and: upperBound))
}

}
15 changes: 15 additions & 0 deletions Tests/SwiftDateTests/TestSwiftDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,19 @@ class TestSwiftDate: XCTestCase {
XCTAssert( (SwiftDate.autoFormats == builtInAutoFormats), "Failed to reset auto formats")
}

func testUTCZone() {
SwiftDate.defaultRegion = Region(calendar: Calendars.gregorian, zone: Zones.asiaShanghai, locale: Locales.current)

// DO NOT recognized the right timezone
// The timezone should be UTC
let wrongZone = "2020-03-13T05:40:48.000Z"
let wrongZoneDate = Date.init(wrongZone)
print(wrongZoneDate!.description)
XCTAssert("2020-03-13 05:40:48 +0000" == wrongZoneDate!.description)

let iso8601Time = "2020-03-13T05:40:48+00:00"
let iso8601Date = Date.init(iso8601Time)
print(iso8601Date!.description)
XCTAssert("2020-03-13 05:40:48 +0000" == iso8601Date!.description)
}
}