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

[SR-11569] DateComponents.isValidDate unexpectedly returns false #3386

Closed
swift-ci opened this issue Oct 3, 2019 · 1 comment
Closed

[SR-11569] DateComponents.isValidDate unexpectedly returns false #3386

swift-ci opened this issue Oct 3, 2019 · 1 comment

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Oct 3, 2019

Previous ID SR-11569
Radar None
Original Reporter pitfield (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 5.1 (swift-5.1-RELEASE) Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, 5.1Regression
Assignee @spevans
Priority Medium

md5: f531eee5421fbcfa182ed29258a82bb9

Issue Description:

On Linux, calling isValidDate on a DateComponents instance unexpectedly returns false if the timeZone property of the DateComponents instance is different than the timeZone property of its calendar.

Similarly, calling isValidDate(in: ) on a DateComponents instance unexpectedly returns false if the timeZone property of the DateComponents instance is different than the timeZone property of the specified calendar.

This is unexpected because:

  • it is inconsistent with Swift 5.0 on Linux

  • it is inconsistent with Swift on macOS (both Swift 5.0 and 5.1)

  • the API doc states: "If the time zone property is set in the DateComponents, it is used."

Steps to reproduce

import Foundation

let calendarTimeZone = TimeZone(secondsFromGMT: 0)!
let dateComponentsTimeZone = TimeZone(secondsFromGMT: 3600)!

var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = calendarTimeZone

var dc = DateComponents()
dc.calendar = calendar
dc.timeZone = dateComponentsTimeZone
dc.year = 2019
dc.month = 1
dc.day = 2
dc.hour = 3
dc.minute = 4
dc.second = 5
dc.nanosecond = 6

// Should be true.
print("dc.isValidDate = \(dc.isValidDate)")

// Should be true.
print("dc.isValidDate(in: calendar) = \(dc.isValidDate(in: calendar))")

Expected output (and output on macOS)

dc.isValidDate = true
dc.isValidDate(in: calendar) = true

Actual output (Linux)

dc.isValidDate = false
dc.isValidDate(in: calendar) = false

Environment

Linux (exhibits the problem):

  • Ubuntu 18.04 server

  • Swift version 5.1 (swift-5.1-RELEASE) Target: x86_64-unknown-linux-gnu

macOS (does not exhibit the problem):

  • macOS 10.14.6

  • Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
    Target: x86_64-apple-darwin18.7.0

@spevans
Copy link
Collaborator

spevans commented Jan 22, 2020

#2625

Note that on macOS 10.15 dc.isValidDate(in: calendar) now gives false. This behaviour is matched on Linux.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants