Skip to content

Implementation of NSDateComponents.copy(with: zone) #564

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

Merged
merged 1 commit into from
Sep 12, 2016

Conversation

mamabusi
Copy link
Contributor

No description provided.

copy._values = self._values
copy._calendar = self._calendar
copy._timeZone = self._timeZone
return copy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't really work for any subclassers right?

let newObj = NSDateComponents()
newObj.calendar = calendar
newObj.timeZone = timeZone
newObj.era = era
newObj.year = year
newObj.quarter = quarter
newObj.month = month
newObj.day = day
newObj.hour = hour
newObj.minute = minute
newObj.second = second
newObj.nanosecond = nanosecond
newObj.week = week
newObj.weekOfYear = weekOfYear
newObj.weekOfMonth = weekOfMonth
newObj.yearForWeekOfYear = yearForWeekOfYear
newObj.weekday = weekday
newObj.weekdayOrdinal = weekdayOrdinal
if isLeapMonthSet {
    newObj.leapMonth = leapMonth
}
return newObj

Copy link
Contributor Author

@mamabusi mamabusi Aug 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phausler Thank you for looking into this.

Wrote a code snippet to subclass NSDateComponents:

class Test: NSDateComponents { 
}

func test_subclass() { 
    let obj = Test()
    obj.year = 1987
    obj.month = 3
    obj.day = 17
    obj.hour = 14
    obj.minute = 20
    obj.second = 0
    let newObj = obj.copy(with: nil) as! NSDateComponents
    print(newObj.year)
    print(newObj.month)
    print(newObj.day)
}

Executing the above prints the year month and day as expected.

Are there shortcomings for subclassers that I am missing?

Thanks.

@mamabusi mamabusi force-pushed the nsdatecomponents-branch branch 2 times, most recently from d7f9fa4 to 96b30ef Compare September 9, 2016 07:09
@mamabusi mamabusi force-pushed the nsdatecomponents-branch branch from 96b30ef to 572582a Compare September 9, 2016 10:36
@mamabusi
Copy link
Contributor Author

mamabusi commented Sep 9, 2016

@phausler Made changes to the implementation addressing the review comments. Please have a look. Thanks!

@phausler
Copy link
Contributor

phausler commented Sep 9, 2016

@swift-ci Please test

@parkera parkera merged commit 2105e9c into swiftlang:master Sep 12, 2016
@mamabusi mamabusi deleted the nsdatecomponents-branch branch May 23, 2017 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants