akosma / SwiftMoment

A time and calendar manipulation library for iOS 9+, macOS 10.11+, tvOS 9+, watchOS 2+ written in Swift 4.
http://akosma.github.io/SwiftMoment
BSD 2-Clause "Simplified" License
1.61k stars 147 forks source link

timezone is ignored in the iso8601 conversion from string to date #85

Open crarau opened 7 years ago

crarau commented 7 years ago

SwiftMoment ignores the timezone from an iso8601 string formatted date even if it's specified.

Example: The code print(moment("2017-02-09T03:17:52.477Z")!.format("yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX")) displays: 2017-02-09T03:17:52.477-05:00 the expected output is either 2017-02-09T03:17:52.477Z or 2017-02-08T22:17:52.477-05:00

from Wikipedia: If the time is in UTC, add a Z directly after the time without a space. Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z".

crarau commented 7 years ago

As a parallel in Javascript for this console.log(moment("2017-02-09T03:17:52.477Z", moment.ISO_8601).format()) we get 2017-02-08T22:17:52-05:00

crarau commented 7 years ago

Any news about this issue, it's serious issue when working with timezones.

DarkDirectX commented 7 years ago

Same issue.

psi-gh commented 7 years ago

Same issue here. SwiftMoment can't handle milliseconds. In

print(moment("2017-02-09T03:17:52.477Z"))

try

print(moment("2017-02-09T03:17:52Z"))