Bot releases are hidden (Show)
Published by malcommac over 6 years ago
Release Date: 2018-07-12
ordinalDay
property to Date
and DateInRegion
(iOS 9+, macOS 10.11+)Published by malcommac over 6 years ago
isAfterDate
, isBeforeDate
from Date+Compare
extension ignores orEqual
argumentPublished by malcommac over 6 years ago
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 regiomn, where all attributes are set automatically to the current's 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 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()
.Int
extension second,minute,hour,day,week,month,year
due to inconsistence (use plurar versions seconds,minutes
etc.dateAt()
function as enum list. Therefore nextWeekend
, `previoDateInRegion
: 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:)
TimeInterval
Extension: string()
is now replaced by toString()
DateTimeInterval
class is now replaced by TimePeriod
class and its descendantsDateInRegion
: 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:)
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.String
to parse dates: toISODate()
, toDotNETDate()
, toRSSDate()
and toSQLDate()
.compare()
function and a list of all available enums.Published by malcommac almost 7 years ago
ColloquialDateFormatter
classisBetween
to check if a date is inside a given dates range with passed granularity.in()
function of TimeInterval
. If specified conversion of the interval is aware of daylight saving time and calendar's specific dates; when not specified absolute conversion still available (only for .day,.hour,.minute,.second
components).Published by malcommac almost 7 years ago
Release Date: 2017-11-26
Zipped Version: Download 4.4.2
Published by malcommac about 7 years ago
NSRange
under XCode 9Published by malcommac about 7 years ago
Release Date: 2017-09-14
Zipped Version for Swift 4: Download 4.4.0
#480 Fix for '-' operator both in Date
and DateInRegion
classes where the result is correctly reported.
Published by malcommac about 7 years ago
Release Date: 2017-09-14
Zipped Version for Swift 3: Download 4.3.0
#480 Fix for '-' operator both in Date
and DateInRegion
classes where the result is correctly reported.
Published by malcommac about 7 years ago
Changes:
Published by malcommac about 7 years ago
Changelog:
CalendarName
now supports RawRepresentable
protocolcolloquial...()
functions now fallback to timeComponents...
functions when style
is set to an abbreviated form (ie to return 1h
)DateTimeInterval
(regression from previous release)Published by malcommac over 7 years ago
Published by malcommac over 7 years ago
firstWeekday
to Region
struct. This allows you to easily change the first day of a week on given Region's Calendar
object. By default the value is set sunday
..dates(between:and)
which sometimes may report as final date of the output array date greater than specified end date.colloquial
functions which return wrong results when differences can be expressed in days.colloquial
functions which return wrong results when differences can be expressed in days.Published by malcommac over 7 years ago
Date
and DateInRegion
has now two functions to round a date to certain interval (expressed in seconds
or minutes
). DateInRegion
exposes roundAt()
which directly modify the date itself; Date
, as immutable object, exposes the same feature in roundedAt()
function (which return a new Date
instances)..isDST
in DateInRegion
(it returns true if the date uses daylight saving time); .DSTOffset
in DateInRegion
(it returns the value (in seconds) of the daylight saving time offset of the represented date), . nextDSTTransitionDate
in DateInRegion
(it returns the next daylight saving time transition after currently represented date when expressed); nextDSTTransitionDate()
func in Date
(it returns the next dst transition date when receiver is expressed in a particular timezone); DSTOffset()
func in Date
(it returns the offset of daylight saving time when receiver is expressed in a particular timezone); isDST()
func in Date
(it returns if receiver date uses daylight saving time when expressed in a particular timezone).ISO8601
formats (weeks only w/wo implicit year/month/day).ISO8601
string now results in a DateInRegion
which contains the correct timezone defined (Date
instances are now converted automatically to be time-independent).Published by malcommac over 7 years ago
#402 Added Greek localization (thanks to @dimmdesign)
#399 colloquialSinceNow
also allows to set unitsStyle
params to specify the type of values you want to print.
#400 DateInRegion
has a class func named date(formats:fromRegion)
which allows parsing a single string with multiple formats (the first one that succeeds returns the instance of the DateInRegion
). Also available as String
extension (with the same name).
#223 ISO8601DateTimeFormatter
now recognize the timezone of an ISO string and create a date with the correct value.
#407 SwiftDate now can parse ISO8601 strings without specifyng the ISO format; it evaluates the best format automatically. Also the parser faster than the previous built one. Since now .iso8601
parsing format is used only as formatter (from date to string, viceversa any given value is ignored. You are encouraged to use .iso8601Auto
instead).
The following ISO8601 variants are supported:
YYYYMMDD
YYYY-MM-DD
YYYY-MM
YYYY
YY //century
//Implied century: YY is 00-99
YYMMDD
YY-MM-DD
-YYMM
-YY-MM
-YY
//Implied year
--MMDD
--MM-DD
--MM
//Implied year and month
---DD
//Ordinal dates: DDD is the number of the day in the year (1-366)
YYYYDDD
YYYY-DDD
YYDDD
YY-DDD
-DDD
//Week-based dates: ww is the number of the week, and d is the number (1-7) of the day in the week
yyyyWwwd
yyyy-Www-d
yyyyWww
yyyy-Www
yyWwwd
yy-Www-d
yyWww
yy-Www
//Year of the implied decade
-yWwwd
-y-Www-d
-yWww
-y-Www
//Week and day of implied year
-Wwwd
-Www-d
//Week only of implied year
-Www
//Day only of implied week
-W-d
at(unitsWithValues dict: [Calendar.Component : Int])
in Date
and DateInRegion
and replaced with functional at(values: [Calendar.Component : Int], keep: Set<Calendar.Component>)
a
and b
where a - b < 0 iff a < b
.colloquial
func which report wrong difference of 1 day
when two dates are distant < 24h but in two different days.Published by malcommac over 7 years ago
#404 Compatibility with Swift 3.1
Published by malcommac over 7 years ago
strict
. Using strict
instead of custom
disable heuristics date guessing of the formatter (ie. 1999-02-31 become an invalid date to parse, while with heuristics enabled guessing date 1999-03-03 is returned instead).Published by malcommac over 7 years ago
Local.collatorIdentifier
(Returns zh-hans-CN and zh-hant-CN)DateZeroBehavior
options are now public outside the libraryuseImminentInterval
in DateInRegionFormatter
with a configurable value called imminentInterval
. With a default value of 5 it fallback to just now
version. If nil
fallback is disabled.DateInRegionFormatter
is now able to load custom localization both from LocaleName
and custom .strings
files (just set the formatter.localization = Localization(path: [PATH_TO_YOUR_STRINGS_FILE]
)Published by malcommac almost 8 years ago
allowedComponents
does not contains lower time components (ie. cannot print "today" when set formatter to accept only allowedComponents = [.day]
and day difference between dates is zero).DateInRegionFormatter
crashes with any non-default .allowedComponents
.Published by malcommac almost 8 years ago
.next(day:)
both for Date
and DateInRegion
to get the next weekday (ie. "next friday from today") after specified date..dates(between:and:increment:)
both for Date
and DateInRegion
which allows to enumerate dates between two interval with given increment in term of DateComponents
..in()
func you can use to express an interval (like using TimeInterval
) in terms of other time units (for example let x = 120.seconds.in(.minute)
will return 2 minutes).DateComponents
can now be merged using &&
operator. So if you have A = 1.hours, 3.minutes, 2.seconds
and B = 1.year, 40.minutes
, using let C = A && B
you will get a new DateComponents
instance with: C = 1.year, 1.hours, 43.minutes, 2.seconds
..startWeek
(get the first day of the sender's week) and .endWeek
(get the last day of the sender's week) both for Date
and DateInRegion
.inDateDefaultRegion()
is also used as standard value for region in .add()
function of the Date
objecten-US
and not only en
). All translation files were updated to reflect this new behaviour.Date
or DateInRegion
in terms of .nanosecond
granularity. Now the comparision result is correct.Date().add(components:)
and daylight saving dates.Published by malcommac almost 8 years ago