Skip to content

Latest commit

 

History

History
65 lines (52 loc) · 5.18 KB

10.Upgrading_SwiftDate4.md

File metadata and controls

65 lines (52 loc) · 5.18 KB

Old Versions

  • for Swift 3.x: Latest compatible version is 4.3.0 Download here. If you are using CocoaPods be sure to fix the release (pod 'SwiftDate', '~> 4.3.0')

Upgrading from Swift 4.x

SwiftDate 5.x is a complete rewrite of the library. While it introduces several new features a great part of the work is about a consistent naming of the functions: some was renamed while deprecated ones was removed.

If you miss a features or you are interested in a new one create a new Issue.

Important Note about Default Region

In SwiftDate 4.x the default region is automatically set to local region, where all attributes are set automatically to the current device's locale, timezone and calendar.

Since SwiftDate 5, in order to be more comply with Date's default behaviour, the default region's timezone is set to GMT+0 (UTC).

If you want to restore the old behaviour just set it to Region.local just after the launch of the app.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
	SwiftDate.defaultRegion = Region.local // set region to local device attributes
	// ... do something else
	return true
}

Added/Removed/Replaced Methods

  • Date.defaultRegion was renamed to SwiftDate.defaultRegion and you can both read and set it.
  • Date.setDefaultRegion(:) was removed; use SwiftDate.defaultRegion's setter.
  • TimeZoneName is now Zones and its conform to the new ZonesConvertible protocol. All parameters (like Region inits function) takes now a generic ZonesConvertible instance: this mean you can pass one of the enum values of the zone or just an instance of TimeZone object (or you can conform your own class to it).
  • CalendarName is now Calendars and its conform to the new CalendarConvertible protocol. All parameters (like Region inits function) takes now a generic CalendarConvertible instance: this mean you can pass one of the enum values of the zone or just an instance of Calendar object (or you can conform your own class to it).
  • LocaleName is now Locales and its conform to the new LocaleConvertible protocol. All parameters (like Region inits function) takes now a generic LocaleConvertible instance: this mean you can pass one of the enum values of the zone or just an instance of Calendar object (or you can conform your own class to it).
  • Date/DateInRegion: isBetween() function was renamed isInRange()
  • Date/DateInRegion: isAfter() was renamed to isAfterDate()
  • Date/DateInRegion: isBefore() was renamed to isBeforeDate()
  • String extension methods date(format:fromRegion) and date(formats:fromRegion) are now replaced by toDate(_:region) (while similar shortcuts methods are added to parse common formats: toISODate(), toDotNETDate(), toRSSDate() and toSQLDate().
  • Removed Int extension second,minute,hour,day,week,month,year due to inconsistencies (use plural versions seconds,minutes etc.
  • Related dates generation is now grouped under the dateAt() function as enum list. Therefore nextWeekend, `previo
  • DateInRegion: roundedAt() is now replaced by dateRoundedAt() which now compacts paramters in a single enum.
  • DateInRegion: startOf() and endOf() are now replaced by dateAtStartOf() and dateAtEndOf()and include support for both single and multiple units.
  • DateInRegion: atTime() is now replaced by dateBySet(hour:min:secs:options)
  • DateInRegion: DateInRegion's static distantFuture() and distantPast are now future() and past()
  • DateInRegion:next(day:) is now part of the dateAt() function with enum .weekday(_).
  • DateInRegion: add(components:) is now replaced by dateByAdding(_:_:)
  • DateInRegion: at(unit:value:) and at(values:keep:) are now replaced by dateBySet().
  • nextDSTTransitionDate property is now part of the enum of dateAt()
  • recentDate() and oldestDate() are now called newestIn() and oldestIn()
  • TimeInterval Extension: in(_:toDate:of:) is now replaced by toUnits(_:from:) and toUnit(_:from:)
  • TimeInterval Extension: string() is now replaced by toString()
  • DateTimeInterval class is now replaced by TimePeriod class and its descendants
  • DateInRegion: dates(between:and:increment:) to enumerate dates is now replaced by enumerateDates(from:to:increment:)
  • DateInRegion: colloquial formatter colloquial(toDate:options:) is now replaced by toRelative(since:style:locale:)
  • Formatting method iso8601() is now toISO8601() and other methods to..() was added to simplify formatting task.
  • Date/DateInRegion: Introduced compareCloseTo() to compare two dates against a precision value.
  • Added several shortcut methods as extensions of String to parse dates: toISODate(), toDotNETDate(), toRSSDate() and toSQLDate().
  • Comparison methods are now grouped by compare() function and a list of all available enums.

--

Index: Table Of Contents