Skip to content

Migration to new NSDate, NSCalendar, NSDateComponentsFormatter APIs #315

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,9 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
Create a date with given components.
Current era is assumed.
*/
public func dateWithEra(_ eraValue: Int, year yearValue: Int, month monthValue: Int, day dayValue: Int, hour hourValue: Int, minute minuteValue: Int, second secondValue: Int, nanosecond nanosecondValue: Int) -> NSDate? {
public func date(_ era: Int, year yearValue: Int, month monthValue: Int, day dayValue: Int, hour hourValue: Int, minute minuteValue: Int, second secondValue: Int, nanosecond nanosecondValue: Int) -> NSDate? {
let comps = NSDateComponents()
comps.era = eraValue
comps.era = era
comps.year = yearValue
comps.month = monthValue
comps.day = dayValue
Expand All @@ -641,9 +641,9 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
Create a date with given components.
Current era is assumed.
*/
public func dateWithEra(_ eraValue: Int, yearForWeekOfYear yearValue: Int, weekOfYear weekValue: Int, weekday weekdayValue: Int, hour hourValue: Int, minute minuteValue: Int, second secondValue: Int, nanosecond nanosecondValue: Int) -> NSDate? {
public func date(_ era: Int, yearForWeekOfYear yearValue: Int, weekOfYear weekValue: Int, weekday weekdayValue: Int, hour hourValue: Int, minute minuteValue: Int, second secondValue: Int, nanosecond nanosecondValue: Int) -> NSDate? {
let comps = NSDateComponents()
comps.era = eraValue
comps.era = era
comps.yearForWeekOfYear = yearValue
comps.weekOfYear = weekValue
comps.weekday = weekdayValue
Expand Down Expand Up @@ -965,7 +965,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
Result dates have an integer number of seconds (as if 0 was specified for the nanoseconds property of the NSDateComponents matching parameter), unless a value was set in the nanoseconds property, in which case the result date will have that number of nanoseconds (or as close as possible with floating point numbers).
The enumeration is stopped by setting *stop = YES in the block and return. It is not necessary to set *stop to NO to keep the enumeration going.
*/
public func enumerateDatesStartingAfterDate(_ start: NSDate, matchingComponents comps: NSDateComponents, options opts: NSCalendarOptions, usingBlock block: (NSDate?, Bool, UnsafeMutablePointer<ObjCBool>) -> Void) { NSUnimplemented() }
public func enumerateDates(_ startingAfter: NSDate, matching comps: NSDateComponents, options opts: NSCalendarOptions, using block: (NSDate?, Bool, UnsafeMutablePointer<ObjCBool>) -> Void) { NSUnimplemented() }

/*
This method computes the next date which matches (or most closely matches) a given set of components.
Expand All @@ -974,7 +974,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
*/
public func nextDateAfterDate(_ date: NSDate, matchingComponents comps: NSDateComponents, options: NSCalendarOptions) -> NSDate? {
var result: NSDate?
enumerateDatesStartingAfterDate(date, matchingComponents: comps, options: options) { date, exactMatch, stop in
enumerateDates(date, matching: comps, options: options) { date, exactMatch, stop in
result = date
stop.pointee = true
}
Expand Down Expand Up @@ -1019,7 +1019,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
let targetComp = NSDateComponents()
targetComp.setValue(v, forComponent: unit)
var result: NSDate?
enumerateDatesStartingAfterDate(date, matchingComponents: targetComp, options: .MatchNextTime) { date, match, stop in
enumerateDates(date, matching: targetComp, options: .MatchNextTime) { date, match, stop in
result = date
stop.pointee = true
}
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding {
offset in hours and minutes from UTC (for example,
"2001-03-24 10:45:32 +0600")
*/
public func descriptionWithLocale(_ locale: AnyObject?) -> String {
guard let aLocale = locale else { return description }
public func description(_ with: AnyObject?) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't these turn into

func description(with locale: AnyObject?) -> String

guard let aLocale = with else { return description }
let dateFormatterRef = CFDateFormatterCreate(kCFAllocatorSystemDefault, (aLocale as! NSLocale)._cfObject, kCFDateFormatterFullStyle, kCFDateFormatterFullStyle)
CFDateFormatterSetProperty(dateFormatterRef, kCFDateFormatterTimeZoneKey, CFTimeZoneCopySystem())

Expand All @@ -149,12 +149,12 @@ public class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding {

extension NSDate {

public func timeIntervalSinceDate(_ anotherDate: NSDate) -> NSTimeInterval {
public func timeIntervalSince(_ anotherDate: NSDate) -> NSTimeInterval {
return self.timeIntervalSinceReferenceDate - anotherDate.timeIntervalSinceReferenceDate
}

public var timeIntervalSinceNow: NSTimeInterval {
return timeIntervalSinceDate(NSDate())
return timeIntervalSince(NSDate())
}

public var timeIntervalSince1970: NSTimeInterval {
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSDateComponentsFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class NSDateComponentsFormatter : NSFormatter {

/* Convenience method for formatting a number of seconds. See 'allowedUnits' for how the default set of allowed units differs from -stringFromDateComponents:.
*/
public func stringFromTimeInterval(_ ti: NSTimeInterval) -> String? { NSUnimplemented() }
public func string(_ from: NSTimeInterval) -> String? { NSUnimplemented() }

public class func localizedStringFromDateComponents(_ components: NSDateComponents, unitsStyle: NSDateComponentsFormatterUnitsStyle) -> String? { NSUnimplemented() }

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
if key is NSArray {
line += (key as! NSArray).descriptionWithLocale(locale, indent: level + 1)
} else if key is NSDate {
line += (key as! NSDate).descriptionWithLocale(locale)
line += (key as! NSDate).description(locale)
} else if key is NSDecimalNumber {
line += (key as! NSDecimalNumber).descriptionWithLocale(locale)
} else if key is NSDictionary {
Expand All @@ -397,7 +397,7 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
if object is NSArray {
line += (object as! NSArray).descriptionWithLocale(locale, indent: level + 1)
} else if object is NSDate {
line += (object as! NSDate).descriptionWithLocale(locale)
line += (object as! NSDate).description(locale)
} else if object is NSDecimalNumber {
line += (object as! NSDecimalNumber).descriptionWithLocale(locale)
} else if object is NSDictionary {
Expand Down