- 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')
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.
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
}Date.defaultRegionwas renamed toSwiftDate.defaultRegionand you can both read and set it.Date.setDefaultRegion(:)was removed; useSwiftDate.defaultRegion's setter.TimeZoneNameis nowZonesand its conform to the newZonesConvertibleprotocol. All parameters (likeRegioninits function) takes now a genericZonesConvertibleinstance: this mean you can pass one of the enum values of the zone or just an instance ofTimeZoneobject (or you can conform your own class to it).CalendarNameis nowCalendarsand its conform to the newCalendarConvertibleprotocol. All parameters (likeRegioninits function) takes now a genericCalendarConvertibleinstance: this mean you can pass one of the enum values of the zone or just an instance ofCalendarobject (or you can conform your own class to it).LocaleNameis nowLocalesand its conform to the newLocaleConvertibleprotocol. All parameters (likeRegioninits function) takes now a genericLocaleConvertibleinstance: this mean you can pass one of the enum values of the zone or just an instance ofCalendarobject (or you can conform your own class to it).Date/DateInRegion:isBetween()function was renamedisInRange()Date/DateInRegion:isAfter()was renamed toisAfterDate()Date/DateInRegion:isBefore()was renamed toisBeforeDate()Stringextension methodsdate(format:fromRegion)anddate(formats:fromRegion)are now replaced bytoDate(_:region)(while similar shortcuts methods are added to parse common formats:toISODate(),toDotNETDate(),toRSSDate()andtoSQLDate().- Removed
Intextensionsecond,minute,hour,day,week,month,yeardue to inconsistencies (use plural versionsseconds,minutesetc. - Related dates generation is now grouped under the
dateAt()function as enum list. ThereforenextWeekend, `previo DateInRegion:roundedAt()is now replaced bydateRoundedAt()which now compacts paramters in a single enum.DateInRegion:startOf()andendOf()are now replaced bydateAtStartOf()anddateAtEndOf()and include support for both single and multiple units.DateInRegion:atTime()is now replaced bydateBySet(hour:min:secs:options)DateInRegion:DateInRegion's staticdistantFuture()anddistantPastare nowfuture()andpast()DateInRegion:next(day:)is now part of thedateAt()function with enum.weekday(_).DateInRegion:add(components:)is now replaced bydateByAdding(_:_:)DateInRegion:at(unit:value:)andat(values:keep:)are now replaced bydateBySet().nextDSTTransitionDateproperty is now part of the enum ofdateAt()recentDate()andoldestDate()are now callednewestIn()andoldestIn()TimeIntervalExtension:in(_:toDate:of:)is now replaced bytoUnits(_:from:)andtoUnit(_:from:)TimeIntervalExtension:string()is now replaced bytoString()DateTimeIntervalclass is now replaced byTimePeriodclass and its descendantsDateInRegion:dates(between:and:increment:)to enumerate dates is now replaced byenumerateDates(from:to:increment:)DateInRegion: colloquial formattercolloquial(toDate:options:)is now replaced bytoRelative(since:style:locale:)- Formatting method
iso8601()is nowtoISO8601()and other methodsto..()was added to simplify formatting task. Date/DateInRegion: IntroducedcompareCloseTo()to compare two dates against a precision value.- Added several shortcut methods as extensions of
Stringto parse dates:toISODate(),toDotNETDate(),toRSSDate()andtoSQLDate(). - Comparison methods are now grouped by
compare()function and a list of all available enums.
--
