- 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.defaultRegion
was renamed toSwiftDate.defaultRegion
and you can both read and set it.Date.setDefaultRegion(:)
was removed; useSwiftDate.defaultRegion
's setter.TimeZoneName
is nowZones
and its conform to the newZonesConvertible
protocol. All parameters (likeRegion
inits function) takes now a genericZonesConvertible
instance: this mean you can pass one of the enum values of the zone or just an instance ofTimeZone
object (or you can conform your own class to it).CalendarName
is nowCalendars
and its conform to the newCalendarConvertible
protocol. All parameters (likeRegion
inits function) takes now a genericCalendarConvertible
instance: this mean you can pass one of the enum values of the zone or just an instance ofCalendar
object (or you can conform your own class to it).LocaleName
is nowLocales
and its conform to the newLocaleConvertible
protocol. All parameters (likeRegion
inits function) takes now a genericLocaleConvertible
instance: this mean you can pass one of the enum values of the zone or just an instance ofCalendar
object (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()
String
extension 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
Int
extensionsecond,minute,hour,day,week,month,year
due to inconsistencies (use plural versionsseconds,minutes
etc. - 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()
anddistantPast
are 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()
.nextDSTTransitionDate
property is now part of the enum ofdateAt()
recentDate()
andoldestDate()
are now callednewestIn()
andoldestIn()
TimeInterval
Extension:in(_:toDate:of:)
is now replaced bytoUnits(_:from:)
andtoUnit(_:from:)
TimeInterval
Extension:string()
is now replaced bytoString()
DateTimeInterval
class is now replaced byTimePeriod
class 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
String
to parse dates:toISODate()
,toDotNETDate()
,toRSSDate()
andtoSQLDate()
. - Comparison methods are now grouped by
compare()
function and a list of all available enums.
--