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
[SR-12105] Calendar.dateComponents() and Calendar.from() behaving incorrectly with dates in the far past #4479
Comments
@swift-ci create |
This looks to be an issue with dates before the Gregorian calendar start (15-october-1582), Need to determine why this works when swift-corelibs-foundation is running on macOS but not Linux, which shares the same CoreFoundation Calendar code but a different ICU |
Looking at it further, the difference starts with the return value of The following run on macOS v Linux shows the difference (using import Foundation
func test(_ testDateStr: String) {
let formatter = ISO8601DateFormatter()
let date = formatter.date(from: testDateStr)!
print(testDateStr, "->", date.timeIntervalSinceReferenceDate)
}
test("1230-10-08T12:21:18Z")
test("1500-10-08T12:21:18Z")
test("1580-10-08T12:21:18Z")
test("1582-09-08T12:21:18Z")
test("1582-10-02T12:21:18Z")
test("1582-10-16T12:21:18Z")
test("1582-11-08T12:21:18Z")
test("1583-10-08T12:21:18Z")
test("1584-10-08T12:21:18Z")
test("1600-10-08T12:21:18Z")
All of the dates before the start of the Gregorian calendar (1582-10-15) show a difference, so I think its just the ISO8601Date formatter than needs to be fixed first. |
the following is true in the swift console on macOS: // Welcome to Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12).
import Foundation
ISO8601DateFormatter.init().date(
from: "1582-10-14T12:00:00Z"
) == ISO8601DateFormatter.init().date(
from: "1582-10-24T12:00:00Z"
) obviously |
Attachment: Download
Environment
Swift 5.1.3
Date: December 13, 2019
Tag: swift-5.1.3-RELEASE
on Ubuntu 18.04
Additional Detail from JIRA
md5: abedf8a59acd0c2eaab871bcc0fd17fe
relates to:
Issue Description:
The includes test program uses a Calendar instance to extract the .year and .month component from a Date instance, then instantiates a new Date from these components. The result date should thus be the first instance of the month, e.g. the start of the month of the original date.
On macOS 10.14 and 10.15, the test program (correctly) outputs "Optional(1230-10-01 00:00:00 +0000)", but on Linux, it outputs "Optional(1230-10-08 00:00:00 +0000)" instead.
Dates that are not as far in the past do work correctly (as an example, the same date in the year 1990 instead of 1230 works fine).
Unfortunately, I can't debug this deeper, since I currently do not have a debug environment set up on Linux, but caught this issue through a unit test in my own code.
The test program is attached, but also included inline here:
The text was updated successfully, but these errors were encountered: