Skip to content

[SR-9668] Adding one month returns a different date on Linux vs Mac. #3558

Open
@swift-ci

Description

@swift-ci
Previous ID SR-9668
Radar None
Original Reporter svanimpe (JIRA User)
Type Bug

Attachment: Download

Environment

Swift 4.2.1

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: b5cd101c9fb210b5c8555f3e1539b89b

Issue Description:

My unit tests unfortunately detected a difference in behavior on Mac vs Linux:

let calendar = Calendar(identifier: .gregorian)
var dateComponents = DateComponents()
dateComponents.calendar = calendar
dateComponents.day = 31
dateComponents.month = 1
dateComponents.year = 2019
let start = calendar.date(from: dateComponents)!
let end = calendar.date(byAdding: .month, value: 1, to: start)!

On Mac, adding one month to Jan. 31 returns Feb. 28 (which is what I hoped it would do). On Linux however, this returns March 1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions