Skip to content

[SR-2846] Calendar date(byAdding:to:wrappingComponents:) returns nil when it shouldn't #4323

@swift-ci

Description

@swift-ci
Previous ID SR-2846
Radar None
Original Reporter UberJason (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

This code functions on OS X 10.11 but not in an Ubuntu 14.04 Docker image.

Here's the swift -version output on OS X 10.11:

Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
Target: x86_64-apple-macosx10.9

And the swift -version output on the Ubuntu 14.04 Docker image:

Swift version 3.0 (swift-3.0-RELEASE)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Linux
Assignee None
Priority Medium

md5: a9665d5c4946832d28b144569d47aae4

Issue Description:

The below snippet of code works on OS X 10.11 El Capitan but not on an Ubuntu 14.04 Docker image with Swift 3.0 RELEASE installed or the October 2 snapshot. Tested in REPL as well as, originally, in a Vapor web application, where I was doing some Date manipulations.

import Foundation

let today = Date()
let diffComponents = DateComponents(day: -1)
let newDate = Calendar.current.date(byAdding: diffComponents, to: today)        //returns nil

A few notes:

  • today is a valid Date object

  • Calendar.current is a valid Calendar object

  • I also tried manually checking that the date(from: DateComponents) function works, and it does:

     todayComponents = DateComponents(year: 2016, month: 10, day: 4) 
    Calendar.current.date(from: todayComponents)        // returns valid Date on both platforms

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