Add: julia-0.6.2

Former-commit-id: ccc667cf67d569f3fb3df39aa57c2134755a7551
This commit is contained in:
2018-02-10 10:27:19 -07:00
parent 94220957d7
commit 019f8e3064
723 changed files with 276164 additions and 0 deletions

View File

@@ -0,0 +1,208 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
# yearmonthday is the opposite of totaldays
# taking Rata Die Day # and returning proleptic Gregorian date
@test Dates.yearmonthday(-306) == (0, 2, 29)
@test Dates.yearmonth(-306) == (0, 2)
@test Dates.monthday(-306) == (2, 29)
@test Dates.yearmonthday(-305) == (0, 3, 1)
@test Dates.yearmonth(-305) == (0, 3)
@test Dates.monthday(-305) == (3, 1)
@test Dates.yearmonthday(-2) == (0, 12, 29)
@test Dates.yearmonth(-2) == (0, 12)
@test Dates.monthday(-2) == (12, 29)
@test Dates.yearmonthday(-1) == (0, 12, 30)
@test Dates.yearmonth(-1) == (0, 12)
@test Dates.monthday(-1) == (12, 30)
@test Dates.yearmonthday(0) == (0, 12, 31)
@test Dates.yearmonth(-0) == (0, 12)
@test Dates.monthday(-0) == (12, 31)
@test Dates.yearmonthday(1) == (1, 1, 1)
@test Dates.yearmonth(1) == (1, 1)
@test Dates.monthday(1) == (1, 1)
# year, month, and day return the indivial components
# of yearmonthday, avoiding additional calculations when possible
@test Dates.year(-1) == 0
@test Dates.month(-1) == 12
@test Dates.day(-1) == 30
@test Dates.year(0) == 0
@test Dates.month(0) == 12
@test Dates.day(0) == 31
@test Dates.year(1) == 1
@test Dates.month(1) == 1
@test Dates.day(1) == 1
@test Dates.yearmonthday(730120) == (2000, 1, 1)
@test Dates.year(730120) == 2000
@test Dates.month(730120) == 1
@test Dates.day(730120) == 1
# Test totaldays and yearmonthday from January 1st of "from" to December 31st of "to"
# test_dates(-10000, 10000) takes about 15 seconds
# test_dates(year(typemin(Date)), year(typemax(Date))) is full range
# and would take.......a really long time
let from=0, to=2100, y=0, m=0, d=0
test_day = Dates.totaldays(from, 1, 1)
for y in from:to
for m = 1:12
for d = 1:Dates.daysinmonth(y, m)
days = Dates.totaldays(y, m, d)
@test days == test_day
@test (y, m, d) == Dates.yearmonthday(days)
test_day += 1
end
end
end
end
# Test year, month, day, hour, minute
let y=0, m=0, d=0, h=0, mi=0
for m = 1:12
for d = 1:Dates.daysinmonth(y, m)
for h = 0:23
for mi = 0:59
dt = Dates.DateTime(y, m, d, h, mi)
@test y == Dates.year(dt)
@test m == Dates.month(dt)
@test d == Dates.day(dt)
@test d == Dates.dayofmonth(dt)
@test h == Dates.hour(dt)
@test mi == Dates.minute(dt)
@test (m, d) == Dates.monthday(dt)
end
end
end
end
end
# Test second, millisecond
let y=0, m=0, d=0, h=0, mi=0, s=0, ms=0
for y in [-2013, -1, 0, 1, 2013]
for m in [1, 6, 12]
for d in [1, 15, Dates.daysinmonth(y, m)]
for h in [0, 12, 23]
for s = 0:59
for ms in [0, 1, 500, 999]
dt = Dates.DateTime(y, m, d, h, mi, s, ms)
@test y == Dates.year(dt)
@test m == Dates.month(dt)
@test d == Dates.day(dt)
@test h == Dates.hour(dt)
@test s == Dates.second(dt)
@test ms == Dates.millisecond(dt)
end
end
end
end
end
end
end
let from=0, to=2100, y=0, m=0, d=0
for y in from:to
for m = 1:12
for d = 1:Dates.daysinmonth(y, m)
dt = Dates.Date(y, m, d)
@test y == Dates.year(dt)
@test m == Dates.month(dt)
@test d == Dates.day(dt)
end
end
end
end
# test hour, minute, second
let h=0, mi=0, s=0, ms=0, us=0, ns=0
for h = (0, 23), mi = (0, 59), s = (0, 59),
ms in (0, 1, 500, 999), us in (0, 1, 500, 999), ns in (0, 1, 500, 999)
t = Dates.Time(h, mi, s, ms, us, ns)
@test h == Dates.hour(t)
@test mi == Dates.minute(t)
@test s == Dates.second(t)
@test ms == Dates.millisecond(t)
@test us == Dates.microsecond(t)
@test ns == Dates.nanosecond(t)
end
end
# week function
# Tests from https://en.wikipedia.org/wiki/ISO_week_date
@test Dates.week(Dates.Date(2005, 1, 1)) == 53
@test Dates.week(Dates.Date(2005, 1, 2)) == 53
@test Dates.week(Dates.Date(2005, 12, 31)) == 52
@test Dates.week(Dates.Date(2007, 1, 1)) == 1
@test Dates.week(Dates.Date(2007, 12, 30)) == 52
@test Dates.week(Dates.Date(2007, 12, 31)) == 1
@test Dates.week(Dates.Date(2008, 1, 1)) == 1
@test Dates.week(Dates.Date(2008, 12, 28)) == 52
@test Dates.week(Dates.Date(2008, 12, 29)) == 1
@test Dates.week(Dates.Date(2008, 12, 30)) == 1
@test Dates.week(Dates.Date(2008, 12, 31)) == 1
@test Dates.week(Dates.Date(2009, 1, 1)) == 1
@test Dates.week(Dates.Date(2009, 12, 31)) == 53
@test Dates.week(Dates.Date(2010, 1, 1)) == 53
@test Dates.week(Dates.Date(2010, 1, 2)) == 53
@test Dates.week(Dates.Date(2010, 1, 2)) == 53
# Tests from http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php?year=1999
dt = Dates.DateTime(1999, 12, 27)
dt1 = Dates.Date(1999, 12, 27)
check = (52, 52, 52, 52, 52, 52, 52, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2)
for i = 1:21
@test Dates.week(dt) == check[i]
@test Dates.week(dt1) == check[i]
dt = dt + Dates.Day(1)
dt1 = dt1 + Dates.Day(1)
end
# Tests from http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php?year=2000
dt = Dates.DateTime(2000, 12, 25)
dt1 = Dates.Date(2000, 12, 25)
for i = 1:21
@test Dates.week(dt) == check[i]
@test Dates.week(dt1) == check[i]
dt = dt + Dates.Day(1)
dt1 = dt1 + Dates.Day(1)
end
# Test from http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php?year=2030
dt = Dates.DateTime(2030, 12, 23)
dt1 = Dates.Date(2030, 12, 23)
for i = 1:21
@test Dates.week(dt) == check[i]
@test Dates.week(dt1) == check[i]
dt = dt + Dates.Day(1)
dt1 = dt1 + Dates.Day(1)
end
# Tests from http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php?year=2004
dt = Dates.DateTime(2004, 12, 20)
dt1 = Dates.Date(2004, 12, 20)
check = (52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 1, 1, 1, 1, 1, 1, 1)
for i = 1:21
@test Dates.week(dt) == check[i]
@test Dates.week(dt1) == check[i]
dt = dt + Dates.Day(1)
dt1 = dt1 + Dates.Day(1)
end
# Vectorized accessors
a = Dates.Date(2014, 1, 1)
dr = [a, a, a, a, a, a, a, a, a, a]
@test Dates.year.(dr) == repmat([2014], 10)
@test Dates.month.(dr) == repmat([1], 10)
@test Dates.day.(dr) == repmat([1], 10)
a = Dates.DateTime(2014, 1, 1)
dr = [a, a, a, a, a, a, a, a, a, a]
@test Dates.year.(dr) == repmat([2014], 10)
@test Dates.month.(dr) == repmat([1], 10)
@test Dates.day.(dr) == repmat([1], 10)
@test Dates.hour.(dr) == repmat([0], 10)
@test Dates.minute.(dr) == repmat([0], 10)
@test Dates.second.(dr) == repmat([0], 10)
@test Dates.millisecond.(dr) == repmat([0], 10)
b = Dates.Time(1, 2, 3, 4, 5, 6)
tr = [b, b, b, b, b, b, b, b, b, b]
@test Dates.hour.(tr) == repmat([1], 10)
@test Dates.minute.(tr) == repmat([2], 10)
@test Dates.second.(tr) == repmat([3], 10)
@test Dates.millisecond.(tr) == repmat([4], 10)
@test Dates.microsecond.(tr) == repmat([5], 10)
@test Dates.nanosecond.(tr) == repmat([6], 10)

View File

@@ -0,0 +1,475 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
#trunc
dt = Dates.Date(2012, 12, 21)
@test trunc(dt, Dates.Year) == Dates.Date(2012)
@test trunc(dt, Dates.Month) == Dates.Date(2012, 12)
@test trunc(dt, Dates.Day) == Dates.Date(2012, 12, 21)
dt = Dates.DateTime(2012, 12, 21, 16, 30, 20, 200)
@test trunc(dt, Dates.Year) == Dates.DateTime(2012)
@test trunc(dt, Dates.Month) == Dates.DateTime(2012, 12)
@test trunc(dt, Dates.Day) == Dates.DateTime(2012, 12, 21)
@test trunc(dt, Dates.Hour) == Dates.DateTime(2012, 12, 21, 16)
@test trunc(dt, Dates.Minute) == Dates.DateTime(2012, 12, 21, 16, 30)
@test trunc(dt, Dates.Second) == Dates.DateTime(2012, 12, 21, 16, 30, 20)
@test trunc(dt, Dates.Millisecond) == Dates.DateTime(2012, 12, 21, 16, 30, 20, 200)
t = Dates.Time(1, 2, 3, 4, 5, 6)
@test trunc(t, Dates.Hour) == Dates.Time(1)
@test trunc(t, Dates.Minute) == Dates.Time(1, 2)
@test trunc(t, Dates.Second) == Dates.Time(1, 2, 3)
@test trunc(t, Dates.Millisecond) == Dates.Time(1, 2, 3, 4)
@test trunc(t, Dates.Microsecond) == Dates.Time(1, 2, 3, 4, 5)
@test trunc(t, Dates.Nanosecond) == Dates.Time(1, 2, 3, 4, 5, 6)
# Date functions
Jan = Dates.DateTime(2013, 1, 1) #Tuesday
Feb = Dates.DateTime(2013, 2, 2) #Saturday
Mar = Dates.DateTime(2013, 3, 3) #Sunday
Apr = Dates.DateTime(2013, 4, 4) #Thursday
May = Dates.DateTime(2013, 5, 5) #Sunday
Jun = Dates.DateTime(2013, 6, 7) #Friday
Jul = Dates.DateTime(2013, 7, 7) #Sunday
Aug = Dates.DateTime(2013, 8, 8) #Thursday
Sep = Dates.DateTime(2013, 9, 9) #Monday
Oct = Dates.DateTime(2013, 10, 10) #Thursday
Nov = Dates.DateTime(2013, 11, 11) #Monday
Dec = Dates.DateTime(2013, 12, 11) #Wednesday
@test Dates.lastdayofmonth(Jan) == Dates.DateTime(2013, 1, 31)
@test Dates.lastdayofmonth(Feb) == Dates.DateTime(2013, 2, 28)
@test Dates.lastdayofmonth(Mar) == Dates.DateTime(2013, 3, 31)
@test Dates.lastdayofmonth(Apr) == Dates.DateTime(2013, 4, 30)
@test Dates.lastdayofmonth(May) == Dates.DateTime(2013, 5, 31)
@test Dates.lastdayofmonth(Jun) == Dates.DateTime(2013, 6, 30)
@test Dates.lastdayofmonth(Jul) == Dates.DateTime(2013, 7, 31)
@test Dates.lastdayofmonth(Aug) == Dates.DateTime(2013, 8, 31)
@test Dates.lastdayofmonth(Sep) == Dates.DateTime(2013, 9, 30)
@test Dates.lastdayofmonth(Oct) == Dates.DateTime(2013, 10, 31)
@test Dates.lastdayofmonth(Nov) == Dates.DateTime(2013, 11, 30)
@test Dates.lastdayofmonth(Dec) == Dates.DateTime(2013, 12, 31)
@test Dates.lastdayofmonth(Date(Jan)) == Dates.Date(2013, 1, 31)
@test Dates.lastdayofmonth(Date(Feb)) == Dates.Date(2013, 2, 28)
@test Dates.lastdayofmonth(Date(Mar)) == Dates.Date(2013, 3, 31)
@test Dates.lastdayofmonth(Date(Apr)) == Dates.Date(2013, 4, 30)
@test Dates.lastdayofmonth(Date(May)) == Dates.Date(2013, 5, 31)
@test Dates.lastdayofmonth(Date(Jun)) == Dates.Date(2013, 6, 30)
@test Dates.lastdayofmonth(Date(Jul)) == Dates.Date(2013, 7, 31)
@test Dates.lastdayofmonth(Date(Aug)) == Dates.Date(2013, 8, 31)
@test Dates.lastdayofmonth(Date(Sep)) == Dates.Date(2013, 9, 30)
@test Dates.lastdayofmonth(Date(Oct)) == Dates.Date(2013, 10, 31)
@test Dates.lastdayofmonth(Date(Nov)) == Dates.Date(2013, 11, 30)
@test Dates.lastdayofmonth(Date(Dec)) == Dates.Date(2013, 12, 31)
@test Dates.firstdayofmonth(Jan) == Dates.DateTime(2013, 1, 1)
@test Dates.firstdayofmonth(Feb) == Dates.DateTime(2013, 2, 1)
@test Dates.firstdayofmonth(Mar) == Dates.DateTime(2013, 3, 1)
@test Dates.firstdayofmonth(Apr) == Dates.DateTime(2013, 4, 1)
@test Dates.firstdayofmonth(May) == Dates.DateTime(2013, 5, 1)
@test Dates.firstdayofmonth(Jun) == Dates.DateTime(2013, 6, 1)
@test Dates.firstdayofmonth(Jul) == Dates.DateTime(2013, 7, 1)
@test Dates.firstdayofmonth(Aug) == Dates.DateTime(2013, 8, 1)
@test Dates.firstdayofmonth(Sep) == Dates.DateTime(2013, 9, 1)
@test Dates.firstdayofmonth(Oct) == Dates.DateTime(2013, 10, 1)
@test Dates.firstdayofmonth(Nov) == Dates.DateTime(2013, 11, 1)
@test Dates.firstdayofmonth(Dec) == Dates.DateTime(2013, 12, 1)
@test Dates.firstdayofmonth(Date(Jan)) == Dates.Date(2013, 1, 1)
@test Dates.firstdayofmonth(Date(Feb)) == Dates.Date(2013, 2, 1)
@test Dates.firstdayofmonth(Date(Mar)) == Dates.Date(2013, 3, 1)
@test Dates.firstdayofmonth(Date(Apr)) == Dates.Date(2013, 4, 1)
@test Dates.firstdayofmonth(Date(May)) == Dates.Date(2013, 5, 1)
@test Dates.firstdayofmonth(Date(Jun)) == Dates.Date(2013, 6, 1)
@test Dates.firstdayofmonth(Date(Jul)) == Dates.Date(2013, 7, 1)
@test Dates.firstdayofmonth(Date(Aug)) == Dates.Date(2013, 8, 1)
@test Dates.firstdayofmonth(Date(Sep)) == Dates.Date(2013, 9, 1)
@test Dates.firstdayofmonth(Date(Oct)) == Dates.Date(2013, 10, 1)
@test Dates.firstdayofmonth(Date(Nov)) == Dates.Date(2013, 11, 1)
@test Dates.firstdayofmonth(Date(Dec)) == Dates.Date(2013, 12, 1)
# Test first day of week; 2014-01-06 is a Monday = 1st day of week
a = Dates.Date(2014, 1, 6)
b = Dates.Date(2014, 1, 7)
c = Dates.Date(2014, 1, 8)
d = Dates.Date(2014, 1, 9)
e = Dates.Date(2014, 1, 10)
f = Dates.Date(2014, 1, 11)
g = Dates.Date(2014, 1, 12)
@test Dates.firstdayofweek(a) == a
@test Dates.firstdayofweek(b) == a
@test Dates.firstdayofweek(c) == a
@test Dates.firstdayofweek(d) == a
@test Dates.firstdayofweek(e) == a
@test Dates.firstdayofweek(f) == a
@test Dates.firstdayofweek(g) == a
# Test firstdayofweek over the course of the year
dt = a
for i = 0:364
@test Dates.firstdayofweek(dt) == a + Dates.Week(div(i, 7))
dt += Dates.Day(1)
end
a = Dates.DateTime(2014, 1, 6)
b = Dates.DateTime(2014, 1, 7)
c = Dates.DateTime(2014, 1, 8)
d = Dates.DateTime(2014, 1, 9)
e = Dates.DateTime(2014, 1, 10)
f = Dates.DateTime(2014, 1, 11)
g = Dates.DateTime(2014, 1, 12)
@test Dates.firstdayofweek(a) == a
@test Dates.firstdayofweek(b) == a
@test Dates.firstdayofweek(c) == a
@test Dates.firstdayofweek(d) == a
@test Dates.firstdayofweek(e) == a
@test Dates.firstdayofweek(f) == a
@test Dates.firstdayofweek(g) == a
dt = a
for i = 0:364
@test Dates.firstdayofweek(dt) == a + Dates.Week(div(i, 7))
dt += Dates.Day(1)
end
@test Dates.firstdayofweek(Dates.DateTime(2013, 12, 24)) == Dates.DateTime(2013, 12, 23)
# Test last day of week; Sunday = last day of week
# 2014-01-12 is a Sunday
a = Dates.Date(2014, 1, 6)
b = Dates.Date(2014, 1, 7)
c = Dates.Date(2014, 1, 8)
d = Dates.Date(2014, 1, 9)
e = Dates.Date(2014, 1, 10)
f = Dates.Date(2014, 1, 11)
g = Dates.Date(2014, 1, 12)
@test Dates.lastdayofweek(a) == g
@test Dates.lastdayofweek(b) == g
@test Dates.lastdayofweek(c) == g
@test Dates.lastdayofweek(d) == g
@test Dates.lastdayofweek(e) == g
@test Dates.lastdayofweek(f) == g
@test Dates.lastdayofweek(g) == g
dt = a
for i = 0:364
@test Dates.lastdayofweek(dt) == g + Dates.Week(div(i, 7))
dt += Dates.Day(1)
end
a = Dates.DateTime(2014, 1, 6)
b = Dates.DateTime(2014, 1, 7)
c = Dates.DateTime(2014, 1, 8)
d = Dates.DateTime(2014, 1, 9)
e = Dates.DateTime(2014, 1, 10)
f = Dates.DateTime(2014, 1, 11)
g = Dates.DateTime(2014, 1, 12)
@test Dates.lastdayofweek(a) == g
@test Dates.lastdayofweek(b) == g
@test Dates.lastdayofweek(c) == g
@test Dates.lastdayofweek(d) == g
@test Dates.lastdayofweek(e) == g
@test Dates.lastdayofweek(f) == g
@test Dates.lastdayofweek(g) == g
dt = a
for i = 0:364
@test Dates.lastdayofweek(dt) == g + Dates.Week(div(i, 7))
dt += Dates.Day(1)
end
@test Dates.lastdayofweek(Dates.DateTime(2013, 12, 24)) == Dates.DateTime(2013, 12, 29)
@test Dates.firstdayofquarter(Dates.Date(2014, 2, 2)) == Dates.Date(2014, 1, 1)
@test Dates.firstdayofquarter(Dates.Date(2014, 5, 2)) == Dates.Date(2014, 4, 1)
@test Dates.firstdayofquarter(Dates.Date(2014, 8, 2)) == Dates.Date(2014, 7, 1)
@test Dates.firstdayofquarter(Dates.Date(2014, 12, 2)) == Dates.Date(2014, 10, 1)
@test Dates.firstdayofquarter(Dates.DateTime(2014, 2, 2)) == Dates.DateTime(2014, 1, 1)
@test Dates.firstdayofquarter(Dates.DateTime(2014, 5, 2)) == Dates.DateTime(2014, 4, 1)
@test Dates.firstdayofquarter(Dates.DateTime(2014, 8, 2)) == Dates.DateTime(2014, 7, 1)
@test Dates.firstdayofquarter(Dates.DateTime(2014, 12, 2)) == Dates.DateTime(2014, 10, 1)
@test Dates.lastdayofquarter(Dates.Date(2014, 2, 2)) == Dates.Date(2014, 3, 31)
@test Dates.lastdayofquarter(Dates.Date(2014, 5, 2)) == Dates.Date(2014, 6, 30)
@test Dates.lastdayofquarter(Dates.Date(2014, 8, 2)) == Dates.Date(2014, 9, 30)
@test Dates.lastdayofquarter(Dates.Date(2014, 12, 2)) == Dates.Date(2014, 12, 31)
@test Dates.lastdayofquarter(Dates.DateTime(2014, 2, 2)) == Dates.DateTime(2014, 3, 31)
@test Dates.lastdayofquarter(Dates.DateTime(2014, 5, 2)) == Dates.DateTime(2014, 6, 30)
@test Dates.lastdayofquarter(Dates.DateTime(2014, 8, 2)) == Dates.DateTime(2014, 9, 30)
@test Dates.lastdayofquarter(Dates.DateTime(2014, 12, 2)) == Dates.DateTime(2014, 12, 31)
firstday = Dates.Date(2014, 1, 1)
lastday = Dates.Date(2014, 12, 31)
for i = 0:364
dt = firstday + Dates.Day(i)
@test Dates.firstdayofyear(dt) == firstday
@test Dates.firstdayofyear(DateTime(dt)) == DateTime(firstday)
@test Dates.lastdayofyear(dt) == lastday
@test Dates.lastdayofyear(DateTime(dt)) == DateTime(lastday)
end
# Adjusters
# Adjuster Constructors
@test Dates.Date(Dates.ismonday, 2014) == Dates.Date(2014, 1, 6)
@test Dates.Date(Dates.ismonday, 2014, 5) == Dates.Date(2014, 5, 5)
@test Dates.DateTime(Dates.ismonday, 2014) == Dates.DateTime(2014, 1, 6)
@test Dates.DateTime(Dates.ismonday, 2014, 5) == Dates.DateTime(2014, 5, 5)
@test Dates.DateTime(x->Dates.hour(x)==12, 2014, 5, 21) == Dates.DateTime(2014, 5, 21, 12)
@test Dates.DateTime(x->Dates.minute(x)==30, 2014, 5, 21, 12) == Dates.DateTime(2014, 5, 21, 12, 30)
@test Dates.DateTime(x->Dates.second(x)==30, 2014, 5, 21, 12, 30) == Dates.DateTime(2014, 5, 21, 12, 30, 30)
@test Dates.DateTime(x->Dates.millisecond(x)==500, 2014, 5, 21, 12, 30, 30) == Dates.DateTime(2014, 5, 21, 12, 30, 30, 500)
# tonext, toprev, tofirst, tolast
dt = Dates.Date(2014, 5, 21)
@test Dates.tonext(dt, Dates.Wed) == Dates.Date(2014, 5, 28)
@test Dates.tonext(dt, Dates.Wed; same=true) == dt
@test Dates.tonext(dt, Dates.Thu) == Dates.Date(2014, 5, 22)
@test Dates.tonext(dt, Dates.Fri) == Dates.Date(2014, 5, 23)
@test Dates.tonext(dt, Dates.Sat) == Dates.Date(2014, 5, 24)
@test Dates.tonext(dt, Dates.Sun) == Dates.Date(2014, 5, 25)
@test Dates.tonext(dt, Dates.Mon) == Dates.Date(2014, 5, 26)
@test Dates.tonext(dt, Dates.Tue) == Dates.Date(2014, 5, 27)
# No dayofweek function for out of range values
@test_throws KeyError Dates.tonext(dt, 8)
@test Dates.tonext(Dates.Date(0), Dates.Mon) == Dates.Date(0, 1, 3)
#test func, diff steps, same
@test Dates.tonext(Dates.iswednesday, dt) == Dates.Date(2014, 5, 28)
@test Dates.tonext(Dates.iswednesday, dt; same=true) == dt
@test Dates.tonext(Dates.isthursday, dt) == Dates.Date(2014, 5, 22)
@test Dates.tonext(Dates.isfriday, dt) == Dates.Date(2014, 5, 23)
@test Dates.tonext(Dates.issaturday, dt) == Dates.Date(2014, 5, 24)
@test Dates.tonext(Dates.issunday, dt) == Dates.Date(2014, 5, 25)
@test Dates.tonext(Dates.ismonday, dt) == Dates.Date(2014, 5, 26)
@test Dates.tonext(Dates.istuesday, dt) == Dates.Date(2014, 5, 27)
@test Dates.tonext(Dates.ismonday, Dates.Date(0)) == Dates.Date(0, 1, 3)
@test Dates.tonext(!Dates.iswednesday, dt) == Dates.Date(2014, 5, 22)
@test Dates.tonext(!Dates.isthursday, dt) == Dates.Date(2014, 5, 23)
# Reach adjust limit
@test_throws ArgumentError Dates.tonext(Dates.iswednesday, dt; limit=6)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Day(2)) == Dates.Date(2014, 6, 4)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Day(3)) == Dates.Date(2014, 6, 11)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Day(4)) == Dates.Date(2014, 6, 18)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Day(5)) == Dates.Date(2014, 6, 25)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Day(6)) == Dates.Date(2014, 7, 2)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Day(7)) == Dates.Date(2014, 5, 28)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Week(1)) == Dates.Date(2014, 5, 28)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Week(2)) == Dates.Date(2014, 6, 4)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Week(3)) == Dates.Date(2014, 6, 11)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Week(4)) == Dates.Date(2014, 6, 18)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Week(5)) == Dates.Date(2014, 6, 25)
@test Dates.tonext(Dates.iswednesday, dt;step=Dates.Week(6)) == Dates.Date(2014, 7, 2)
@test Dates.tonext(Dates.iswednesday, dt; same=true) == dt
@test Dates.tonext(Dates.isthursday, dt) == Dates.Date(2014, 5, 22)
#toprev
@test Dates.toprev(dt, Dates.Wed) == Dates.Date(2014, 5, 14)
@test Dates.toprev(dt, Dates.Wed; same=true) == dt
@test Dates.toprev(dt, Dates.Thu) == Dates.Date(2014, 5, 15)
@test Dates.toprev(dt, Dates.Fri) == Dates.Date(2014, 5, 16)
@test Dates.toprev(dt, Dates.Sat) == Dates.Date(2014, 5, 17)
@test Dates.toprev(dt, Dates.Sun) == Dates.Date(2014, 5, 18)
@test Dates.toprev(dt, Dates.Mon) == Dates.Date(2014, 5, 19)
@test Dates.toprev(dt, Dates.Tue) == Dates.Date(2014, 5, 20)
# No dayofweek function for out of range values
@test_throws KeyError Dates.toprev(dt, 8)
@test Dates.toprev(Dates.Date(0), Dates.Mon) == Dates.Date(-1, 12, 27)
#tofirst
@test Dates.tofirst(dt, Dates.Mon) == Dates.Date(2014, 5, 5)
@test Dates.tofirst(dt, Dates.Tue) == Dates.Date(2014, 5, 6)
@test Dates.tofirst(dt, Dates.Wed) == Dates.Date(2014, 5, 7)
@test Dates.tofirst(dt, Dates.Thu) == Dates.Date(2014, 5, 1)
@test Dates.tofirst(dt, Dates.Fri) == Dates.Date(2014, 5, 2)
@test Dates.tofirst(dt, Dates.Sat) == Dates.Date(2014, 5, 3)
@test Dates.tofirst(dt, Dates.Sun) == Dates.Date(2014, 5, 4)
@test Dates.tofirst(dt, Dates.Mon, of=Dates.Year) == Dates.Date(2014, 1, 6)
@test Dates.tofirst(dt, Dates.Tue, of=Dates.Year) == Dates.Date(2014, 1, 7)
@test Dates.tofirst(dt, Dates.Wed, of=Dates.Year) == Dates.Date(2014, 1, 1)
@test Dates.tofirst(dt, Dates.Thu, of=Dates.Year) == Dates.Date(2014, 1, 2)
@test Dates.tofirst(dt, Dates.Fri, of=Dates.Year) == Dates.Date(2014, 1, 3)
@test Dates.tofirst(dt, Dates.Sat, of=Dates.Year) == Dates.Date(2014, 1, 4)
@test Dates.tofirst(dt, Dates.Sun, of=Dates.Year) == Dates.Date(2014, 1, 5)
@test Dates.tofirst(Dates.Date(0), Dates.Mon) == Dates.Date(0, 1, 3)
#tolast
@test Dates.tolast(dt, Dates.Mon) == Dates.Date(2014, 5, 26)
@test Dates.tolast(dt, Dates.Tue) == Dates.Date(2014, 5, 27)
@test Dates.tolast(dt, Dates.Wed) == Dates.Date(2014, 5, 28)
@test Dates.tolast(dt, Dates.Thu) == Dates.Date(2014, 5, 29)
@test Dates.tolast(dt, Dates.Fri) == Dates.Date(2014, 5, 30)
@test Dates.tolast(dt, Dates.Sat) == Dates.Date(2014, 5, 31)
@test Dates.tolast(dt, Dates.Sun) == Dates.Date(2014, 5, 25)
@test Dates.tolast(dt, Dates.Mon, of=Dates.Year) == Dates.Date(2014, 12, 29)
@test Dates.tolast(dt, Dates.Tue, of=Dates.Year) == Dates.Date(2014, 12, 30)
@test Dates.tolast(dt, Dates.Wed, of=Dates.Year) == Dates.Date(2014, 12, 31)
@test Dates.tolast(dt, Dates.Thu, of=Dates.Year) == Dates.Date(2014, 12, 25)
@test Dates.tolast(dt, Dates.Fri, of=Dates.Year) == Dates.Date(2014, 12, 26)
@test Dates.tolast(dt, Dates.Sat, of=Dates.Year) == Dates.Date(2014, 12, 27)
@test Dates.tolast(dt, Dates.Sun, of=Dates.Year) == Dates.Date(2014, 12, 28)
@test Dates.tolast(Dates.Date(0), Dates.Mon) == Dates.Date(0, 1, 31)
# filter (was recur)
startdate = Dates.Date(2014, 1, 1)
stopdate = Dates.Date(2014, 2, 1)
@test length(filter(x->true, startdate:stopdate)) == 32
@test length(filter(x->true, stopdate:Dates.Day(-1):startdate)) == 32
Januarymondays2014 = [Dates.Date(2014, 1, 6), Dates.Date(2014, 1, 13), Dates.Date(2014, 1, 20), Dates.Date(2014, 1, 27)]
@test filter(Dates.ismonday, startdate:stopdate) == Januarymondays2014
@test_throws MethodError filter((x, y)->x + y, Dates.Date(2013):Dates.Date(2014))
@test_throws MethodError Dates.DateFunction((x, y)->x + y, Date(0))
@test_throws ArgumentError Dates.DateFunction((dt)->2, Date(0))
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 2))) == 32
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 1, 1))) == 1
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 1, 2))) == 2
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 1, 3))) == 3
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 1, 4))) == 4
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 1, 5))) == 5
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 1, 6))) == 6
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 1, 7))) == 7
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2013, 1, 8))) == 8
@test length(filter(x->true, Dates.Date(2013):Dates.Month(1):Dates.Date(2013, 1, 1))) == 1
@test length(filter(x->true, Dates.Date(2013):Dates.Day(-1):Dates.Date(2012, 1, 1))) == 367
# Empty range
@test length(filter(x->true, Dates.Date(2013):Dates.Date(2012, 1, 1))) == 0
# All leap days in 20th century
@test length(filter(Dates.Date(1900):Dates.Date(2000)) do x
Dates.month(x) == Dates.Feb && Dates.day(x) == 29
end) == 24
# Thanksgiving: 4th Thursday of November
thanksgiving = x->Dates.dayofweek(x) == Dates.Thu &&
Dates.month(x) == Dates.Nov &&
Dates.dayofweekofmonth(x) == 4
d = Dates.Date(2014, 6, 5)
@test Dates.tonext(d) do x
thanksgiving(x)
end == Dates.Date(2014, 11, 27)
@test Dates.toprev(d) do x
thanksgiving(x)
end == Dates.Date(2013, 11, 28)
# Pittsburgh street cleaning
dr = Dates.Date(2014):Dates.Date(2015)
@test length(filter(dr) do x
Dates.dayofweek(x) == Dates.Tue &&
Dates.April < Dates.month(x) < Dates.Nov &&
Dates.dayofweekofmonth(x) == 2
end) == 6
# U.S. Federal Holidays
newyears(y) = (y, 1, 1)
independenceday(y) = (y, 7, 4)
veteransday(y) = (y, 11, 11)
christmas(y) = (y, 12, 25)
isnewyears(dt) = Dates.yearmonthday(dt) == newyears(Dates.year(dt))
isindependenceday(dt) = Dates.yearmonthday(dt) == independenceday(Dates.year(dt))
isveteransday(dt) = Dates.yearmonthday(dt) == veteransday(Dates.year(dt))
ischristmas(dt) = Dates.yearmonthday(dt) == christmas(Dates.year(dt))
ismartinlutherking(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == Dates.Jan && Dates.dayofweekofmonth(dt) == 3
ispresidentsday(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == Dates.Feb && Dates.dayofweekofmonth(dt) == 3
# Last Monday of May
ismemorialday(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == Dates.May &&
Dates.dayofweekofmonth(dt) == Dates.daysofweekinmonth(dt)
islaborday(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == Dates.Sep && Dates.dayofweekofmonth(dt) == 1
iscolumbusday(dt) = Dates.dayofweek(dt) == Dates.Mon &&
Dates.month(dt) == Dates.Oct && Dates.dayofweekofmonth(dt) == 2
isthanksgiving(dt) = Dates.dayofweek(dt) == Dates.Thu &&
Dates.month(dt) == Dates.Nov && Dates.dayofweekofmonth(dt) == 4
function easter(y)
# Butcher's Algorithm: http://www.smart.net/~mmontes/butcher.html
a = y % 19
b = div(y, 100)
c = y % 100
d = div(b, 4)
e = b % 4
f = div(b + 8, 25)
g = div(b - f + 1, 3)
h = (19 * a + b - d - g + 15) % 30
i = div(c, 4)
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = div(a + 11 * h + 22 * l, 451)
month = div(h + l - 7 * m + 114, 31)
p = (h + l - 7 * m + 114) % 31
return (y, month, p + 1)
end
iseaster(dt) = Dates.yearmonthday(dt) == easter(Dates.year(dt))
const HOLIDAYS = x->isnewyears(x) || isindependenceday(x) ||
isveteransday(x) || ischristmas(x) ||
ismartinlutherking(x) || ispresidentsday(x) ||
ismemorialday(x) || islaborday(x) ||
iscolumbusday(x) || isthanksgiving(x)
@test length(filter(HOLIDAYS, dr)) == 11
const OBSERVEDHOLIDAYS = x->begin
# If the holiday is on a weekday
if HOLIDAYS(x) && Dates.dayofweek(x) < Dates.Saturday
return true
# Holiday is observed Monday if falls on Sunday
elseif Dates.dayofweek(x) == 1 && HOLIDAYS(x - Dates.Day(1))
return true
# Holiday is observed Friday if falls on Saturday
elseif Dates.dayofweek(x) == 5 && HOLIDAYS(x + Dates.Day(1))
return true
else
return false
end
end
observed = filter(OBSERVEDHOLIDAYS, Dates.Date(1999):Dates.Date(2000))
@test length(observed) == 11
@test observed[10] == Dates.Date(1999, 12, 24)
@test observed[11] == Dates.Date(1999, 12, 31)
# Get all business/working days of 2014
# Since we have already defined observed holidays,
# we just look at weekend days and negate the result
@test length(filter(Dates.Date(2014):Dates.Date(2015)) do x
!(OBSERVEDHOLIDAYS(x) ||
Dates.dayofweek(x) > 5)
end) == 251
# First day of the next month for each day of 2014
@test length([Dates.firstdayofmonth(i + Dates.Month(1))
for i in Dates.Date(2014):Dates.Date(2014, 12, 31)]) == 365
# From those goofy email forwards claiming a "special, lucky month"
# that has 5 Fridays, 5 Saturdays, and 5 Sundays and that it only
# occurs every 823 years
@test length(filter(Date(2000):Dates.Month(1):Date(2016)) do dt
sum = 0
for i = 1:7
sum += Dates.dayofweek(dt) > 4 ? Dates.daysofweekinmonth(dt) : 0
dt += Dates.Day(1)
end
return sum == 15
end) == 15 # On average, there's one of those months every year
r = Dates.Time(x->Dates.second(x) == 5, 1)
@test r == Dates.Time(1, 0, 5)
r = filter(x->Dates.second(x) == 5, Dates.Time(0):Dates.Time(10))
@test length(r) == 600
@test first(r) == Dates.Time(0, 0, 5)
@test last(r) == Dates.Time(9, 59, 5)

View File

@@ -0,0 +1,441 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Time arithmetic
a = Dates.Time(23, 59, 59)
b = Dates.Time(11, 59, 59)
@test Dates.CompoundPeriod(a - b) == Dates.Hour(12)
# Dates.DateTime arithmetic
a = Dates.DateTime(2013, 1, 1, 0, 0, 0, 1)
b = Dates.DateTime(2013, 1, 1, 0, 0, 0, 0)
@test a - b == Dates.Millisecond(1)
@test Dates.DateTime(2013, 1, 2) - b == Dates.Millisecond(86400000)
# Dates.DateTime-Year arithmetic
dt = Dates.DateTime(1999, 12, 27)
@test dt + Dates.Year(1) == Dates.DateTime(2000, 12, 27)
@test dt + Dates.Year(100) == Dates.DateTime(2099, 12, 27)
@test dt + Dates.Year(1000) == Dates.DateTime(2999, 12, 27)
@test dt - Dates.Year(1) == Dates.DateTime(1998, 12, 27)
@test dt - Dates.Year(100) == Dates.DateTime(1899, 12, 27)
@test dt - Dates.Year(1000) == Dates.DateTime(999, 12, 27)
dt = Dates.DateTime(2000, 2, 29)
@test dt + Dates.Year(1) == Dates.DateTime(2001, 2, 28)
@test dt - Dates.Year(1) == Dates.DateTime(1999, 2, 28)
@test dt + Dates.Year(4) == Dates.DateTime(2004, 2, 29)
@test dt - Dates.Year(4) == Dates.DateTime(1996, 2, 29)
dt = Dates.DateTime(1972, 6, 30, 23, 59, 59)
@test dt + Dates.Year(1) == Dates.DateTime(1973, 6, 30, 23, 59, 59)
@test dt - Dates.Year(1) == Dates.DateTime(1971, 6, 30, 23, 59, 59)
@test dt + Dates.Year(-1) == Dates.DateTime(1971, 6, 30, 23, 59, 59)
@test dt - Dates.Year(-1) == Dates.DateTime(1973, 6, 30, 23, 59, 59)
# Wrapping arithemtic for Months
# This ends up being trickier than expected because
# the user might do 2014-01-01 + Month(-14)
# monthwrap figures out the resulting month
# when adding/subtracting months from a date
@test Dates.monthwrap(1, -14) == 11
@test Dates.monthwrap(1, -13) == 12
@test Dates.monthwrap(1, -12) == 1
@test Dates.monthwrap(1, -11) == 2
@test Dates.monthwrap(1, -10) == 3
@test Dates.monthwrap(1, -9) == 4
@test Dates.monthwrap(1, -8) == 5
@test Dates.monthwrap(1, -7) == 6
@test Dates.monthwrap(1, -6) == 7
@test Dates.monthwrap(1, -5) == 8
@test Dates.monthwrap(1, -4) == 9
@test Dates.monthwrap(1, -3) == 10
@test Dates.monthwrap(1, -2) == 11
@test Dates.monthwrap(1, -1) == 12
@test Dates.monthwrap(1, 0) == 1
@test Dates.monthwrap(1, 1) == 2
@test Dates.monthwrap(1, 2) == 3
@test Dates.monthwrap(1, 3) == 4
@test Dates.monthwrap(1, 4) == 5
@test Dates.monthwrap(1, 5) == 6
@test Dates.monthwrap(1, 6) == 7
@test Dates.monthwrap(1, 7) == 8
@test Dates.monthwrap(1, 8) == 9
@test Dates.monthwrap(1, 9) == 10
@test Dates.monthwrap(1, 10) == 11
@test Dates.monthwrap(1, 11) == 12
@test Dates.monthwrap(1, 12) == 1
@test Dates.monthwrap(1, 13) == 2
@test Dates.monthwrap(1, 24) == 1
@test Dates.monthwrap(12, -14) == 10
@test Dates.monthwrap(12, -13) == 11
@test Dates.monthwrap(12, -12) == 12
@test Dates.monthwrap(12, -11) == 1
@test Dates.monthwrap(12, -2) == 10
@test Dates.monthwrap(12, -1) == 11
@test Dates.monthwrap(12, 0) == 12
@test Dates.monthwrap(12, 1) == 1
@test Dates.monthwrap(12, 2) == 2
@test Dates.monthwrap(12, 11) == 11
@test Dates.monthwrap(12, 12) == 12
@test Dates.monthwrap(12, 13) == 1
# yearwrap figures out the resulting year
# when adding/subtracting months from a date
@test Dates.yearwrap(2000, 1, -3600) == 1700
@test Dates.yearwrap(2000, 1, -37) == 1996
@test Dates.yearwrap(2000, 1, -36) == 1997
@test Dates.yearwrap(2000, 1, -35) == 1997
@test Dates.yearwrap(2000, 1, -25) == 1997
@test Dates.yearwrap(2000, 1, -24) == 1998
@test Dates.yearwrap(2000, 1, -23) == 1998
@test Dates.yearwrap(2000, 1, -14) == 1998
@test Dates.yearwrap(2000, 1, -13) == 1998
@test Dates.yearwrap(2000, 1, -12) == 1999
@test Dates.yearwrap(2000, 1, -11) == 1999
@test Dates.yearwrap(2000, 1, -2) == 1999
@test Dates.yearwrap(2000, 1, -1) == 1999
@test Dates.yearwrap(2000, 1, 0) == 2000
@test Dates.yearwrap(2000, 1, 1) == 2000
@test Dates.yearwrap(2000, 1, 11) == 2000
@test Dates.yearwrap(2000, 1, 12) == 2001
@test Dates.yearwrap(2000, 1, 13) == 2001
@test Dates.yearwrap(2000, 1, 23) == 2001
@test Dates.yearwrap(2000, 1, 24) == 2002
@test Dates.yearwrap(2000, 1, 25) == 2002
@test Dates.yearwrap(2000, 1, 36) == 2003
@test Dates.yearwrap(2000, 1, 3600) == 2300
@test Dates.yearwrap(2000, 2, -2) == 1999
@test Dates.yearwrap(2000, 3, 10) == 2001
@test Dates.yearwrap(2000, 4, -4) == 1999
@test Dates.yearwrap(2000, 5, 8) == 2001
@test Dates.yearwrap(2000, 6, -18) == 1998
@test Dates.yearwrap(2000, 6, -6) == 1999
@test Dates.yearwrap(2000, 6, 6) == 2000
@test Dates.yearwrap(2000, 6, 7) == 2001
@test Dates.yearwrap(2000, 6, 19) == 2002
@test Dates.yearwrap(2000, 12, -3600) == 1700
@test Dates.yearwrap(2000, 12, -36) == 1997
@test Dates.yearwrap(2000, 12, -35) == 1998
@test Dates.yearwrap(2000, 12, -24) == 1998
@test Dates.yearwrap(2000, 12, -23) == 1999
@test Dates.yearwrap(2000, 12, -14) == 1999
@test Dates.yearwrap(2000, 12, -13) == 1999
@test Dates.yearwrap(2000, 12, -12) == 1999
@test Dates.yearwrap(2000, 12, -11) == 2000
@test Dates.yearwrap(2000, 12, -2) == 2000
@test Dates.yearwrap(2000, 12, -1) == 2000
@test Dates.yearwrap(2000, 12, 0) == 2000
@test Dates.yearwrap(2000, 12, 1) == 2001
@test Dates.yearwrap(2000, 12, 11) == 2001
@test Dates.yearwrap(2000, 12, 12) == 2001
@test Dates.yearwrap(2000, 12, 13) == 2002
@test Dates.yearwrap(2000, 12, 24) == 2002
@test Dates.yearwrap(2000, 12, 25) == 2003
@test Dates.yearwrap(2000, 12, 36) == 2003
@test Dates.yearwrap(2000, 12, 37) == 2004
@test Dates.yearwrap(2000, 12, 3600) == 2300
dt = Dates.DateTime(1999, 12, 27)
@test dt + Dates.Month(1) == Dates.DateTime(2000, 1, 27)
@test dt + Dates.Month(-1) == Dates.DateTime(1999, 11, 27)
@test dt + Dates.Month(-11) == Dates.DateTime(1999, 1, 27)
@test dt + Dates.Month(11) == Dates.DateTime(2000, 11, 27)
@test dt + Dates.Month(-12) == Dates.DateTime(1998, 12, 27)
@test dt + Dates.Month(12) == Dates.DateTime(2000, 12, 27)
@test dt + Dates.Month(13) == Dates.DateTime(2001, 1, 27)
@test dt + Dates.Month(100) == Dates.DateTime(2008, 4, 27)
@test dt + Dates.Month(1000) == Dates.DateTime(2083, 4, 27)
@test dt - Dates.Month(1) == Dates.DateTime(1999, 11, 27)
@test dt - Dates.Month(-1) == Dates.DateTime(2000, 1, 27)
@test dt - Dates.Month(100) == Dates.DateTime(1991, 8, 27)
@test dt - Dates.Month(1000) == Dates.DateTime(1916, 8, 27)
dt = Dates.DateTime(2000, 2, 29)
@test dt + Dates.Month(1) == Dates.DateTime(2000, 3, 29)
@test dt - Dates.Month(1) == Dates.DateTime(2000, 1, 29)
dt = Dates.DateTime(1972, 6, 30, 23, 59, 59)
@test dt + Dates.Month(1) == Dates.DateTime(1972, 7, 30, 23, 59, 59)
@test dt - Dates.Month(1) == Dates.DateTime(1972, 5, 30, 23, 59, 59)
@test dt + Dates.Month(-1) == Dates.DateTime(1972, 5, 30, 23, 59, 59)
dt = Dates.DateTime(1999, 12, 27)
@test dt + Dates.Week(1) == Dates.DateTime(2000, 1, 3)
@test dt + Dates.Week(100) == Dates.DateTime(2001, 11, 26)
@test dt + Dates.Week(1000) == Dates.DateTime(2019, 2, 25)
@test dt - Dates.Week(1) == Dates.DateTime(1999, 12, 20)
@test dt - Dates.Week(100) == Dates.DateTime(1998, 1, 26)
@test dt - Dates.Week(1000) == Dates.DateTime(1980, 10, 27)
dt = Dates.DateTime(2000, 2, 29)
@test dt + Dates.Week(1) == Dates.DateTime(2000, 3, 7)
@test dt - Dates.Week(1) == Dates.DateTime(2000, 2, 22)
dt = Dates.DateTime(1972, 6, 30, 23, 59, 59)
@test dt + Dates.Week(1) == Dates.DateTime(1972, 7, 7, 23, 59, 59)
@test dt - Dates.Week(1) == Dates.DateTime(1972, 6, 23, 23, 59, 59)
@test dt + Dates.Week(-1) == Dates.DateTime(1972, 6, 23, 23, 59, 59)
dt = Dates.DateTime(1999, 12, 27)
@test dt + Dates.Day(1) == Dates.DateTime(1999, 12, 28)
@test dt + Dates.Day(100) == Dates.DateTime(2000, 4, 5)
@test dt + Dates.Day(1000) == Dates.DateTime(2002, 9, 22)
@test dt - Dates.Day(1) == Dates.DateTime(1999, 12, 26)
@test dt - Dates.Day(100) == Dates.DateTime(1999, 9, 18)
@test dt - Dates.Day(1000) == Dates.DateTime(1997, 4, 1)
dt = Dates.DateTime(1972, 6, 30, 23, 59, 59)
@test dt + Dates.Day(1) == Dates.DateTime(1972, 7, 1, 23, 59, 59)
@test dt - Dates.Day(1) == Dates.DateTime(1972, 6, 29, 23, 59, 59)
@test dt + Dates.Day(-1) == Dates.DateTime(1972, 6, 29, 23, 59, 59)
dt = Dates.DateTime(1999, 12, 27)
@test dt + Dates.Hour(1) == Dates.DateTime(1999, 12, 27, 1)
@test dt + Dates.Hour(100) == Dates.DateTime(1999, 12, 31, 4)
@test dt + Dates.Hour(1000) == Dates.DateTime(2000, 2, 6, 16)
@test dt - Dates.Hour(1) == Dates.DateTime(1999, 12, 26, 23)
@test dt - Dates.Hour(100) == Dates.DateTime(1999, 12, 22, 20)
@test dt - Dates.Hour(1000) == Dates.DateTime(1999, 11, 15, 8)
dt = Dates.DateTime(1972, 6, 30, 23, 59, 59)
@test dt + Dates.Hour(1) == Dates.DateTime(1972, 7, 1, 0, 59, 59)
@test dt - Dates.Hour(1) == Dates.DateTime(1972, 6, 30, 22, 59, 59)
@test dt + Dates.Hour(-1) == Dates.DateTime(1972, 6, 30, 22, 59, 59)
dt = Dates.DateTime(1999, 12, 27)
@test dt + Dates.Minute(1) == Dates.DateTime(1999, 12, 27, 0, 1)
@test dt + Dates.Minute(100) == Dates.DateTime(1999, 12, 27, 1, 40)
@test dt + Dates.Minute(1000) == Dates.DateTime(1999, 12, 27, 16, 40)
@test dt - Dates.Minute(1) == Dates.DateTime(1999, 12, 26, 23, 59)
@test dt - Dates.Minute(100) == Dates.DateTime(1999, 12, 26, 22, 20)
@test dt - Dates.Minute(1000) == Dates.DateTime(1999, 12, 26, 7, 20)
dt = Dates.DateTime(1972, 6, 30, 23, 59, 59)
@test dt + Dates.Minute(1) == Dates.DateTime(1972, 7, 1, 0, 0, 59)
@test dt - Dates.Minute(1) == Dates.DateTime(1972, 6, 30, 23, 58, 59)
@test dt + Dates.Minute(-1) == Dates.DateTime(1972, 6, 30, 23, 58, 59)
dt = Dates.DateTime(1999, 12, 27)
@test dt + Dates.Second(1) == Dates.DateTime(1999, 12, 27, 0, 0, 1)
@test dt + Dates.Second(100) == Dates.DateTime(1999, 12, 27, 0, 1, 40)
@test dt + Dates.Second(1000) == Dates.DateTime(1999, 12, 27, 0, 16, 40)
@test dt - Dates.Second(1) == Dates.DateTime(1999, 12, 26, 23, 59, 59)
@test dt - Dates.Second(100) == Dates.DateTime(1999, 12, 26, 23, 58, 20)
@test dt - Dates.Second(1000) == Dates.DateTime(1999, 12, 26, 23, 43, 20)
dt = Dates.DateTime(1999, 12, 27)
@test dt + Dates.Millisecond(1) == Dates.DateTime(1999, 12, 27, 0, 0, 0, 1)
@test dt + Dates.Millisecond(100) == Dates.DateTime(1999, 12, 27, 0, 0, 0, 100)
@test dt + Dates.Millisecond(1000) == Dates.DateTime(1999, 12, 27, 0, 0, 1)
@test dt - Dates.Millisecond(1) == Dates.DateTime(1999, 12, 26, 23, 59, 59, 999)
@test dt - Dates.Millisecond(100) == Dates.DateTime(1999, 12, 26, 23, 59, 59, 900)
@test dt - Dates.Millisecond(1000) == Dates.DateTime(1999, 12, 26, 23, 59, 59)
dt = Dates.DateTime(1972, 6, 30, 23, 59, 59)
@test dt + Dates.Millisecond(1) == Dates.DateTime(1972, 6, 30, 23, 59, 59, 1)
@test dt - Dates.Millisecond(1) == Dates.DateTime(1972, 6, 30, 23, 59, 58, 999)
@test dt + Dates.Millisecond(-1) == Dates.DateTime(1972, 6, 30, 23, 59, 58, 999)
dt = Dates.Date(1999, 12, 27)
@test dt + Dates.Year(1) == Dates.Date(2000, 12, 27)
@test dt + Dates.Year(100) == Dates.Date(2099, 12, 27)
@test dt + Dates.Year(1000) == Dates.Date(2999, 12, 27)
@test dt - Dates.Year(1) == Dates.Date(1998, 12, 27)
@test dt - Dates.Year(100) == Dates.Date(1899, 12, 27)
@test dt - Dates.Year(1000) == Dates.Date(999, 12, 27)
dt = Dates.Date(2000, 2, 29)
@test dt + Dates.Year(1) == Dates.Date(2001, 2, 28)
@test dt - Dates.Year(1) == Dates.Date(1999, 2, 28)
@test dt + Dates.Year(4) == Dates.Date(2004, 2, 29)
@test dt - Dates.Year(4) == Dates.Date(1996, 2, 29)
dt = Dates.Date(1999, 12, 27)
@test dt + Dates.Month(1) == Dates.Date(2000, 1, 27)
@test dt + Dates.Month(100) == Dates.Date(2008, 4, 27)
@test dt + Dates.Month(1000) == Dates.Date(2083, 4, 27)
@test dt - Dates.Month(1) == Dates.Date(1999, 11, 27)
@test dt - Dates.Month(100) == Dates.Date(1991, 8, 27)
@test dt - Dates.Month(1000) == Dates.Date(1916, 8, 27)
dt = Dates.Date(2000, 2, 29)
@test dt + Dates.Month(1) == Dates.Date(2000, 3, 29)
@test dt - Dates.Month(1) == Dates.Date(2000, 1, 29)
dt = Dates.Date(1999, 12, 27)
@test dt + Dates.Week(1) == Dates.Date(2000, 1, 3)
@test dt + Dates.Week(100) == Dates.Date(2001, 11, 26)
@test dt + Dates.Week(1000) == Dates.Date(2019, 2, 25)
@test dt - Dates.Week(1) == Dates.Date(1999, 12, 20)
@test dt - Dates.Week(100) == Dates.Date(1998, 1, 26)
@test dt - Dates.Week(1000) == Dates.Date(1980, 10, 27)
dt = Dates.Date(2000, 2, 29)
@test dt + Dates.Week(1) == Dates.Date(2000, 3, 7)
@test dt - Dates.Week(1) == Dates.Date(2000, 2, 22)
dt = Dates.Date(1999, 12, 27)
@test dt + Dates.Day(1) == Dates.Date(1999, 12, 28)
@test dt + Dates.Day(100) == Dates.Date(2000, 4, 5)
@test dt + Dates.Day(1000) == Dates.Date(2002, 9, 22)
@test dt - Dates.Day(1) == Dates.Date(1999, 12, 26)
@test dt - Dates.Day(100) == Dates.Date(1999, 9, 18)
@test dt - Dates.Day(1000) == Dates.Date(1997, 4, 1)
# Test Time-TimePeriod arithmetic
t = Dates.Time(0)
@test t + Dates.Hour(1) == Dates.Time(1)
@test t - Dates.Hour(1) == Dates.Time(23)
@test t - Dates.Nanosecond(1) == Dates.Time(23, 59, 59, 999, 999, 999)
@test t + Dates.Nanosecond(-1) == Dates.Time(23, 59, 59, 999, 999, 999)
@test t + Dates.Hour(24) == t
@test t + Dates.Nanosecond(86400000000000) == t
@test t - Dates.Nanosecond(86400000000000) == t
@test t + Dates.Minute(1) == Dates.Time(0, 1)
@test t + Dates.Second(1) == Dates.Time(0, 0, 1)
@test t + Dates.Millisecond(1) == Dates.Time(0, 0, 0, 1)
@test t + Dates.Microsecond(1) == Dates.Time(0, 0, 0, 0, 1)
@test_throws MethodError t + Dates.Day(1)
# Vectorized Time arithmetic
a = Dates.Time(1, 1, 1)
dr = [a, a, a, a, a, a, a, a, a, a]
b = a + Dates.Hour(1)
@test dr .+ Dates.Hour(1) == repmat([b], 10)
b = a + Dates.Second(1)
@test dr .+ Dates.Second(1) == repmat([b], 10)
b = a + Dates.Millisecond(1)
@test dr .+ Dates.Millisecond(1) == repmat([b], 10)
b = a + Dates.Microsecond(1)
@test dr .+ Dates.Microsecond(1) == repmat([b], 10)
b = a + Dates.Nanosecond(1)
@test dr .+ Dates.Nanosecond(1) == repmat([b], 10)
b = a - Dates.Hour(1)
@test dr .- Dates.Hour(1) == repmat([b], 10)
b = a - Dates.Second(1)
@test dr .- Dates.Second(1) == repmat([b], 10)
b = a - Dates.Millisecond(1)
@test dr .- Dates.Millisecond(1) == repmat([b], 10)
b = a - Dates.Microsecond(1)
@test dr .- Dates.Microsecond(1) == repmat([b], 10)
b = a - Dates.Nanosecond(1)
@test dr .- Dates.Nanosecond(1) == repmat([b], 10)
# Vectorized arithmetic
a = Dates.Date(2014, 1, 1)
dr = [a, a, a, a, a, a, a, a, a, a]
b = a + Dates.Year(1)
@test dr .+ Dates.Year(1) == repmat([b], 10)
b = a + Dates.Month(1)
@test dr .+ Dates.Month(1) == repmat([b], 10)
b = a + Dates.Day(1)
@test dr .+ Dates.Day(1) == repmat([b], 10)
b = a - Dates.Year(1)
@test dr .- Dates.Year(1) == repmat([b], 10)
b = a - Dates.Month(1)
@test dr .- Dates.Month(1) == repmat([b], 10)
b = a - Dates.Day(1)
@test dr .- Dates.Day(1) == repmat([b], 10)
# Vectorized arithmetic
b = a + Dates.Year(1)
@test dr .+ Dates.Year(1) == repmat([b], 10)
b = a + Dates.Month(1)
@test dr .+ Dates.Month(1) == repmat([b], 10)
b = a + Dates.Day(1)
@test dr .+ Dates.Day(1) == repmat([b], 10)
b = a - Dates.Year(1)
@test dr .- Dates.Year(1) == repmat([b], 10)
b = a - Dates.Month(1)
@test dr .- Dates.Month(1) == repmat([b], 10)
b = a - Dates.Day(1)
@test dr .- Dates.Day(1) == repmat([b], 10)
# Month arithmetic minimizes "edit distance", or number of changes
# needed to get a correct answer
# This approach results in a few cases of non-associativity
a = Dates.Date(2012, 1, 29)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 1, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 2, 29)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 3, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 4, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 5, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 6, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 8, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 9, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 10, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
a = Dates.Date(2012, 11, 30)
@test (a + Dates.Day(1)) + Dates.Month(1) != (a + Dates.Month(1)) + Dates.Day(1)
dt = Dates.DateTime(2000, 1, 1, 12, 30, 45, 500)
dt2 = dt + Dates.Year(1)
@test Dates.year(dt2) == 2001
@test Dates.month(dt2) == 1
@test Dates.day(dt2) == 1
@test Dates.hour(dt2) == 12
@test Dates.minute(dt2) == 30
@test Dates.second(dt2) == 45
@test Dates.millisecond(dt2) == 500
t1 = [Dates.Date(2009, 1, 1) Dates.Date(2009, 1, 2) Dates.Date(2009, 1, 3); Dates.Date(2009, 2, 1) Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3)]
t2 = [Dates.Date(2009, 1, 2) Dates.Date(2009, 2, 2) Dates.Date(2010, 1, 3); Dates.Date(2010, 2, 1) Dates.Date(2009, 3, 2) Dates.Date(2009, 2, 4)]
t3 = [Dates.DateTime(2009, 1, 1), Dates.DateTime(2009, 1, 2), Dates.DateTime(2009, 1, 3)]
t4 = [Dates.DateTime(2009, 1, 1, 0, 0, 1), Dates.DateTime(2009, 1, 2, 0, 1), Dates.DateTime(2009, 1, 3, 1)]
t5 = [Dates.Time(0, 0, 0) Dates.Time(0, 0, 1) Dates.Time(0, 0, 2); Dates.Time(0, 1, 0) Dates.Time(0, 2, 0) Dates.Time(0, 3, 0)]
# TimeType, Array{TimeType}
@test Dates.Date(2010, 1, 1) .- t1 == [Dates.Day(365) Dates.Day(364) Dates.Day(363); Dates.Day(334) Dates.Day(333) Dates.Day(332)]
@test t1 .- Dates.Date(2010, 1, 1) == [Dates.Day(-365) Dates.Day(-364) Dates.Day(-363); Dates.Day(-334) Dates.Day(-333) Dates.Day(-332)]
@test Dates.DateTime(2009, 1, 1) .- t3 == [Dates.Millisecond(0), Dates.Millisecond(-86400000), Dates.Millisecond(-172800000)]
@test t3 .- Dates.DateTime(2009, 1, 1) == [Dates.Millisecond(0), Dates.Millisecond(86400000), Dates.Millisecond(172800000)]
@test Dates.Date(2010, 1, 1) - t1 == [Dates.Day(365) Dates.Day(364) Dates.Day(363); Dates.Day(334) Dates.Day(333) Dates.Day(332)]
@test t1 - Dates.Date(2010, 1, 1) == [Dates.Day(-365) Dates.Day(-364) Dates.Day(-363); Dates.Day(-334) Dates.Day(-333) Dates.Day(-332)]
@test Dates.DateTime(2009, 1, 1) - t3 == [Dates.Millisecond(0), Dates.Millisecond(-86400000), Dates.Millisecond(-172800000)]
@test t3 - Dates.DateTime(2009, 1, 1) == [Dates.Millisecond(0), Dates.Millisecond(86400000), Dates.Millisecond(172800000)]
@test Dates.Time(2) .- t5 == [Dates.Nanosecond(7200000000000) Dates.Nanosecond(7199000000000) Dates.Nanosecond(7198000000000);
Dates.Nanosecond(7140000000000) Dates.Nanosecond(7080000000000) Dates.Nanosecond(7020000000000)]
# GeneralPeriod, Array{TimeType}
@test Dates.Day(1) .+ t1 == [Dates.Date(2009, 1, 2) Dates.Date(2009, 1, 3) Dates.Date(2009, 1, 4); Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3) Dates.Date(2009, 2, 4)]
@test Dates.Hour(1) .+ t3 == [Dates.DateTime(2009, 1, 1, 1), Dates.DateTime(2009, 1, 2, 1), Dates.DateTime(2009, 1, 3, 1)]
@test t1 .+ Dates.Day(1) == [Dates.Date(2009, 1, 2) Dates.Date(2009, 1, 3) Dates.Date(2009, 1, 4); Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3) Dates.Date(2009, 2, 4)]
@test t3 .+ Dates.Hour(1) == [Dates.DateTime(2009, 1, 1, 1), Dates.DateTime(2009, 1, 2, 1), Dates.DateTime(2009, 1, 3, 1)]
@test Dates.Day(1) + t1 == [Dates.Date(2009, 1, 2) Dates.Date(2009, 1, 3) Dates.Date(2009, 1, 4); Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3) Dates.Date(2009, 2, 4)]
@test Dates.Hour(1) + t3 == [Dates.DateTime(2009, 1, 1, 1), Dates.DateTime(2009, 1, 2, 1), Dates.DateTime(2009, 1, 3, 1)]
@test t1 + Dates.Day(1) == [Dates.Date(2009, 1, 2) Dates.Date(2009, 1, 3) Dates.Date(2009, 1, 4); Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3) Dates.Date(2009, 2, 4)]
@test t3 + Dates.Hour(1) == [Dates.DateTime(2009, 1, 1, 1), Dates.DateTime(2009, 1, 2, 1), Dates.DateTime(2009, 1, 3, 1)]
@test t5 + Dates.Hour(1) == [Dates.Time(1, 0, 0) Dates.Time(1, 0, 1) Dates.Time(1, 0, 2); Dates.Time(1, 1, 0) Dates.Time(1, 2, 0) Dates.Time(1, 3, 0)]
@test (Dates.Month(1) + Dates.Day(1)) .+ t1 == [Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3) Dates.Date(2009, 2, 4); Dates.Date(2009, 3, 2) Dates.Date(2009, 3, 3) Dates.Date(2009, 3, 4)]
@test (Dates.Hour(1) + Dates.Minute(1)) .+ t3 == [Dates.DateTime(2009, 1, 1, 1, 1), Dates.DateTime(2009, 1, 2, 1, 1), Dates.DateTime(2009, 1, 3, 1, 1)]
@test t1 .+ (Dates.Month(1) + Dates.Day(1)) == [Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3) Dates.Date(2009, 2, 4); Dates.Date(2009, 3, 2) Dates.Date(2009, 3, 3) Dates.Date(2009, 3, 4)]
@test t3 .+ (Dates.Hour(1) + Dates.Minute(1)) == [Dates.DateTime(2009, 1, 1, 1, 1), Dates.DateTime(2009, 1, 2, 1, 1), Dates.DateTime(2009, 1, 3, 1, 1)]
@test (Dates.Month(1) + Dates.Day(1)) + t1 == [Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3) Dates.Date(2009, 2, 4); Dates.Date(2009, 3, 2) Dates.Date(2009, 3, 3) Dates.Date(2009, 3, 4)]
@test (Dates.Hour(1) + Dates.Minute(1)) + t3 == [Dates.DateTime(2009, 1, 1, 1, 1), Dates.DateTime(2009, 1, 2, 1, 1), Dates.DateTime(2009, 1, 3, 1, 1)]
@test t1 + (Dates.Month(1) + Dates.Day(1)) == [Dates.Date(2009, 2, 2) Dates.Date(2009, 2, 3) Dates.Date(2009, 2, 4); Dates.Date(2009, 3, 2) Dates.Date(2009, 3, 3) Dates.Date(2009, 3, 4)]
@test t3 + (Dates.Hour(1) + Dates.Minute(1)) == [Dates.DateTime(2009, 1, 1, 1, 1), Dates.DateTime(2009, 1, 2, 1, 1), Dates.DateTime(2009, 1, 3, 1, 1)]
@test t1 .- Dates.Day(1) == [Dates.Date(2008, 12, 31) Dates.Date(2009, 1, 1) Dates.Date(2009, 1, 2); Dates.Date(2009, 1, 31) Dates.Date(2009, 2, 1) Dates.Date(2009, 2, 2)]
@test t3 .- Dates.Hour(1) == [Dates.DateTime(2008, 12, 31, 23), Dates.DateTime(2009, 1, 1, 23), Dates.DateTime(2009, 1, 2, 23)]
@test t1 - Dates.Day(1) == [Dates.Date(2008, 12, 31) Dates.Date(2009, 1, 1) Dates.Date(2009, 1, 2); Dates.Date(2009, 1, 31) Dates.Date(2009, 2, 1) Dates.Date(2009, 2, 2)]
@test t3 - Dates.Hour(1) == [Dates.DateTime(2008, 12, 31, 23), Dates.DateTime(2009, 1, 1, 23), Dates.DateTime(2009, 1, 2, 23)]
@test t1 .- (Dates.Month(1) + Dates.Day(1)) == [Dates.Date(2008, 11, 30) Dates.Date(2008, 12, 1) Dates.Date(2008, 12, 2); Dates.Date(2008, 12, 31) Dates.Date(2009, 1, 1) Dates.Date(2009, 1, 2)]
@test t3 .- (Dates.Hour(1) + Dates.Minute(1)) == [Dates.DateTime(2008, 12, 31, 22, 59), Dates.DateTime(2009, 1, 1, 22, 59), Dates.DateTime(2009, 1, 2, 22, 59)]
@test t1 - (Dates.Month(1) + Dates.Day(1)) == [Dates.Date(2008, 11, 30) Dates.Date(2008, 12, 1) Dates.Date(2008, 12, 2); Dates.Date(2008, 12, 31) Dates.Date(2009, 1, 1) Dates.Date(2009, 1, 2)]
@test t3 - (Dates.Hour(1) + Dates.Minute(1)) == [Dates.DateTime(2008, 12, 31, 22, 59), Dates.DateTime(2009, 1, 1, 22, 59), Dates.DateTime(2009, 1, 2, 22, 59)]
# Array{TimeType}, Array{TimeType}
@test t2 - t1 == [Dates.Day(1) Dates.Day(31) Dates.Day(365); Dates.Day(365) Dates.Day(28) Dates.Day(1)]
@test t4 - t3 == [Dates.Millisecond(1000), Dates.Millisecond(60000), Dates.Millisecond(3600000)]
@test (Dates.Date(2009, 1, 1):Dates.Week(1):Dates.Date(2009, 1, 21)) - (Dates.Date(2009, 1, 1):Dates.Day(1):Dates.Date(2009, 1, 3)) == [Dates.Day(0), Dates.Day(6), Dates.Day(12)]
@test (Dates.DateTime(2009, 1, 1, 1, 1, 1):Dates.Second(1):Dates.DateTime(2009, 1, 1, 1, 1, 3)) - (Dates.DateTime(2009, 1, 1, 1, 1):Dates.Second(1):Dates.DateTime(2009, 1, 1, 1, 1, 2)) == [Dates.Second(1), Dates.Second(1), Dates.Second(1)]
# ensure commutative subtraction methods are not defined, #20205
@test_throws MethodError Dates.Day(1) .- t1
@test_throws MethodError Dates.Hour(1) .- t3
@test_throws MethodError Dates.Day(1) - t1
@test_throws MethodError Dates.Hour(1) - t3
@test_throws MethodError (Dates.Month(1) + Dates.Day(1)) .- t1
@test_throws MethodError (Dates.Hour(1) + Dates.Minute(1)) .- t3
@test_throws MethodError (Dates.Month(1) + Dates.Day(1)) - t1
@test_throws MethodError (Dates.Hour(1) + Dates.Minute(1)) - t3

View File

@@ -0,0 +1,112 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Test conversion to and from unix
@test Dates.unix2datetime(Dates.datetime2unix(DateTime(2000, 1, 1))) == DateTime(2000, 1, 1)
@test Dates.value(Dates.DateTime(1970)) == Dates.UNIXEPOCH
# Tests from here: https://en.wikipedia.org/wiki/Unix_time
@test string(Dates.unix2datetime(1095379198.75)) == string("2004-09-16T23:59:58.75")
@test string(Dates.unix2datetime(1095379199.00)) == string("2004-09-16T23:59:59")
@test string(Dates.unix2datetime(1095379199.25)) == string("2004-09-16T23:59:59.25")
@test string(Dates.unix2datetime(1095379199.50)) == string("2004-09-16T23:59:59.5")
@test string(Dates.unix2datetime(1095379199.75)) == string("2004-09-16T23:59:59.75")
@test string(Dates.unix2datetime(1095379200.00)) == string("2004-09-17T00:00:00")
@test string(Dates.unix2datetime(1095379200.25)) == string("2004-09-17T00:00:00.25")
@test string(Dates.unix2datetime(1095379200.50)) == string("2004-09-17T00:00:00.5")
@test string(Dates.unix2datetime(1095379200.75)) == string("2004-09-17T00:00:00.75")
@test string(Dates.unix2datetime(1095379201.00)) == string("2004-09-17T00:00:01")
@test string(Dates.unix2datetime(1095379201.25)) == string("2004-09-17T00:00:01.25")
@test string(Dates.unix2datetime(915148798.75)) == string("1998-12-31T23:59:58.75")
@test string(Dates.unix2datetime(915148799.00)) == string("1998-12-31T23:59:59")
@test string(Dates.unix2datetime(915148799.25)) == string("1998-12-31T23:59:59.25")
@test string(Dates.unix2datetime(915148799.50)) == string("1998-12-31T23:59:59.5")
@test string(Dates.unix2datetime(915148799.75)) == string("1998-12-31T23:59:59.75")
@test string(Dates.unix2datetime(915148800.00)) == string("1999-01-01T00:00:00")
@test string(Dates.unix2datetime(915148800.25)) == string("1999-01-01T00:00:00.25")
@test string(Dates.unix2datetime(915148800.50)) == string("1999-01-01T00:00:00.5")
@test string(Dates.unix2datetime(915148800.75)) == string("1999-01-01T00:00:00.75")
@test string(Dates.unix2datetime(915148801.00)) == string("1999-01-01T00:00:01")
@test string(Dates.unix2datetime(915148801.25)) == string("1999-01-01T00:00:01.25")
# Test conversion to and from Rata Die
@test Date(Dates.rata2datetime(734869)) == Dates.Date(2013, 1, 1)
@test Dates.datetime2rata(Dates.rata2datetime(734869)) == 734869
# Tests from here: http://mysite.verizon.net/aesir_research/date/back.htm#JDN
@test Dates.julian2datetime(1721119.5) == Dates.DateTime(0, 3, 1)
@test Dates.julian2datetime(1721424.5) == Dates.DateTime(0, 12, 31)
@test Dates.julian2datetime(1721425.5) == Dates.DateTime(1, 1, 1)
@test Dates.julian2datetime(2299149.5) == Dates.DateTime(1582, 10, 4)
@test Dates.julian2datetime(2415020.5) == Dates.DateTime(1900, 1, 1)
@test Dates.julian2datetime(2415385.5) == Dates.DateTime(1901, 1, 1)
@test Dates.julian2datetime(2440587.5) == Dates.DateTime(1970, 1, 1)
@test Dates.julian2datetime(2444239.5) == Dates.DateTime(1980, 1, 1)
@test Dates.julian2datetime(2452695.625) == Dates.DateTime(2003, 2, 25, 3)
@test Dates.datetime2julian(Dates.DateTime(2013, 12, 3, 21)) == 2456630.375
@test typeof(Dates.now()) <: Dates.DateTime
@test typeof(Dates.today()) <: Dates.Date
@test typeof(Dates.now(Dates.UTC)) <: Dates.DateTime
if is_apple()
withenv("TZ" => "UTC") do
@test abs(Dates.now() - now(Dates.UTC)) < Dates.Second(1)
end
end
@test abs(Dates.now() - now(Dates.UTC)) < Dates.Hour(16)
# Issue #9171, #9169
let t = Dates.Period[Dates.Week(2), Dates.Day(14), Dates.Hour(14 * 24), Dates.Minute(14 * 24 * 60), Dates.Second(14 * 24 * 60 * 60), Dates.Millisecond(14 * 24 * 60 * 60 * 1000)]
for i = 1:length(t)
Pi = typeof(t[i])
for j = 1:length(t)
@test t[i] == t[j]
end
for j = i+1:length(t)
Pj = typeof(t[j])
tj1 = t[j] + Pj(1)
@test t[i] < tj1
@test_throws InexactError Pi(tj1)
@test_throws InexactError Pj(Pi(typemax(Int64)))
@test_throws InexactError Pj(Pi(typemin(Int64)))
end
end
end
@test Dates.Year(3) == Dates.Month(36)
#@test_throws MethodError Int(Dates.Month(36)) # re-enable when deprecation removed
@test Dates.Year(3) < Dates.Month(37)
@test_throws InexactError convert(Dates.Year, Dates.Month(37))
@test_throws InexactError Dates.Month(Dates.Year(typemax(Int64)))
# Ensure that conversion of 32-bit integers work
let dt = DateTime(1915, 1, 1, 12)
unix = Int32(Dates.datetime2unix(dt))
julian = Int32(Dates.datetime2julian(dt))
@test Dates.unix2datetime(unix) == dt
@test Dates.julian2datetime(julian) == dt
end
# "Conversions" to/from numbers
a = Dates.DateTime(2000)
b = Dates.Date(2000)
@test Dates.value(b) == 730120
@test Dates.value(a) == 63082368000000
@test convert(Dates.DateTime, Dates.Millisecond(63082368000000)) == a
@test convert(Dates.Millisecond, a) == Dates.Millisecond(63082368000000)
@test Dates.DateTime(Dates.UTM(63082368000000)) == a
@test Dates.DateTime(Dates.UTM(63082368000000.0)) == a
@test convert(Dates.Date, Dates.Day(730120)) == b
@test convert(Dates.Day, b) == Dates.Day(730120)
@test Dates.Date(Dates.UTD(730120)) == b
@test Dates.Date(Dates.UTD(730120.0)) == b
@test Dates.Date(Dates.UTD(Int32(730120))) == b
dt = Dates.DateTime(2000, 1, 1, 23, 59, 59, 50)
t = Dates.Time(dt)
@test Dates.hour(t) == 23
@test Dates.minute(t) == 59
@test Dates.second(t) == 59
@test Dates.millisecond(t) == 50
@test Dates.microsecond(t) == 0
@test Dates.nanosecond(t) == 0

View File

@@ -0,0 +1,447 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Test string/show representation of Date
@test string(Dates.Date(1, 1, 1)) == "0001-01-01" # January 1st, 1 AD/CE
@test sprint(show, Dates.Date(1, 1, 1)) == "0001-01-01"
@test string(Dates.Date(0, 12, 31)) == "0000-12-31" # December 31, 1 BC/BCE
@test Dates.Date(1, 1, 1) - Dates.Date(0, 12, 31) == Dates.Day(1)
@test Dates.Date(Dates.UTD(-306)) == Dates.Date(0, 2, 29)
@test string(Dates.Date(0, 1, 1)) == "0000-01-01" # January 1st, 1 BC/BCE
@test string(Dates.Date(-1, 1, 1)) == "-0001-01-01" # January 1st, 2 BC/BCE
@test string(Dates.Date(-1000000, 1, 1)) == "-1000000-01-01"
@test string(Dates.Date(1000000, 1, 1)) == "1000000-01-01"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "2000-01-01T00:00:00.001"
@test sprint(show, Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "2000-01-01T00:00:00.001"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 2)) == "2000-01-01T00:00:00.002"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 500)) == "2000-01-01T00:00:00.5"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 998)) == "2000-01-01T00:00:00.998"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 999)) == "2000-01-01T00:00:00.999"
@test string(Dates.Time(0)) == "00:00:00"
@test string(Dates.Time(0, 1)) == "00:01:00"
@test string(Dates.Time(0, 1, 2)) == "00:01:02"
@test string(Dates.Time(0, 1, 2, 3)) == "00:01:02.003"
@test string(Dates.Time(0, 1, 2, 3, 4)) == "00:01:02.003004"
@test string(Dates.Time(0, 1, 2, 3, 4, 5)) == "00:01:02.003004005"
@test string(Dates.Time(0, 0, 0, 0, 1)) == "00:00:00.000001"
@test string(Dates.Time(0, 0, 0, 0, 0, 1)) == "00:00:00.000000001"
@test string(Dates.Time(0, 0, 0, 1)) == "00:00:00.001"
# DateTime parsing
# Useful reference for different locales: http://library.princeton.edu/departments/tsd/katmandu/reference/months.html
# Allow parsing of strings which are not representable as a TimeType
let str = "02/15/1996 24:00", df = Dates.DateFormat("mm/dd/yyyy HH:MM")
parsed = Any[
Dates.Month(2), Dates.Day(15), Dates.Year(1996), Dates.Hour(24), Dates.Minute(0)
]
@test Dates.parse_components(str, df) == parsed
@test_throws ArgumentError Dates.parse(DateTime, str, df)
end
# DateFormat printing
@test sprint(show, DateFormat("yyyzzxmmdd\\MHH:MM:SS\\P")) == "dateformat\"yyyzzxmmdd\\MHH:MM:SSP\""
@test sprint(show, DateFormat("yyy").tokens[1]) == "DatePart(yyy)"
@test sprint(show, DateFormat("mmzzdd").tokens[2]) == "Delim(zz)"
@test sprint(show, DateFormat("ddxmm").tokens[2]) == "Delim(x)"
@test sprint(show, DateFormat("xxmmxx").tokens[2]) == "DatePart(mm)"
# Common Parsing Patterns
#'1996-January-15'
dt = Dates.DateTime(1996, 1, 15)
f = "yy-mm-dd"
a = "96-01-15"
@test DateTime(a, f) + Dates.Year(1900) == dt
@test Dates.format(dt, f) == a
a1 = "96-1-15"
@test Dates.DateTime(a1, f) + Dates.Year(1900) == dt
@test Dates.format(dt, "yy-m-dd") == a1
a2 = "96-1-1"
@test Dates.DateTime(a2, f) + Dates.Year(1900) + Dates.Day(14) == dt
@test Dates.format(dt - Dates.Day(14), "yy-m-d") == a2
a3 = "1996-1-15"
@test Dates.DateTime(a3, f) == dt
@test Dates.format(dt, "yyyy-m-d") == a3
a4 = "1996-Jan-15"
@test_throws ArgumentError Dates.DateTime(a4, f) # Trying to use month name, but specified only "mm"
f = "yy/uuu/dd"
b = "96/Feb/15"
@test Dates.DateTime(b, f) + Dates.Year(1900) == dt + Dates.Month(1)
@test Dates.format(dt + Dates.Month(1), f) == b
b1 = "1996/Feb/15"
@test Dates.DateTime(b1, f) == dt + Dates.Month(1)
@test Dates.format(dt + Dates.Month(1), "yyyy/uuu/dd") == b1
b2 = "96/Feb/1"
@test Dates.DateTime(b2, f) + Dates.Year(1900) + Dates.Day(14) == dt + Dates.Month(1)
@test Dates.format(dt + Dates.Month(1) - Dates.Day(14), "yy/uuu/d") == b2
# Here we've specifed a text month name, but given a number
b3 = "96/2/15"
@test_throws ArgumentError Dates.DateTime(b3, f)
try
Dates.parse(DateTime, "2012/2/20T9:9:31.25i90", dateformat"yyyy/mm/ddTHH:MM:SS.s")
@test false
catch err
@test isa(err, ArgumentError)
@test err.msg == "Found extra characters at the end of date time string"
end
try
Dates.parse(DateTime, "2012/2/20T9:9:3i90", dateformat"yyyy/mm/ddTHH:MM:SS.s")
@test false
catch err
@test isa(err, ArgumentError)
@test err.msg == "Unable to parse date time. Expected directive Delim(.) at char 16"
end
f = "yy:dd:mm"
c = "96:15:01"
@test Dates.DateTime(c, f) + Dates.Year(1900) == dt
@test Dates.format(dt, f) == c
c1 = "1996:15:01"
@test Dates.DateTime(c1, f) == dt
@test Dates.format(dt, "yyyy:dd:mm") == c1
c2 = "96:15:1"
@test Dates.DateTime(c2, f) + Dates.Year(1900) == dt
@test Dates.format(dt, "yy:dd:m") == c2
c3 = "96:1:01"
@test Dates.DateTime(c3, f) + Dates.Year(1900) + Dates.Day(14) == dt
@test Dates.format(dt - Dates.Day(14), "yy:m:dd") == c3
c4 = "1996:15:01 # random comment"
@test_throws ArgumentError Dates.DateTime(c4, f)
f = "yyyy, uuu, dd"
d = "1996, Jan, 15"
@test Dates.DateTime(d, f) == dt
@test Dates.format(dt, f) == d
d1 = "96, Jan, 15"
@test Dates.DateTime(d1, f) + Dates.Year(1900) == dt
@test Dates.format(dt, "yy, uuu, dd") == d1
d2 = "1996, Jan, 1"
@test Dates.DateTime(d2, f) + Dates.Day(14) == dt
@test Dates.format(dt - Dates.Day(14), "yyyy, uuu, d") == d2
d3 = "1996, 2, 15"
@test_throws ArgumentError Dates.DateTime(d3, f)
f = "yyyy.U.dd"
e = "1996.January.15"
@test Dates.DateTime(e, f) == dt
@test Dates.format(dt, f) == e
e1 = "96.January.15"
@test Dates.DateTime(e1, f) + Dates.Year(1900) == dt
@test Dates.format(dt, "yy.U.dd") == e1
fo = "yyyy m dd"
f = "1996 1 15"
@test Dates.DateTime(f, fo) == dt
@test Dates.format(dt, fo) == f
f1 = "1996 01 15"
@test Dates.DateTime(f1, fo) == dt
@test Dates.format(dt, "yyyy mm dd") == f1
f2 = "1996 1 1"
@test Dates.DateTime(f2, fo) + Dates.Day(14) == dt
@test Dates.format(dt - Dates.Day(14), "yyyy m d") == f2
j = "1996-01-15"
f = "yyyy-mm-dd zzz"
@test Dates.DateTime(j, f) == dt
@test Dates.format(dt, f) == j * " zzz"
k = "1996-01-15 10:00:00"
f = "yyyy-mm-dd HH:MM:SS zzz"
@test Dates.DateTime(k, f) == dt + Dates.Hour(10)
@test Dates.format(dt + Dates.Hour(10), f) == k * " zzz"
l = "1996-01-15 10:10:10.25"
f = "yyyy-mm-dd HH:MM:SS.ss zzz"
@test Dates.DateTime(l, f) == dt + Dates.Hour(10) + Dates.Minute(10) + Dates.Second(10) + Dates.Millisecond(250)
@test Dates.format(dt + Dates.Hour(10) + Dates.Minute(10) + Dates.Second(10) + Dates.Millisecond(250), f) == l * " zzz"
r = "1/15/1996" # Excel
f = "m/dd/yyyy"
@test Dates.DateTime(r, f) == dt
@test Dates.format(dt, f) == r
s = "19960115"
f = "yyyymmdd"
@test Dates.DateTime(s, f) == dt
@test Dates.format(dt, f) == s
v = "1996-01-15 10:00:00"
f = "yyyy-mm-dd HH:MM:SS"
@test Dates.DateTime(v, f) == dt + Dates.Hour(10)
@test Dates.format(dt + Dates.Hour(10), f) == v
w = "1996-01-15T10:00:00"
f = "yyyy-mm-ddTHH:MM:SS zzz"
@test Dates.DateTime(w, f) == dt + Dates.Hour(10)
@test Dates.format(dt + Dates.Hour(10), f) == w * " zzz"
f = "yyyy/m"
y = "1996/1"
@test Dates.DateTime(y, f) == dt - Dates.Day(14)
@test Dates.format(dt, f) == y
y1 = "1996/1/15"
@test_throws ArgumentError Dates.DateTime(y1, f)
y2 = "96/1"
@test Dates.DateTime(y2, f) + Dates.Year(1900) == dt - Dates.Day(14)
@test Dates.format(dt, "yy/m") == y2
f = "yyyy"
z = "1996"
@test Dates.DateTime(z, f) == dt - Dates.Day(14)
@test Dates.format(dt, f) == z
z1 = "1996-3"
@test_throws ArgumentError Dates.DateTime(z1, f)
z2 = "1996-3-1"
@test_throws ArgumentError Dates.DateTime(z2, f)
aa = "1/5/1996"
f = "m/d/yyyy"
@test Dates.DateTime(aa, f) == dt - Dates.Day(10)
@test Dates.format(dt - Dates.Day(10), f) == aa
bb = "5/1/1996"
f = "d/m/yyyy"
@test Dates.DateTime(bb, f) == dt - Dates.Day(10)
@test Dates.format(dt - Dates.Day(10), f) == bb
cc = "01151996"
f = "mmddyyyy"
@test Dates.DateTime(cc, f) == dt
@test Dates.format(dt, f) == cc
dd = "15011996"
f = "ddmmyyyy"
@test Dates.DateTime(dd, f) == dt
@test Dates.format(dt, f) == dd
ee = "01199615"
f = "mmyyyydd"
@test Dates.DateTime(ee, f) == dt
@test Dates.format(dt, f) == ee
ff = "1996-15-Jan"
f = "yyyy-dd-uuu"
@test Dates.DateTime(ff, f) == dt
@test Dates.format(dt, f) == ff
gg = "Jan-1996-15"
f = "uuu-yyyy-dd"
@test Dates.DateTime(gg, f) == dt
@test Dates.format(dt, f) == gg
hh = "1996#1#15"
f = "yyyy#m#d"
@test Dates.DateTime(hh, f) == dt
@test Dates.format(dt, f) == hh
# test prefix.
s = "/1996/1/15"
f = "/yyyy/m/d"
@test Dates.DateTime(s, f) == dt
@test Dates.format(dt, f) == s
@test_throws ArgumentError Dates.DateTime("1996/1/15", f)
# from Jiahao
@test Dates.Date("2009年12月01日", "yyyy年mm月dd日") == Dates.Date(2009, 12, 1)
@test Dates.format(Dates.Date(2009, 12, 1), "yyyy年mm月dd日") == "2009年12月01日"
@test Dates.Date("2009-12-01", "yyyy-mm-dd") == Dates.Date(2009, 12, 1)
# French: from Milan
f = "dd/mm/yyyy"
f2 = "dd/mm/yy"
@test Dates.Date("28/05/2014", f) == Dates.Date(2014, 5, 28)
@test Dates.Date("28/05/14", f2) + Dates.Year(2000) == Dates.Date(2014, 5, 28)
# Customizing locale
Dates.LOCALES["french"] = Dates.DateLocale(
["janvier", "février", "mars", "avril", "mai", "juin",
"juillet", "août", "septembre", "octobre", "novembre", "décembre"],
["janv", "févr", "mars", "avril", "mai", "juin",
"juil", "août", "sept", "oct", "nov", "déc"],
["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"],
[""],
)
f = "dd uuuuu yyyy"
@test Dates.Date("28 mai 2014", f; locale="french") == Dates.Date(2014, 5, 28)
@test Dates.format(Dates.Date(2014, 5, 28), f; locale="french") == "28 mai 2014"
@test Dates.Date("28 févr 2014", f; locale="french") == Dates.Date(2014, 2, 28)
@test Dates.format(Dates.Date(2014, 2, 28), f; locale="french") == "28 févr 2014"
@test Dates.Date("28 août 2014", f; locale="french") == Dates.Date(2014, 8, 28)
@test Dates.format(Dates.Date(2014, 8, 28), f; locale="french") == "28 août 2014"
@test Dates.Date("28 avril 2014", f; locale="french") == Dates.Date(2014, 4, 28)
@test Dates.format(Dates.Date(2014, 4, 28), f; locale="french") == "28 avril 2014"
f = "dd u yyyy"
@test Dates.Date("28 avril 2014", f; locale="french") == Dates.Date(2014, 4, 28)
f = "dduuuuyyyy"
# parses 3 and 4 character month names
@test Dates.Date("28mai2014", f; locale="french") == Dates.Date(2014, 5, 28)
@test Dates.Date("28août2014", f; locale="french") == Dates.Date(2014, 8, 28)
# doesn't parse month name greater than 4 chars
@test_throws ArgumentError Dates.Date("28avril2014", f; locale="french")
# From Tony Fong
f = "dduuuyy"
@test Dates.Date("01Dec09", f) + Dates.Year(2000) == Dates.Date(2009, 12, 1)
@test Dates.format(Dates.Date(2009, 12, 1), f) == "01Dec09"
f = "dduuuyyyy"
@test Dates.Date("01Dec2009", f) == Dates.Date(2009, 12, 1)
@test Dates.format(Dates.Date(2009, 12, 1), f) == "01Dec2009"
f = "duy"
const globex = ["f", "g", "h", "j", "k", "m", "n", "q", "u", "v", "x", "z"]
locale = Dates.DateLocale(globex, map(uppercase, globex), globex[1:7], globex[1:7])
@test Dates.Date("1F4", f; locale=locale) + Dates.Year(2010) == Dates.Date(2014, 1, 1)
@test Dates.format(Dates.Date(2014, 1, 1), f; locale=locale) == "1F4"
# From Matt Bauman
f = "yyyy-mm-ddTHH:MM:SS"
@test Dates.DateTime("2014-05-28T16:46:04", f) == Dates.DateTime(2014, 5, 28, 16, 46, 04)
# Try to break stuff
# Specified mm/dd, but date string has day/mm
@test_throws ArgumentError Dates.DateTime("18/05/2009", "mm/dd/yyyy")
@test_throws ArgumentError Dates.DateTime("18/05/2009 16", "mm/dd/yyyy hh")
# Used "mm" for months AND minutes
@test_throws ArgumentError Dates.DateTime("18/05/2009 16:12", "mm/dd/yyyy hh:mm")
# Date string has different delimiters than format string
@test_throws ArgumentError Dates.DateTime("18:05:2009", "mm/dd/yyyy")
f = "y m d"
@test Dates.Date("1 1 1", f) == Dates.Date(1)
@test Dates.Date("10000000000 1 1", f) == Dates.Date(10000000000)
@test_throws ArgumentError Dates.Date("1 13 1", f)
@test_throws ArgumentError Dates.Date("1 1 32", f)
@test_throws ArgumentError Dates.Date(" 1 1 32", f)
@test_throws ArgumentError Dates.Date("# 1 1 32", f)
@test Dates.Date("1", f) == Dates.Date(1)
@test Dates.Date("1 ", f) == Dates.Date(1)
@test Dates.Date("1 2", f) == Dates.Date(1, 2)
# can't find space delimiter (finds '/'), so fails
@test_throws ArgumentError Dates.Date("2000/1", f)
f = "ymd"
@test Dates.Date("111", f) == Dates.Date(1)
@test Dates.Date("1", f) == Dates.Date(1)
@test Dates.DateTime("20140529 120000", "yyyymmdd HHMMSS") == Dates.DateTime(2014, 5, 29, 12)
@test Dates.Date(string(Dates.Date(dt))) == Dates.Date(dt)
@test Dates.DateTime(string(dt)) == dt
# Vectorized
dr = ["2000-01-01", "2000-01-02", "2000-01-03", "2000-01-04", "2000-01-05",
"2000-01-06", "2000-01-07", "2000-01-08", "2000-01-09", "2000-01-10"]
dr2 = [Dates.Date(2000) : Dates.Date(2000, 1, 10);]
@test Dates.Date(dr) == dr2
@test Dates.Date(dr, "yyyy-mm-dd") == dr2
@test Dates.DateTime.(dr) == Dates.DateTime.(dr2)
@test Dates.DateTime(dr, "yyyy-mm-dd") == Dates.DateTime.(dr2)
@test Dates.format(dr2) == dr
@test Dates.format(dr2, "yyyy-mm-dd") == dr
@test typeof(Dates.Date(dr)) == Array{Date, 1}
# Issue 13
t = Dates.DateTime(1, 1, 1, 14, 51, 0, 118)
@test Dates.DateTime("[14:51:00.118]", "[HH:MM:SS.sss]") == t
@test Dates.DateTime("14:51:00.118", "HH:MM:SS.sss") == t
@test Dates.DateTime("[14:51:00.118?", "[HH:MM:SS.sss?") == t
@test Dates.DateTime("?14:51:00.118?", "?HH:MM:SS.sss?") == t
@test Dates.DateTime("x14:51:00.118", "xHH:MM:SS.sss") == t
@test Dates.DateTime("14:51:00.118]", "HH:MM:SS.sss]") == t
# RFC1123Format
dt = Dates.DateTime(2014, 8, 23, 17, 22, 15)
@test Dates.format(dt, Dates.RFC1123Format) == "Sat, 23 Aug 2014 17:22:15"
@test Dates.DateTime(Dates.format(dt, Dates.RFC1123Format), Dates.RFC1123Format) == dt
@test Dates.format(dt, "yyyy-mm-ddTHH:MM:SS E") == "2014-08-23T17:22:15 Saturday"
@test Dates.format(dt, "yyyy-mm-ddTHH:MM:SS e") == "2014-08-23T17:22:15 Sat"
@test Dates.format(dt, "yyyy-mm-dd E") == "2014-08-23 Saturday"
@test Dates.format(dt, "yyyy-mm-dd e") == "2014-08-23 Sat"
@test Dates.format(dt, "yyyy-e-mm-dd") == "2014-Sat-08-23"
@test Dates.format(Dates.DateTime(2014, 1, 2, 0, 0, 0, 999), Dates.RFC1123Format) == "Thu, 02 Jan 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 2, 18, 0, 0, 0, 9), Dates.RFC1123Format) == "Tue, 18 Feb 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 3, 8, 0, 0, 0, 9), Dates.RFC1123Format) == "Sat, 08 Mar 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 4, 28, 0, 0, 0, 9), Dates.RFC1123Format) == "Mon, 28 Apr 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 5, 10, 0, 0, 0, 9), Dates.RFC1123Format) == "Sat, 10 May 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 6, 4, 0, 0, 0, 9), Dates.RFC1123Format) == "Wed, 04 Jun 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 7, 13, 0, 0, 0, 9), Dates.RFC1123Format) == "Sun, 13 Jul 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 8, 17, 0, 0, 0, 9), Dates.RFC1123Format) == "Sun, 17 Aug 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 9, 20, 0, 0, 0, 9), Dates.RFC1123Format) == "Sat, 20 Sep 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 10, 31, 0, 0, 0, 9), Dates.RFC1123Format) == "Fri, 31 Oct 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 11, 2, 0, 0, 0, 9), Dates.RFC1123Format) == "Sun, 02 Nov 2014 00:00:00"
@test Dates.format(Dates.DateTime(2014, 12, 5, 0, 0, 0, 9), Dates.RFC1123Format) == "Fri, 05 Dec 2014 00:00:00"
dt = Dates.DateTime(2016, 11, 12, 7, 45, 36)
@test parse(Dates.DateTime, "Sat, 12 Nov 2016 07:45:36", Dates.RFC1123Format) == dt
@test parse(Dates.DateTime, "Mon, 12 Nov 2016 07:45:36", Dates.RFC1123Format) == dt # Wrong day of week
@test_throws ArgumentError parse(Date, "Foo, 12 Nov 2016 07:45:36", Dates.RFC1123Format)
# Issue 15195
let f = "YY"
@test Dates.format(Dates.Date(1999), f) == "1999"
@test Dates.format(Dates.Date(9), f) == "09"
@test Dates.format(typemax(Dates.Date), f) == "252522163911149"
end
# Issue: https://github.com/quinnj/TimeZones.jl/issues/19
let
const Zulu = String
function Dates.tryparsenext(d::Dates.DatePart{'Z'}, str, i, len)
Dates.tryparsenext_word(str, i, len, Dates.min_width(d), Dates.max_width(d))
end
str = "2015-07-24T05:38:19.591Z"
dt = Dates.DateTime(2015, 7, 24, 5, 38, 19, 591)
parsed = Any[
Dates.Year(2015), Dates.Month(7), Dates.Day(24),
Dates.Hour(5), Dates.Minute(38), Dates.Second(19), Dates.Millisecond(591)
]
format = "yyyy-mm-ddTHH:MM:SS.sssZ"
escaped_format = "yyyy-mm-dd\\THH:MM:SS.sss\\Z"
# Typically 'Z' isn't treated as a specifier so it doesn't have to be escaped
@test Dates.parse_components(str, Dates.DateFormat(format)) == parsed
@test Dates.parse_components(str, Dates.DateFormat(escaped_format)) == parsed
try
# Make 'Z' into a specifier
Dates.CONVERSION_SPECIFIERS['Z'] = Zulu
Dates.CONVERSION_DEFAULTS[Zulu] = ""
@test Dates.parse_components(str, Dates.DateFormat(format)) == [parsed; Zulu("Z")]
@test Dates.parse_components(str, Dates.DateFormat(escaped_format)) == parsed
finally
delete!(Dates.CONVERSION_SPECIFIERS, 'Z')
delete!(Dates.CONVERSION_DEFAULTS, Zulu)
end
# Ensure that the default behaviour has been restored
@test Dates.parse_components(str, Dates.DateFormat(format)) == parsed
@test Dates.parse_components(str, Dates.DateFormat(escaped_format)) == parsed
end
# Issue 10817
@test Dates.Date("Apr 01 2014", "uuu dd yyyy") == Dates.Date(2014, 4, 1)
@test_throws ArgumentError Dates.Date("Apr 01 xx 2014", "uuu dd zz yyyy")
@test_throws ArgumentError Dates.Date("Apr 01 xx 2014", "uuu dd yyyy")
# Issue 21001
for (ms, str) in zip([0, 1, 20, 300, 450, 678], ["0", "001", "02", "3", "45", "678"])
dt = DateTime(2000, 1, 1, 0, 0, 0, ms)
@test Dates.format(dt, "s") == str
@test Dates.format(dt, "ss") == rpad(str, 2, '0')
@test Dates.format(dt, "sss") == rpad(str, 3, '0')
@test Dates.format(dt, "ssss") == rpad(str, 4, '0')
end
# Issue #21504
@test isnull(tryparse(Dates.Date, "0-1000"))
# Issue #22100
@testset "parse milliseconds" begin
@test Dates.DateTime("2017-Mar-17 00:00:00.0000", "y-u-d H:M:S.s") == Dates.DateTime(2017, 3, 17)
@test Dates.parse_components(".1", Dates.DateFormat(".s")) == [Dates.Millisecond(100)]
@test Dates.parse_components(".12", Dates.DateFormat(".s")) == [Dates.Millisecond(120)]
@test Dates.parse_components(".123", Dates.DateFormat(".s")) == [Dates.Millisecond(123)]
@test Dates.parse_components(".1230", Dates.DateFormat(".s")) == [Dates.Millisecond(123)]
@test_throws InexactError Dates.parse_components(".1234", Dates.DateFormat(".s"))
# Ensure that no overflow occurs when using Int32 literals: Int32(10)^10
@test Dates.parse_components("." * rpad(999, 10, '0'), Dates.DateFormat(".s")) == [Dates.Millisecond(999)]
end

View File

@@ -0,0 +1,396 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Period testing
@test -Dates.Year(1) == Dates.Year(-1)
@test Dates.Year(1) > Dates.Year(0)
@test (Dates.Year(1) < Dates.Year(0)) == false
@test Dates.Year(1) == Dates.Year(1)
@test Dates.Year(1) != 1
@test Dates.Year(1) + Dates.Year(1) == Dates.Year(2)
@test Dates.Year(1) - Dates.Year(1) == zero(Dates.Year)
@test_throws MethodError Dates.Year(1) * Dates.Year(1) == Dates.Year(1)
@test Dates.Year(10) % Dates.Year(4) == Dates.Year(2)
@test gcd(Dates.Year(10), Dates.Year(4)) == Dates.Year(2)
@test lcm(Dates.Year(10), Dates.Year(4)) == Dates.Year(20)
@test div(Dates.Year(10), Dates.Year(3)) == 3
@test div(Dates.Year(10), Dates.Year(4)) == 2
@test div(Dates.Year(10), 4) == Dates.Year(2)
@test Dates.Year(10) / Dates.Year(4) == 2.5
@test mod(Dates.Year(10), Dates.Year(4)) == Dates.Year(2)
@test mod(Dates.Year(-10), Dates.Year(4)) == Dates.Year(2)
@test mod(Dates.Year(10), 4) == Dates.Year(2)
@test mod(Dates.Year(-10), 4) == Dates.Year(2)
@test rem(Dates.Year(10), Dates.Year(4)) == Dates.Year(2)
@test rem(Dates.Year(-10), Dates.Year(4)) == Dates.Year(-2)
@test rem(Dates.Year(10), 4) == Dates.Year(2)
@test rem(Dates.Year(-10), 4) == Dates.Year(-2)
t = Dates.Year(1)
t2 = Dates.Year(2)
@test ([t, t, t, t, t] + Dates.Year(1)) == ([t2, t2, t2, t2, t2])
@test (Dates.Year(1) + [t, t, t, t, t]) == ([t2, t2, t2, t2, t2])
@test ([t2, t2, t2, t2, t2] - Dates.Year(1)) == ([t, t, t, t, t])
@test_throws MethodError ([t, t, t, t, t] .* Dates.Year(1)) == ([t, t, t, t, t])
@test ([t, t, t, t, t] * 1) == ([t, t, t, t, t])
@test ([t, t, t, t, t] .% t2) == ([t, t, t, t, t])
@test div.([t, t, t, t, t], Dates.Year(1)) == ([1, 1, 1, 1, 1])
@test mod.([t, t, t, t, t], Dates.Year(2)) == ([t, t, t, t, t])
@test [t, t, t] / t2 == [0.5, 0.5, 0.5]
@test abs(-t) == t
#Period arithmetic
y = Dates.Year(1)
m = Dates.Month(1)
w = Dates.Week(1)
d = Dates.Day(1)
h = Dates.Hour(1)
mi = Dates.Minute(1)
s = Dates.Second(1)
ms = Dates.Millisecond(1)
us = Dates.Microsecond(1)
ns = Dates.Nanosecond(1)
@test Dates.Year(y) == y
@test Dates.Month(m) == m
@test Dates.Week(w) == w
@test Dates.Day(d) == d
@test Dates.Hour(h) == h
@test Dates.Minute(mi) == mi
@test Dates.Second(s) == s
@test Dates.Millisecond(ms) == ms
@test Dates.Microsecond(us) == us
@test Dates.Nanosecond(ns) == ns
@test Dates.Year(convert(Int8, 1)) == y
@test Dates.Year(convert(UInt8, 1)) == y
@test Dates.Year(convert(Int16, 1)) == y
@test Dates.Year(convert(UInt16, 1)) == y
@test Dates.Year(convert(Int32, 1)) == y
@test Dates.Year(convert(UInt32, 1)) == y
@test Dates.Year(convert(Int64, 1)) == y
@test Dates.Year(convert(UInt64, 1)) == y
@test Dates.Year(convert(Int128, 1)) == y
@test Dates.Year(convert(UInt128, 1)) == y
@test Dates.Year(convert(BigInt, 1)) == y
@test Dates.Year(convert(BigFloat, 1)) == y
@test Dates.Year(convert(Complex, 1)) == y
@test Dates.Year(convert(Rational, 1)) == y
@test Dates.Year(convert(Float16, 1)) == y
@test Dates.Year(convert(Float32, 1)) == y
@test Dates.Year(convert(Float64, 1)) == y
@test y == y
@test m == m
@test w == w
@test d == d
@test h == h
@test mi == mi
@test s == s
@test ms == ms
@test us == us
@test ns == ns
y2 = Dates.Year(2)
@test y < y2
@test y2 > y
@test y != y2
@test Dates.Year(Int8(1)) == y
@test Dates.Year(UInt8(1)) == y
@test Dates.Year(Int16(1)) == y
@test Dates.Year(UInt16(1)) == y
@test Dates.Year(Int(1)) == y
@test Dates.Year(UInt(1)) == y
@test Dates.Year(Int64(1)) == y
@test Dates.Year(UInt64(1)) == y
@test Dates.Year(UInt128(1)) == y
@test Dates.Year(UInt128(1)) == y
@test Dates.Year(big(1)) == y
@test Dates.Year(BigFloat(1)) == y
@test Dates.Year(float(1)) == y
@test Dates.Year(Float32(1)) == y
@test Dates.Year(Rational(1)) == y
@test Dates.Year(complex(1)) == y
@test_throws InexactError Dates.Year(BigFloat(1.2)) == y
@test_throws InexactError Dates.Year(1.2) == y
@test_throws InexactError Dates.Year(Float32(1.2)) == y
@test_throws InexactError Dates.Year(3//4) == y
@test_throws InexactError Dates.Year(complex(1.2)) == y
@test_throws InexactError Dates.Year(Float16(1.2)) == y
@test Dates.Year(true) == y
@test Dates.Year(false) != y
@test_throws MethodError Dates.Year(:hey) == y
@test Dates.Year(real(1)) == y
@test_throws InexactError Dates.Year(m) == y
@test_throws MethodError Dates.Year(w) == y
@test_throws MethodError Dates.Year(d) == y
@test_throws MethodError Dates.Year(h) == y
@test_throws MethodError Dates.Year(mi) == y
@test_throws MethodError Dates.Year(s) == y
@test_throws MethodError Dates.Year(ms) == y
@test Dates.Year(Dates.Date(2013, 1, 1)) == Dates.Year(2013)
@test Dates.Year(Dates.DateTime(2013, 1, 1)) == Dates.Year(2013)
@test typeof(y + m) <: Dates.CompoundPeriod
@test typeof(m + y) <: Dates.CompoundPeriod
@test typeof(y + w) <: Dates.CompoundPeriod
@test typeof(y + d) <: Dates.CompoundPeriod
@test typeof(y + h) <: Dates.CompoundPeriod
@test typeof(y + mi) <: Dates.CompoundPeriod
@test typeof(y + s) <: Dates.CompoundPeriod
@test typeof(y + ms) <: Dates.CompoundPeriod
@test typeof(y + us) <: Dates.CompoundPeriod
@test typeof(y + ns) <: Dates.CompoundPeriod
@test y > m
@test d < w
@test mi < h
@test ms < h
@test ms < mi
@test us < ms
@test ns < ms
@test ns < us
@test ns < w
@test us < w
@test typemax(Dates.Year) == Dates.Year(typemax(Int64))
@test typemax(Dates.Year) + y == Dates.Year(-9223372036854775808)
@test typemin(Dates.Year) == Dates.Year(-9223372036854775808)
#Period-Real arithmetic
@test_throws MethodError y + 1 == Dates.Year(2)
@test_throws MethodError y + true == Dates.Year(2)
@test_throws InexactError y + Dates.Year(1.2)
@test y + Dates.Year(1f0) == Dates.Year(2)
@test y * 4 == Dates.Year(4)
@test y * 4f0 == Dates.Year(4)
@test_throws InexactError y * 3//4 == Dates.Year(1)
@test div(y, 2) == Dates.Year(0)
@test_throws MethodError div(2, y) == Dates.Year(2)
@test div(y, y) == 1
@test y*10 % Dates.Year(5) == Dates.Year(0)
@test_throws MethodError (y > 3) == false
@test_throws MethodError (4 < y) == false
@test 1 != y
t = [y, y, y, y, y]
@test t .+ Dates.Year(2) == [Dates.Year(3), Dates.Year(3), Dates.Year(3), Dates.Year(3), Dates.Year(3)]
let x = Dates.Year(5), y = Dates.Year(2)
@test div(x, y) * y + rem(x, y) == x
@test fld(x, y) * y + mod(x, y) == x
end
# Associativity
dt = Dates.DateTime(2012, 12, 21)
test = ((((((((dt + y) - m) + w) - d) + h) - mi) + s) - ms)
@test test == dt + y - m + w - d + h - mi + s - ms
@test test == y - m + w - d + dt + h - mi + s - ms
@test test == dt - m + y - d + w - mi + h - ms + s
@test test == dt + (y - m + w - d + h - mi + s - ms)
@test test == dt + y - m + w - d + (h - mi + s - ms)
@test (dt + Dates.Year(4)) + Dates.Day(1) == dt + (Dates.Year(4) + Dates.Day(1))
@test Dates.Date(2014, 1, 29) + Dates.Month(1) + Dates.Day(1) + Dates.Month(1) + Dates.Day(1) ==
Dates.Date(2014, 1, 29) + Dates.Day(1) + Dates.Month(1) + Dates.Month(1) + Dates.Day(1)
@test Dates.Date(2014, 1, 29) + Dates.Month(1) + Dates.Day(1) == Dates.Date(2014, 1, 29) + Dates.Day(1) + Dates.Month(1)
# traits
@test Dates._units(Dates.Year(0)) == " years"
@test Dates._units(Dates.Year(1)) == " year"
@test Dates._units(Dates.Year(-1)) == " year"
@test Dates._units(Dates.Year(2)) == " years"
@test Dates.string(Dates.Year(0)) == "0 years"
@test Dates.string(Dates.Year(1)) == "1 year"
@test Dates.string(Dates.Year(-1)) == "-1 year"
@test Dates.string(Dates.Year(2)) == "2 years"
@test zero(Dates.Year) == Dates.Year(0)
@test zero(Dates.Year(10)) == Dates.Year(0)
@test zero(Dates.Month) == Dates.Month(0)
@test zero(Dates.Month(10)) == Dates.Month(0)
@test zero(Dates.Day) == Dates.Day(0)
@test zero(Dates.Day(10)) == Dates.Day(0)
@test zero(Dates.Hour) == Dates.Hour(0)
@test zero(Dates.Hour(10)) == Dates.Hour(0)
@test zero(Dates.Minute) == Dates.Minute(0)
@test zero(Dates.Minute(10)) == Dates.Minute(0)
@test zero(Dates.Second) == Dates.Second(0)
@test zero(Dates.Second(10)) == Dates.Second(0)
@test zero(Dates.Millisecond) == Dates.Millisecond(0)
@test zero(Dates.Millisecond(10)) == Dates.Millisecond(0)
@test Dates.Year(-1) < Dates.Year(1)
@test !(Dates.Year(-1) > Dates.Year(1))
@test Dates.Year(1) == Dates.Year(1)
@test Dates.Year(1) != 1
@test 1 != Dates.Year(1)
@test Dates.Month(-1) < Dates.Month(1)
@test !(Dates.Month(-1) > Dates.Month(1))
@test Dates.Month(1) == Dates.Month(1)
@test Dates.Day(-1) < Dates.Day(1)
@test !(Dates.Day(-1) > Dates.Day(1))
@test Dates.Day(1) == Dates.Day(1)
@test Dates.Hour(-1) < Dates.Hour(1)
@test !(Dates.Hour(-1) > Dates.Hour(1))
@test Dates.Hour(1) == Dates.Hour(1)
@test Dates.Minute(-1) < Dates.Minute(1)
@test !(Dates.Minute(-1) > Dates.Minute(1))
@test Dates.Minute(1) == Dates.Minute(1)
@test Dates.Second(-1) < Dates.Second(1)
@test !(Dates.Second(-1) > Dates.Second(1))
@test Dates.Second(1) == Dates.Second(1)
@test Dates.Millisecond(-1) < Dates.Millisecond(1)
@test !(Dates.Millisecond(-1) > Dates.Millisecond(1))
@test Dates.Millisecond(1) == Dates.Millisecond(1)
@test_throws MethodError Dates.Year(1) < Dates.Millisecond(1)
@test_throws MethodError Dates.Millisecond(1) < Dates.Year(1)
@test_throws MethodError Dates.Year(1) == Dates.Millisecond(1)
@test_throws MethodError Dates.Millisecond(1) == Dates.Year(1)
# Allow comparisons with new Period subtypes
let
# https://en.wikipedia.org/wiki/Swatch_Internet_Time
struct Beat <: Dates.Period
value::Int64
end
Dates.value(b::Beat) = b.value
Dates.toms(b::Beat) = Dates.value(b) * 86400
Dates._units(b::Beat) = " beat" * (abs(Dates.value(b)) == 1 ? "" : "s")
Base.promote_rule(::Type{Dates.Day}, ::Type{Beat}) = Dates.Millisecond
Base.convert{T<:Dates.Millisecond}(::Type{T}, b::Beat) = T(Dates.toms(b))
@test Beat(1000) == Dates.Day(1)
@test Beat(1) < Dates.Day(1)
end
@test Dates.Year("1") == y
@test Dates.Month("1") == m
@test Dates.Week("1") == w
@test Dates.Day("1") == d
@test Dates.Hour("1") == h
@test Dates.Minute("1") == mi
@test Dates.Second("1") == s
@test Dates.Millisecond("1") == ms
@test Dates.Microsecond("1") == us
@test Dates.Nanosecond("1") == ns
@test_throws ArgumentError Dates.Year("1.0")
@test Dates.Year(parse(Float64, "1.0")) == y
dt = Dates.DateTime(2014)
@test typeof(Dates.Year(dt)) <: Dates.Year
@test typeof(Dates.Month(dt)) <: Dates.Month
@test typeof(Dates.Week(dt)) <: Dates.Week
@test typeof(Dates.Day(dt)) <: Dates.Day
@test typeof(Dates.Hour(dt)) <: Dates.Hour
@test typeof(Dates.Minute(dt)) <: Dates.Minute
@test typeof(Dates.Second(dt)) <: Dates.Second
@test typeof(Dates.Millisecond(dt)) <: Dates.Millisecond
# Default values
@test Dates.default(Dates.Year) == y
@test Dates.default(Dates.Month) == m
@test Dates.default(Dates.Week) == w
@test Dates.default(Dates.Day) == d
@test Dates.default(Dates.Hour) == zero(Dates.Hour)
@test Dates.default(Dates.Minute) == zero(Dates.Minute)
@test Dates.default(Dates.Second) == zero(Dates.Second)
@test Dates.default(Dates.Millisecond) == zero(Dates.Millisecond)
@test Dates.default(Dates.Microsecond) == zero(Dates.Microsecond)
@test Dates.default(Dates.Nanosecond) == zero(Dates.Nanosecond)
# Conversions
@test Dates.toms(ms) == Dates.value(Dates.Millisecond(ms)) == 1
@test Dates.toms(s) == Dates.value(Dates.Millisecond(s)) == 1000
@test Dates.toms(mi) == Dates.value(Dates.Millisecond(mi)) == 60000
@test Dates.toms(h) == Dates.value(Dates.Millisecond(h)) == 3600000
@test Dates.toms(d) == Dates.value(Dates.Millisecond(d)) == 86400000
@test Dates.toms(w) == Dates.value(Dates.Millisecond(w)) == 604800000
@test Dates.days(ms) == Dates.days(s) == Dates.days(mi) == Dates.days(h) == 0
@test Dates.days(Dates.Millisecond(86400000)) == 1
@test Dates.days(Dates.Second(86400)) == 1
@test Dates.days(Dates.Minute(1440)) == 1
@test Dates.days(Dates.Hour(24)) == 1
@test Dates.days(d) == 1
@test Dates.days(w) == 7
# issue #9214
@test 2s + (7ms + 1ms) == (2s + 7ms) + 1ms == 1ms + (2s + 7ms) == 1ms + (1s + 7ms) + 1s == 1ms + (2s + 3d + 7ms) + (-3d) == (1ms + (2s + 3d)) + (7ms - 3d) == (1ms + (2s + 3d)) - (3d - 7ms)
@test 1ms - (2s + 7ms) == -((2s + 7ms) - 1ms) == (-6ms) - 2s
emptyperiod = ((y + d) - d) - y
@test emptyperiod == ((d + y) - y) - d == ((d + y) - d) - y
@test emptyperiod == 2y + (m - d) + ms - ((m - d) + 2y + ms)
@test emptyperiod == 0ms
@test string(emptyperiod) == "empty period"
@test string(ms + mi + d + m + y + w + h + s + 2y + m) == "3 years, 2 months, 1 week, 1 day, 1 hour, 1 minute, 1 second, 1 millisecond"
@test 8d - s == 1w + 23h + 59mi + 59s
@test h + 3mi == 63mi
@test y - m == 11m
# compound periods should avoid automatically converting period types
@test (d - h).periods == Dates.Period[d, -h]
@test d - h == 23h
@test !isequal(d - h, 23h)
@test isequal(d - h, 2d - 2h - 1d + 1h)
# reduce compound periods into the most basic form
@test Dates.canonicalize(h - mi).periods == Dates.Period[59mi]
@test Dates.canonicalize(-h + mi).periods == Dates.Period[-59mi]
@test Dates.canonicalize(-y + d).periods == Dates.Period[-y, d]
@test Dates.canonicalize(-y + m - w + d).periods == Dates.Period[-11m, -6d]
@test Dates.canonicalize(-y + m - w + ms).periods == Dates.Period[-11m, -6d, -23h, -59mi, -59s, -999ms]
@test Dates.canonicalize(y - m + w - d + h - mi + s - ms).periods == Dates.Period[11m, 6d, 59mi, 999ms]
@test Dates.canonicalize(-y + m - w + d - h + mi - s + ms).periods == Dates.Period[-11m, -6d, -59mi, -999ms]
@test Dates.Date(2009, 2, 1) - (Dates.Month(1) + Dates.Day(1)) == Dates.Date(2008, 12, 31)
@test_throws MethodError (Dates.Month(1) + Dates.Day(1)) - Dates.Date(2009,2,1)
pa = [1y 1m 1w 1d; 1h 1mi 1s 1ms]
cpa = [1y + 1s 1m + 1s 1w + 1s 1d + 1s; 1h + 1s 1mi + 1s 2m + 1s 1s + 1ms]
@test +pa == pa == -(-pa)
@test -pa == map(-, pa)
@test 1y .+ pa == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
@test (1y + 1m) .+ pa == [2y + 1m 1y + 2m 1y + 1m + 1w 1y + 1m + 1d; 1y + 1m + 1h 1y + 1m + 1mi 1y + 1m + 1s 1y + 1m + 1ms]
@test pa .+ 1y == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
@test pa .+ (1y + 1m) == [2y + 1m 1y + 2m 1y + 1m + 1w 1y + 1m + 1d; 1y + 1m + 1h 1y + 1m + 1mi 1y + 1m + 1s 1y + 1m + 1ms]
@test 1y .+ cpa == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
@test (1y + 1m) .+ cpa == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
@test cpa .+ 1y == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
@test cpa .+ (1y + 1m) == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
@test 1y + pa == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
@test (1y + 1m) + pa == [2y + 1m 1y + 2m 1y + 1m + 1w 1y + 1m + 1d; 1y + 1m + 1h 1y + 1m + 1mi 1y + 1m + 1s 1y + 1m + 1ms]
@test pa + 1y == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
@test pa + (1y + 1m) == [2y + 1m 1y + 2m 1y + 1m + 1w 1y + 1m + 1d; 1y + 1m + 1h 1y + 1m + 1mi 1y + 1m + 1s 1y + 1m + 1ms]
@test 1y + cpa == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
@test (1y + 1m) + cpa == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
@test cpa + 1y == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
@test cpa + (1y + 1m) == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
@test 1y .- pa == [0y 1y-1m 1y-1w 1y-1d; 1y-1h 1y-1mi 1y-1s 1y-1ms]
@test (1y + 1m) .- pa == [1m 1y 1y + 1m-1w 1y + 1m-1d; 1y + 1m-1h 1y + 1m-1mi 1y + 1m-1s 1y + 1m-1ms]
@test pa .- (1y + 1m) == [-1m -1y -1y-1m + 1w -1y-1m + 1d; -1y-1m + 1h -1y-1m + 1mi -1y-1m + 1s -1y-1m + 1ms]
@test pa .- 1y == [0y 1m-1y -1y + 1w -1y + 1d; -1y + 1h -1y + 1mi -1y + 1s -1y + 1ms]
@test 1y .- cpa == [-1s 1y-1m-1s 1y-1w-1s 1y-1d-1s; 1y-1h-1s 1y-1mi-1s 1y-2m-1s 1y-1ms-1s]
@test (1y + 1m) .- cpa == [1m-1s 1y-1s 1y + 1m-1w-1s 1y + 1m-1d-1s; 1y + 1m-1h-1s 1y + 1m-1mi-1s 1y-1m-1s 1y + 1m-1s-1ms]
@test cpa .- 1y == [1s -1y + 1m + 1s -1y + 1w + 1s -1y + 1d + 1s; -1y + 1h + 1s -1y + 1mi + 1s -1y + 2m + 1s -1y + 1ms + 1s]
@test cpa .- (1y + 1m) == [-1m + 1s -1y + 1s -1y-1m + 1w + 1s -1y-1m + 1d + 1s; -1y-1m + 1h + 1s -1y-1m + 1mi + 1s -1y + 1m + 1s -1y + -1m + 1s + 1ms]
@test 1y - pa == [0y 1y-1m 1y-1w 1y-1d; 1y-1h 1y-1mi 1y-1s 1y-1ms]
@test (1y + 1m) - pa == [1m 1y 1y + 1m-1w 1y + 1m-1d; 1y + 1m-1h 1y + 1m-1mi 1y + 1m-1s 1y + 1m-1ms]
@test pa - (1y + 1m) == [-1m -1y -1y-1m + 1w -1y-1m + 1d; -1y-1m + 1h -1y-1m + 1mi -1y-1m + 1s -1y-1m + 1ms]
@test pa - 1y == [0y 1m-1y -1y + 1w -1y + 1d; -1y + 1h -1y + 1mi -1y + 1s -1y + 1ms]
@test 1y - cpa == [-1s 1y-1m-1s 1y-1w-1s 1y-1d-1s; 1y-1h-1s 1y-1mi-1s 1y-2m-1s 1y-1ms-1s]
@test (1y + 1m) - cpa == [1m-1s 1y-1s 1y + 1m-1w-1s 1y + 1m-1d-1s; 1y + 1m-1h-1s 1y + 1m-1mi-1s 1y-1m-1s 1y + 1m-1s-1ms]
@test cpa - 1y == [1s -1y + 1m + 1s -1y + 1w + 1s -1y + 1d + 1s; -1y + 1h + 1s -1y + 1mi + 1s -1y + 2m + 1s -1y + 1ms + 1s]
@test cpa - (1y + 1m) == [-1m + 1s -1y + 1s -1y-1m + 1w + 1s -1y-1m + 1d + 1s; -1y-1m + 1h + 1s -1y-1m + 1mi + 1s -1y + 1m + 1s -1y + -1m + 1s + 1ms]
@test [1y 1m; 1w 1d] + [1h 1mi; 1s 1ms] == [1y + 1h 1m + 1mi; 1w + 1s 1d + 1ms]
@test [1y 1m; 1w 1d] - [1h 1mi; 1s 1ms] == [1y-1h 1m-1mi; 1w-1s 1d-1ms]
@test [1y 1m; 1w 1d] - [1h 1mi; 1s 1ms] - [1y-1h 1m-1mi; 1w-1s 1d-1ms] == [emptyperiod emptyperiod; emptyperiod emptyperiod]
@test [1y + 1s 1m + 1s; 1w + 1s 1d + 1s] + [1h 1mi; 1s 1ms] == [1y + 1h + 1s 1m + 1mi + 1s; 1w + 2s 1d + 1s + 1ms]
@test [1y + 1s 1m + 1s; 1w + 1s 1d + 1s] - [1h 1mi; 1s 1ms] == [1y-1h + 1s 1m-1mi + 1s; 1w 1d + 1s-1ms]
@test [1y 1m; 1w 1d] + [1h + 1s 1mi + 1s; 1m + 1s 1s + 1ms] == [1y + 1h + 1s 1m + 1mi + 1s; 1w + 1m + 1s 1d + 1s + 1ms]
@test [1y 1m; 1w 1d] - [1h + 1s 1mi + 1s; 1m + 1s 1s + 1ms] == [1y-1h-1s 1m-1mi-1s; 1w-1m-1s 1d-1s-1ms]
@test [1y + 1s 1m + 1s; 1w + 1s 1d + 1s] + [1y + 1h 1y + 1mi; 1y + 1s 1y + 1ms] == [2y + 1h + 1s 1y + 1m + 1mi + 1s; 1y + 1w + 2s 1y + 1d + 1s + 1ms]
@test [1y + 1s 1m + 1s; 1w + 1s 1d + 1s] - [1y + 1h 1y + 1mi; 1y + 1s 1y + 1ms] == [1s-1h 1m + 1s-1y-1mi; 1w-1y 1d + 1s-1y-1ms]

View File

@@ -0,0 +1,202 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Name functions
Jan = Dates.DateTime(2013, 1, 1) # Tuesday
Feb = Dates.DateTime(2013, 2, 2) # Saturday
Mar = Dates.DateTime(2013, 3, 3) # Sunday
Apr = Dates.DateTime(2013, 4, 4) # Thursday
May = Dates.DateTime(2013, 5, 5) # Sunday
Jun = Dates.DateTime(2013, 6, 7) # Friday
Jul = Dates.DateTime(2013, 7, 7) # Sunday
Aug = Dates.DateTime(2013, 8, 8) # Thursday
Sep = Dates.DateTime(2013, 9, 9) # Monday
Oct = Dates.DateTime(2013, 10, 10) # Thursday
Nov = Dates.DateTime(2013, 11, 11) # Monday
Dec = Dates.DateTime(2013, 12, 11) # Wednesday
monthnames = ["January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December"]
daysofweek = [Dates.Tue, Dates.Sat, Dates.Sun, Dates.Thu, Dates.Sun, Dates.Fri,
Dates.Sun, Dates.Thu, Dates.Mon, Dates.Thu, Dates.Mon, Dates.Wed]
dows = ["Tuesday", "Saturday", "Sunday", "Thursday", "Sunday", "Friday",
"Sunday", "Thursday", "Monday", "Thursday", "Monday", "Wednesday"]
daysinmonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for (i, dt) in enumerate([Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec])
@test Dates.month(dt) == i
@test Dates.monthname(dt) == monthnames[i]
@test Dates.monthname(i) == monthnames[i]
@test Dates.monthabbr(dt) == monthnames[i][1:3]
@test Dates.monthabbr(i) == monthnames[i][1:3]
@test Dates.dayofweek(dt) == daysofweek[i]
@test Dates.dayname(dt) == dows[i]
@test Dates.dayname(Dates.dayofweek(dt)) == dows[i]
@test Dates.dayabbr(dt) == dows[i][1:3]
@test Dates.dayabbr(Dates.dayofweek(dt)) == dows[i][1:3]
@test Dates.daysinmonth(dt) == daysinmonth[i]
end
# Customizing locale
Dates.LOCALES["french"] = Dates.DateLocale(
["janvier", "février", "mars", "avril", "mai", "juin",
"juillet", "août", "septembre", "octobre", "novembre", "décembre"],
["janv", "févr", "mars", "avril", "mai", "juin",
"juil", "août", "sept", "oct", "nov", "déc"],
["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"],
[""],
)
@test Dates.dayname(Nov; locale="french") == "lundi"
@test Dates.dayname(Jan; locale="french") == "mardi"
@test Dates.dayname(Dec; locale="french") == "mercredi"
@test Dates.dayname(Apr; locale="french") == "jeudi"
@test Dates.dayname(Jun; locale="french") == "vendredi"
@test Dates.dayname(Feb; locale="french") == "samedi"
@test Dates.dayname(May; locale="french") == "dimanche"
@test Dates.monthname(Jan; locale="french") == "janvier"
@test Dates.monthname(Feb; locale="french") == "février"
@test Dates.monthname(Mar; locale="french") == "mars"
@test Dates.monthname(Apr; locale="french") == "avril"
@test Dates.monthname(May; locale="french") == "mai"
@test Dates.monthname(Jun; locale="french") == "juin"
@test Dates.monthname(Jul; locale="french") == "juillet"
@test Dates.monthname(Aug; locale="french") == "août"
@test Dates.monthname(Sep; locale="french") == "septembre"
@test Dates.monthname(Oct; locale="french") == "octobre"
@test Dates.monthname(Nov; locale="french") == "novembre"
@test Dates.monthname(Dec; locale="french") == "décembre"
@test Dates.isleapyear(Dates.DateTime(1900)) == false
@test Dates.isleapyear(Dates.DateTime(2000)) == true
@test Dates.isleapyear(Dates.DateTime(2004)) == true
@test Dates.isleapyear(Dates.DateTime(2008)) == true
@test Dates.isleapyear(Dates.DateTime(0)) == true
@test Dates.isleapyear(Dates.DateTime(1)) == false
@test Dates.isleapyear(Dates.DateTime(-1)) == false
@test Dates.isleapyear(Dates.DateTime(4)) == true
@test Dates.isleapyear(Dates.DateTime(-4)) == true
@test Dates.daysinyear(2000) == 366
@test Dates.daysinyear(2001) == 365
@test Dates.daysinyear(2000) == 366
@test Dates.daysinyear(2001) == 365
@test Dates.daysinyear(Dates.Date(2000)) == 366
@test Dates.daysinyear(Dates.Date(2001)) == 365
@test Dates.daysinyear(Dates.DateTime(2000)) == 366
@test Dates.daysinyear(Dates.DateTime(2001)) == 365
# Days of week from Monday = 1 to Sunday = 7
@test Dates.dayofweek(Dates.DateTime(2013, 12, 22)) == 7
@test Dates.dayofweek(Dates.DateTime(2013, 12, 23)) == 1
@test Dates.dayofweek(Dates.DateTime(2013, 12, 24)) == 2
@test Dates.dayofweek(Dates.DateTime(2013, 12, 25)) == 3
@test Dates.dayofweek(Dates.DateTime(2013, 12, 26)) == 4
@test Dates.dayofweek(Dates.DateTime(2013, 12, 27)) == 5
@test Dates.dayofweek(Dates.DateTime(2013, 12, 28)) == 6
@test Dates.dayofweek(Dates.DateTime(2013, 12, 29)) == 7
# There are 5 Sundays in December, 2013
@test Dates.daysofweekinmonth(Dates.DateTime(2013, 12, 1)) == 5
# There are 4 Sundays in November, 2013
@test Dates.daysofweekinmonth(Dates.DateTime(2013, 11, 24)) == 4
@test Dates.dayofweekofmonth(Dates.DateTime(2013, 12, 1)) == 1
@test Dates.dayofweekofmonth(Dates.DateTime(2013, 12, 8)) == 2
@test Dates.dayofweekofmonth(Dates.DateTime(2013, 12, 15)) == 3
@test Dates.dayofweekofmonth(Dates.DateTime(2013, 12, 22)) == 4
@test Dates.dayofweekofmonth(Dates.DateTime(2013, 12, 29)) == 5
@test Dates.dayofyear(2000, 1, 1) == 1
@test Dates.dayofyear(2004, 1, 1) == 1
@test Dates.dayofyear(20013, 1, 1) == 1
# Leap year
@test Dates.dayofyear(2000, 12, 31) == 366
# Non-leap year
@test Dates.dayofyear(2001, 12, 31) == 365
@test Dates.dayofyear(Dates.DateTime(2000, 1, 1)) == 1
@test Dates.dayofyear(Dates.DateTime(2004, 1, 1)) == 1
@test Dates.dayofyear(Dates.DateTime(20013, 1, 1)) == 1
# Leap year
@test Dates.dayofyear(Dates.DateTime(2000, 12, 31)) == 366
# Non-leap year
@test Dates.dayofyear(Dates.DateTime(2001, 12, 31)) == 365
# Test every day of a year
dt = Dates.DateTime(2000, 1, 1)
for i = 1:366
@test Dates.dayofyear(dt) == i
dt += Dates.Day(1)
end
dt = Dates.DateTime(2001, 1, 1)
for i = 1:365
@test Dates.dayofyear(dt) == i
dt += Dates.Day(1)
end
@test Dates.quarterofyear(Dates.Date(2000, 1, 1)) == 1
@test Dates.quarterofyear(Dates.Date(2000, 1, 31)) == 1
@test Dates.quarterofyear(Dates.Date(2000, 2, 1)) == 1
@test Dates.quarterofyear(Dates.Date(2000, 2, 29)) == 1
@test Dates.quarterofyear(Dates.Date(2000, 3, 1)) == 1
@test Dates.quarterofyear(Dates.Date(2000, 3, 31)) == 1
@test Dates.quarterofyear(Dates.Date(2000, 4, 1)) == 2
@test Dates.quarterofyear(Dates.Date(2000, 4, 30)) == 2
@test Dates.quarterofyear(Dates.Date(2000, 5, 1)) == 2
@test Dates.quarterofyear(Dates.Date(2000, 5, 31)) == 2
@test Dates.quarterofyear(Dates.Date(2000, 6, 1)) == 2
@test Dates.quarterofyear(Dates.Date(2000, 6, 30)) == 2
@test Dates.quarterofyear(Dates.Date(2000, 7, 1)) == 3
@test Dates.quarterofyear(Dates.Date(2000, 7, 31)) == 3
@test Dates.quarterofyear(Dates.Date(2000, 8, 1)) == 3
@test Dates.quarterofyear(Dates.Date(2000, 8, 31)) == 3
@test Dates.quarterofyear(Dates.Date(2000, 9, 1)) == 3
@test Dates.quarterofyear(Dates.Date(2000, 9, 30)) == 3
@test Dates.quarterofyear(Dates.Date(2000, 10, 1)) == 4
@test Dates.quarterofyear(Dates.Date(2000, 10, 31)) == 4
@test Dates.quarterofyear(Dates.Date(2000, 11, 1)) == 4
@test Dates.quarterofyear(Dates.Date(2000, 11, 30)) == 4
@test Dates.quarterofyear(Dates.Date(2000, 12, 1)) == 4
@test Dates.quarterofyear(Dates.Date(2000, 12, 31)) == 4
@test Dates.quarterofyear(Dates.DateTime(2000, 1, 1)) == 1
@test Dates.quarterofyear(Dates.DateTime(2000, 1, 31)) == 1
@test Dates.quarterofyear(Dates.DateTime(2000, 2, 1)) == 1
@test Dates.quarterofyear(Dates.DateTime(2000, 2, 29)) == 1
@test Dates.quarterofyear(Dates.DateTime(2000, 3, 1)) == 1
@test Dates.quarterofyear(Dates.DateTime(2000, 3, 31)) == 1
@test Dates.quarterofyear(Dates.DateTime(2000, 4, 1)) == 2
@test Dates.quarterofyear(Dates.DateTime(2000, 4, 30)) == 2
@test Dates.quarterofyear(Dates.DateTime(2000, 5, 1)) == 2
@test Dates.quarterofyear(Dates.DateTime(2000, 5, 31)) == 2
@test Dates.quarterofyear(Dates.DateTime(2000, 6, 1)) == 2
@test Dates.quarterofyear(Dates.DateTime(2000, 6, 30)) == 2
@test Dates.quarterofyear(Dates.DateTime(2000, 7, 1)) == 3
@test Dates.quarterofyear(Dates.DateTime(2000, 7, 31)) == 3
@test Dates.quarterofyear(Dates.DateTime(2000, 8, 1)) == 3
@test Dates.quarterofyear(Dates.DateTime(2000, 8, 31)) == 3
@test Dates.quarterofyear(Dates.DateTime(2000, 9, 1)) == 3
@test Dates.quarterofyear(Dates.DateTime(2000, 9, 30)) == 3
@test Dates.quarterofyear(Dates.DateTime(2000, 10, 1)) == 4
@test Dates.quarterofyear(Dates.DateTime(2000, 10, 31)) == 4
@test Dates.quarterofyear(Dates.DateTime(2000, 11, 1)) == 4
@test Dates.quarterofyear(Dates.DateTime(2000, 11, 30)) == 4
@test Dates.quarterofyear(Dates.DateTime(2000, 12, 1)) == 4
@test Dates.quarterofyear(Dates.DateTime(2000, 12, 31)) == 4
@test Dates.dayofquarter(Dates.Date(2014, 1, 1)) == 1
@test Dates.dayofquarter(Dates.Date(2014, 4, 1)) == 1
@test Dates.dayofquarter(Dates.Date(2014, 7, 1)) == 1
@test Dates.dayofquarter(Dates.Date(2014, 10, 1)) == 1
@test Dates.dayofquarter(Dates.Date(2014, 3, 31)) == 90
@test Dates.dayofquarter(Dates.Date(2014, 6, 30)) == 91
@test Dates.dayofquarter(Dates.Date(2014, 9, 30)) == 92
@test Dates.dayofquarter(Dates.Date(2014, 12, 31)) == 92
@test Dates.dayofquarter(Dates.DateTime(2014, 1, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(2014, 4, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(2014, 7, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(2014, 10, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(2014, 3, 31)) == 90
@test Dates.dayofquarter(Dates.DateTime(2014, 6, 30)) == 91
@test Dates.dayofquarter(Dates.DateTime(2014, 9, 30)) == 92
@test Dates.dayofquarter(Dates.DateTime(2014, 12, 31)) == 92

View File

@@ -0,0 +1,548 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
let
for T in (Dates.Date, Dates.DateTime)
f1 = T(2014); l1 = T(2013, 12, 31)
f2 = T(2014); l2 = T(2014)
f3 = T(-2000); l3 = T(2000)
f4 = typemin(T); l4 = typemax(T)
for P in subtypes(Dates.DatePeriod)
for pos_step in (P(1), P(2), P(50), P(2048), P(10000))
# empty range
dr = f1:pos_step:l1
len = length(dr)
@test len == 0
@test isa(len, Int64)
@test isempty(dr)
@test first(dr) == f1
@test last(dr) < f1
@test length([i for i in dr]) == 0
@test_throws ArgumentError minimum(dr)
@test_throws ArgumentError maximum(dr)
@test_throws BoundsError dr[1]
@test findin(dr, dr) == Int64[]
@test [dr;] == T[]
@test isempty(reverse(dr))
@test length(reverse(dr)) == 0
@test first(reverse(dr)) < f1
@test last(reverse(dr)) >= f1
@test issorted(dr)
@test sortperm(dr) == 1:1:0
@test !(f1 in dr)
@test !(l1 in dr)
@test !(f1 - pos_step in dr)
@test !(l1 + pos_step in dr)
for (f, l) in ((f2, l2), (f3, l3), (f4, l4))
dr = f:pos_step:l
len = length(dr)
@test len > 0
@test isa(len, Int64)
@test !isempty(dr)
@test first(dr) == f
@test last(dr) <= l
@test minimum(dr) == first(dr)
@test maximum(dr) == last(dr)
@test dr[1] == f
@test dr[end] <= l
@test next(dr, start(dr)) == (first(dr), 1)
if len < 10000
dr1 = [i for i in dr]
@test length(dr1) == len
@test findin(dr, dr) == [1:len;]
@test length([dr;]) == len
end
@test !isempty(reverse(dr))
@test length(reverse(dr)) == len
@test last(reverse(dr)) == f
@test issorted(dr)
@test f in dr
end
end
for neg_step in (P(-1), P(-2), P(-50), P(-2048), P(-10000))
# empty range
dr = l1:neg_step:f1
len = length(dr)
@test len == 0
@test isa(len, Int64)
@test isempty(dr)
@test first(dr) == l1
@test last(dr) > l1
@test length([i for i in dr]) == 0
@test_throws ArgumentError minimum(dr)
@test_throws ArgumentError maximum(dr)
@test_throws BoundsError dr[1]
@test findin(dr, dr) == Int64[]
@test [dr;] == T[]
@test isempty(reverse(dr))
@test length(reverse(dr)) == 0
@test first(reverse(dr)) > l1
@test last(reverse(dr)) <= l1
@test issorted(dr)
@test sortperm(dr) == 1:1:0
@test !(l1 in dr)
@test !(l1 in dr)
@test !(l1 - neg_step in dr)
@test !(l1 + neg_step in dr)
for (f, l) in ((f2, l2), (f3, l3), (f4, l4))
dr = l:neg_step:f
len = length(dr)
@test len > 0
@test isa(len, Int64)
@test !isempty(dr)
@test first(dr) == l
@test last(dr) >= f
@test minimum(dr) == last(dr)
@test maximum(dr) == first(dr)
@test dr[1] == l
@test dr[end] >= f
@test next(dr, start(dr)) == (first(dr), 1)
if len < 10000
dr1 = [i for i in dr]
@test length(dr1) == len
@test findin(dr, dr) == [1:len;]
@test length([dr;]) == len
end
@test !isempty(reverse(dr))
@test length(reverse(dr)) == len
@test issorted(dr) == (len <= 1)
@test l in dr
end
end
end
if T == Dates.DateTime
for P in subtypes(Dates.TimePeriod)
P in (Dates.Microsecond, Dates.Nanosecond) && continue
for pos_step in (P(1), P(2), P(50), P(2048), P(10000))
# empty range
dr = f1:pos_step:l1
len = length(dr)
@test len == 0
@test isa(len, Int64)
@test isempty(dr)
@test first(dr) == f1
@test last(dr) < f1
@test length([i for i in dr]) == 0
@test_throws ArgumentError minimum(dr)
@test_throws ArgumentError maximum(dr)
@test_throws BoundsError dr[1]
@test findin(dr, dr) == Int64[]
@test [dr;] == T[]
@test isempty(reverse(dr))
@test length(reverse(dr)) == 0
@test first(reverse(dr)) < f1
@test last(reverse(dr)) >= f1
@test issorted(dr)
@test sortperm(dr) == 1:1:0
@test !(f1 in dr)
@test !(l1 in dr)
@test !(f1 - pos_step in dr)
@test !(l1 + pos_step in dr)
for (f, l) in ((f2, l2), (f3, l3), (f4, l4))
dr = f:pos_step:l
len = length(dr)
@test len > 0
@test isa(len, Int64)
@test !isempty(dr)
@test first(dr) == f
@test last(dr) <= l
@test minimum(dr) == first(dr)
@test maximum(dr) == last(dr)
@test dr[1] == f
@test dr[end] <= l
@test next(dr, start(dr)) == (first(dr), 1)
if len < 10000
dr1 = [i for i in dr]
@test length(dr1) == len
@test findin(dr, dr) == [1:len;]
@test length([dr;]) == len
end
@test !isempty(reverse(dr))
@test length(reverse(dr)) == len
@test last(reverse(dr)) == f
@test issorted(dr)
@test f in dr
end
end
for neg_step in (P(-1), P(-2), P(-50), P(-2048), P(-10000))
# empty range
dr = l1:neg_step:f1
len = length(dr)
@test len == 0
@test isa(len, Int64)
@test isempty(dr)
@test first(dr) == l1
@test last(dr) > l1
@test length([i for i in dr]) == 0
@test_throws ArgumentError minimum(dr)
@test_throws ArgumentError maximum(dr)
@test_throws BoundsError dr[1]
@test findin(dr, dr) == Int64[]
@test [dr;] == T[]
@test isempty(reverse(dr))
@test length(reverse(dr)) == 0
@test first(reverse(dr)) > l1
@test last(reverse(dr)) <= l1
@test issorted(dr)
@test sortperm(dr) == 1:1:0
@test !(l1 in dr)
@test !(l1 in dr)
@test !(l1 - neg_step in dr)
@test !(l1 + neg_step in dr)
for (f, l) in ((f2, l2), (f3, l3), (f4, l4))
dr = l:neg_step:f
len = length(dr)
@test len > 0
@test isa(len, Int64)
@test !isempty(dr)
@test first(dr) == l
@test last(dr) >= f
@test minimum(dr) == last(dr)
@test maximum(dr) == first(dr)
@test dr[1] == l
@test dr[end] >= f
@test next(dr, start(dr)) == (first(dr), 1)
if len < 10000
dr1 = [i for i in dr]
@test length(dr1) == len
@test findin(dr, dr) == [1:len;]
@test length([dr;]) == len
end
@test !isempty(reverse(dr))
@test length(reverse(dr)) == len
@test last(reverse(dr)) >= l
@test issorted(dr) == (len <= 1)
@test l in dr
end
end
end
end
end
end
# All the range representations we want to test
# Date ranges
dr = Dates.DateTime(2013, 1, 1):Dates.DateTime(2013, 2, 1)
dr1 = Dates.DateTime(2013, 1, 1):Dates.DateTime(2013, 1, 1)
dr2 = Dates.DateTime(2013, 1, 1):Dates.DateTime(2012, 2, 1) # empty range
dr3 = Dates.DateTime(2013, 1, 1):Dates.Day(-1):Dates.DateTime(2012) # negative step
# Big ranges
dr4 = Dates.DateTime(0):Dates.DateTime(20000, 1, 1)
dr5 = Dates.DateTime(0):Dates.DateTime(200000, 1, 1)
dr6 = Dates.DateTime(0):Dates.DateTime(2000000, 1, 1)
dr7 = Dates.DateTime(0):Dates.DateTime(20000000, 1, 1)
dr8 = Dates.DateTime(0):Dates.DateTime(200000000, 1, 1)
dr9 = typemin(Dates.DateTime):typemax(Dates.DateTime)
# Non-default steps
dr10 = typemax(Dates.DateTime):Dates.Day(-1):typemin(Dates.DateTime)
dr11 = typemin(Dates.DateTime):Dates.Week(1):typemax(Dates.DateTime)
dr12 = typemin(Dates.DateTime):Dates.Month(1):typemax(Dates.DateTime)
dr13 = typemin(Dates.DateTime):Dates.Year(1):typemax(Dates.DateTime)
dr14 = typemin(Dates.DateTime):Dates.Week(10):typemax(Dates.DateTime)
dr15 = typemin(Dates.DateTime):Dates.Month(100):typemax(Dates.DateTime)
dr16 = typemin(Dates.DateTime):Dates.Year(1000):typemax(Dates.DateTime)
dr17 = typemax(Dates.DateTime):Dates.Week(-10000):typemin(Dates.DateTime)
dr18 = typemax(Dates.DateTime):Dates.Month(-100000):typemin(Dates.DateTime)
dr19 = typemax(Dates.DateTime):Dates.Year(-1000000):typemin(Dates.DateTime)
dr20 = typemin(Dates.DateTime):Dates.Day(2):typemax(Dates.DateTime)
drs = Any[dr, dr1, dr2, dr3, dr4, dr5, dr6, dr7, dr8, dr9, dr10,
dr11, dr12, dr13, dr14, dr15, dr16, dr17, dr18, dr19, dr20]
drs2 = map(x->Dates.Date(first(x)):step(x):Dates.Date(last(x)), drs)
@test map(length, drs) == map(x->size(x)[1], drs)
@test map(length, drs) == map(x->length(Dates.Date(first(x)):step(x):Dates.Date(last(x))), drs)
@test map(length, drs) == map(x->length(reverse(x)), drs)
@test all(x->findin(x, x)==[1:length(x);], drs[1:4])
@test isempty(dr2)
@test all(x->reverse(x) == range(last(x), -step(x), length(x)), drs)
@test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end])
@test all(x->maximum(x) == (step(x) < zero(step(x)) ? first(x) : last(x)), drs[4:end])
@test all(drs[1:3]) do dd
for (i, d) in enumerate(dd)
@test d == (first(dd) + Dates.Day(i - 1))
end
true
end
@test_throws MethodError dr + 1
a = Dates.DateTime(2013, 1, 1)
b = Dates.DateTime(2013, 2, 1)
@test map!(x->x + Dates.Day(1), Array{Dates.DateTime}(32), dr) == [(a + Dates.Day(1)):(b + Dates.Day(1));]
@test map(x->x + Dates.Day(1), dr) == [(a + Dates.Day(1)):(b + Dates.Day(1));]
@test map(x->a in x, drs[1:4]) == [true, true, false, true]
@test a in dr
@test b in dr
@test Dates.DateTime(2013, 1, 3) in dr
@test Dates.DateTime(2013, 1, 15) in dr
@test Dates.DateTime(2013, 1, 26) in dr
@test !(Dates.DateTime(2012, 1, 1) in dr)
@test all(x->sort(x) == (step(x) < zero(step(x)) ? reverse(x) : x), drs)
@test all(x->step(x) < zero(step(x)) ? issorted(reverse(x)) : issorted(x), drs)
@test length(b:Dates.Day(-1):a) == 32
@test length(b:a) == 0
@test length(b:Dates.Day(1):a) == 0
@test length(a:Dates.Day(2):b) == 16
@test last(a:Dates.Day(2):b) == Dates.DateTime(2013, 1, 31)
@test length(a:Dates.Day(7):b) == 5
@test last(a:Dates.Day(7):b) == Dates.DateTime(2013, 1, 29)
@test length(a:Dates.Day(32):b) == 1
@test last(a:Dates.Day(32):b) == Dates.DateTime(2013, 1, 1)
@test (a:b)[1] == Dates.DateTime(2013, 1, 1)
@test (a:b)[2] == Dates.DateTime(2013, 1, 2)
@test (a:b)[7] == Dates.DateTime(2013, 1, 7)
@test (a:b)[end] == b
@test first(a:Dates.DateTime(20000, 1, 1)) == a
@test first(a:Dates.DateTime(200000, 1, 1)) == a
@test first(a:Dates.DateTime(2000000, 1, 1)) == a
@test first(a:Dates.DateTime(20000000, 1, 1)) == a
@test first(a:Dates.DateTime(200000000, 1, 1)) == a
@test first(a:typemax(Dates.DateTime)) == a
@test first(typemin(Dates.DateTime):typemax(Dates.DateTime)) == typemin(Dates.DateTime)
# Date ranges
dr = Dates.Date(2013, 1, 1):Dates.Date(2013, 2, 1)
dr1 = Dates.Date(2013, 1, 1):Dates.Date(2013, 1, 1)
dr2 = Dates.Date(2013, 1, 1):Dates.Date(2012, 2, 1) # empty range
dr3 = Dates.Date(2013, 1, 1):Dates.Day(-1):Dates.Date(2012, 1, 1) # negative step
# Big ranges
dr4 = Dates.Date(0):Dates.Date(20000, 1, 1)
dr5 = Dates.Date(0):Dates.Date(200000, 1, 1)
dr6 = Dates.Date(0):Dates.Date(2000000, 1, 1)
dr7 = Dates.Date(0):Dates.Date(20000000, 1, 1)
dr8 = Dates.Date(0):Dates.Date(200000000, 1, 1)
dr9 = typemin(Dates.Date):typemax(Dates.Date)
# Non-default steps
dr10 = typemax(Dates.Date):Dates.Day(-1):typemin(Dates.Date)
dr11 = typemin(Dates.Date):Dates.Week(1):typemax(Dates.Date)
dr12 = typemin(Dates.Date):Dates.Month(1):typemax(Dates.Date)
dr13 = typemin(Dates.Date):Dates.Year(1):typemax(Dates.Date)
dr14 = typemin(Dates.Date):Dates.Week(10):typemax(Dates.Date)
dr15 = typemin(Dates.Date):Dates.Month(100):typemax(Dates.Date)
dr16 = typemin(Dates.Date):Dates.Year(1000):typemax(Dates.Date)
dr17 = typemax(Dates.Date):Dates.Week(-10000):typemin(Dates.Date)
dr18 = typemax(Dates.Date):Dates.Month(-100000):typemin(Dates.Date)
dr19 = typemax(Dates.Date):Dates.Year(-1000000):typemin(Dates.Date)
dr20 = typemin(Dates.Date):Dates.Day(2):typemax(Dates.Date)
drs = Any[dr, dr1, dr2, dr3, dr4, dr5, dr6, dr7, dr8, dr9, dr10,
dr11, dr12, dr13, dr14, dr15, dr16, dr17, dr18, dr19, dr20]
@test map(length, drs) == map(x->size(x)[1], drs)
@test all(x->findin(x, x) == [1:length(x);], drs[1:4])
@test isempty(dr2)
@test all(x->reverse(x) == last(x): - step(x):first(x), drs)
@test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end])
@test all(x->maximum(x) == (step(x) < zero(step(x)) ? first(x) : last(x)), drs[4:end])
@test all(drs[1:3]) do dd
for (i, d) in enumerate(dd)
@test d == (first(dd) + Dates.Day(i - 1))
end
true
end
@test_throws MethodError dr + 1
a = Dates.Date(2013, 1, 1)
b = Dates.Date(2013, 2, 1)
@test map!(x->x + Dates.Day(1), Array{Dates.Date}(32), dr) == [(a + Dates.Day(1)):(b + Dates.Day(1));]
@test map(x->x + Dates.Day(1), dr) == [(a + Dates.Day(1)):(b + Dates.Day(1));]
@test map(x->a in x, drs[1:4]) == [true, true, false, true]
@test a in dr
@test b in dr
@test Dates.Date(2013, 1, 3) in dr
@test Dates.Date(2013, 1, 15) in dr
@test Dates.Date(2013, 1, 26) in dr
@test !(Dates.Date(2012, 1, 1) in dr)
@test all(x->sort(x) == (step(x) < zero(step(x)) ? reverse(x) : x), drs)
@test all(x->step(x) < zero(step(x)) ? issorted(reverse(x)) : issorted(x), drs)
@test length(b:Dates.Day(-1):a) == 32
@test length(b:a) == 0
@test length(b:Dates.Day(1):a) == 0
@test length(a:Dates.Day(2):b) == 16
@test last(a:Dates.Day(2):b) == Dates.Date(2013, 1, 31)
@test length(a:Dates.Day(7):b) == 5
@test last(a:Dates.Day(7):b) == Dates.Date(2013, 1, 29)
@test length(a:Dates.Day(32):b) == 1
@test last(a:Dates.Day(32):b) == Dates.Date(2013, 1, 1)
@test (a:b)[1] == Dates.Date(2013, 1, 1)
@test (a:b)[2] == Dates.Date(2013, 1, 2)
@test (a:b)[7] == Dates.Date(2013, 1, 7)
@test (a:b)[end] == b
@test first(a:Dates.Date(20000, 1, 1)) == a
@test first(a:Dates.Date(200000, 1, 1)) == a
@test first(a:Dates.Date(2000000, 1, 1)) == a
@test first(a:Dates.Date(20000000, 1, 1)) == a
@test first(a:Dates.Date(200000000, 1, 1)) == a
@test first(a:typemax(Dates.Date)) == a
@test first(typemin(Dates.Date):typemax(Dates.Date)) == typemin(Dates.Date)
# Non-default step sizes
@test length(typemin(Dates.Date):Dates.Week(1):typemax(Dates.Date)) == 26351950414948059
# Big Month/Year ranges
@test length(typemin(Dates.Date):Dates.Month(1):typemax(Dates.Date)) == 6060531933867600
@test length(typemin(Dates.Date):Dates.Year(1):typemax(Dates.Date)) == 505044327822300
@test length(typemin(Dates.DateTime):Dates.Month(1):typemax(Dates.DateTime)) == 3507324288
@test length(typemin(Dates.DateTime):Dates.Year(1):typemax(Dates.DateTime)) == 292277024
@test length(typemin(Dates.DateTime):Dates.Week(1):typemax(Dates.DateTime)) == 15250284420
@test length(typemin(Dates.DateTime):Dates.Day(1):typemax(Dates.DateTime)) == 106751990938
@test length(typemin(Dates.DateTime):Dates.Hour(1):typemax(Dates.DateTime)) == 2562047782512
@test length(typemin(Dates.DateTime):Dates.Minute(1):typemax(Dates.DateTime)) == 153722866950720
@test length(typemin(Dates.DateTime):Dates.Second(1):typemax(Dates.DateTime)) == 9223372017043200
@test length(typemin(DateTime):Dates.Millisecond(1):typemax(DateTime)) == 9223372017043199001
c = Dates.Date(2013, 6, 1)
@test length(a:Dates.Month(1):c) == 6
@test [a:Dates.Month(1):c;] == [a + Dates.Month(1)*i for i in 0:5]
@test [a:Dates.Month(2):Dates.Date(2013, 1, 2);] == [a]
@test [c:Dates.Month(-1):a;] == reverse([a:Dates.Month(1):c;])
@test length(range(Date(2000), 366)) == 366
let n=100000
a = Dates.Date(2000)
for i = 1:n
@test length(range(a, i)) == i
end
return a + Dates.Day(n)
end
# Custom definition to override default step of DateTime ranges
@test typeof(step(Dates.DateTime(2000):Dates.DateTime(2001))) == Dates.Day
a = Dates.Date(2013, 1, 1)
b = Dates.Date(2013, 2, 1)
d = Dates.Date(2020, 1, 1)
@test length(a:Dates.Year(1):d) == 8
@test first(a:Dates.Year(1):d) == a
@test last(a:Dates.Year(1):d) == d
@test length(a:Dates.Month(12):d) == 8
@test first(a:Dates.Month(12):d) == a
@test last(a:Dates.Month(12):d) == d
@test length(a:Dates.Week(52):d) == 8
@test first(a:Dates.Week(52):d) == a
@test last(a:Dates.Week(52):d) == Dates.Date(2019, 12, 24)
@test length(a:Dates.Day(365):d) == 8
@test first(a:Dates.Day(365):d) == a
@test last(a:Dates.Day(365):d) == Dates.Date(2019, 12, 31)
a = Dates.Date(2013, 1, 1)
b = Dates.Date(2013, 2, 1)
@test length(a:Dates.Year(1):Dates.Date(2020, 2, 1)) == 8
@test length(a:Dates.Year(1):Dates.Date(2020, 6, 1)) == 8
@test length(a:Dates.Year(1):Dates.Date(2020, 11, 1)) == 8
@test length(a:Dates.Year(1):Dates.Date(2020, 12, 31)) == 8
@test length(a:Dates.Year(1):Dates.Date(2021, 1, 1)) == 9
@test length(Dates.Date(2000):Dates.Year(-10):Dates.Date(1900)) == 11
@test length(Dates.Date(2000, 6, 23):Dates.Year(-10):Dates.Date(1900, 2, 28)) == 11
@test length(Dates.Date(2000, 1, 1):Dates.Year(1):Dates.Date(2000, 2, 1)) == 1
let n=100000
a = b = Dates.Date(0)
for i = 1:n
@test length(a:Dates.Year(1):b) == i
b += Dates.Year(1)
end
end
let n=10000
a = Dates.Date(1985, 12, 5)
b = Dates.Date(1986, 12, 27)
c = Dates.DateTime(1985, 12, 5)
d = Dates.DateTime(1986, 12, 27)
for i = 1:n
@test length(a:Dates.Month(1):b) == 13
@test length(a:Dates.Year(1):b) == 2
@test length(c:Dates.Month(1):d) == 13
@test length(c:Dates.Year(1):d) == 2
a += Dates.Day(1)
b += Dates.Day(1)
end
return b
end
let n=100000
a = b = Dates.Date(2000)
for i = 1:n
@test length(a:Dates.Month(1):b) == i
b += Dates.Month(1)
end
return b
end
@test length(Dates.Year(1):Dates.Year(1):Dates.Year(10)) == 10
@test length(Dates.Year(10):Dates.Year(-1):Dates.Year(1)) == 10
@test length(Dates.Year(10):Dates.Year(-2):Dates.Year(1)) == 5
@test_throws OverflowError length(typemin(Dates.Year):Dates.Year(1):typemax(Dates.Year))
@test_throws MethodError Dates.Date(0):Dates.DateTime(2000)
@test_throws MethodError Dates.Date(0):Dates.Year(10)
@test length(range(Dates.Date(2000), 366)) == 366
@test last(range(Dates.Date(2000), 366)) == Dates.Date(2000, 12, 31)
@test last(range(Dates.Date(2001), 365)) == Dates.Date(2001, 12, 31)
@test last(range(Dates.Date(2000), 367)) == last(range(Dates.Date(2000), Dates.Month(12), 2)) == last(range(Dates.Date(2000), Dates.Year(1), 2))
@test last(range(Dates.DateTime(2000), Dates.Day(366), 2)) == last(range(Dates.DateTime(2000), Dates.Hour(8784), 2))
# Issue 5
lastdaysofmonth = [Dates.Date(2014, i, Dates.daysinmonth(2014, i)) for i=1:12]
@test [Date(2014, 1, 31):Dates.Month(1):Date(2015);] == lastdaysofmonth
# Range addition/subtraction:
let d = Dates.Day(1)
@test (Dates.Date(2000):d:Dates.Date(2001)) + d == (Dates.Date(2000) + d:d:Dates.Date(2001) + d)
@test (Dates.Date(2000):d:Dates.Date(2001)) - d == (Dates.Date(2000) - d:d:Dates.Date(2001) - d)
end
# Time ranges
dr = Dates.Time(23, 1, 1):Dates.Time(23, 2, 1)
dr1 = Dates.Time(23, 1, 1):Dates.Time(23, 1, 1)
dr2 = Dates.Time(23, 1, 1):Dates.Time(22, 2, 1) # empty range
dr3 = Dates.Time(23, 1, 1):Dates.Minute(-1):Dates.Time(22, 1, 1) # negative step
# Big ranges
dr8 = typemin(Dates.Time):typemax(Dates.Time)
dr9 = typemin(Dates.Time):Dates.Nanosecond(1):typemax(Dates.Time)
# Non - default steps
dr10 = typemax(Dates.Time):Dates.Microsecond(-1):typemin(Dates.Time)
dr11 = typemin(Dates.Time):Dates.Millisecond(1):typemax(Dates.Time)
dr12 = typemin(Dates.Time):Dates.Minute(1):typemax(Dates.Time)
dr13 = typemin(Dates.Time):Dates.Hour(1):typemax(Dates.Time)
dr14 = typemin(Dates.Time):Dates.Millisecond(10):typemax(Dates.Time)
dr15 = typemin(Dates.Time):Dates.Minute(100):typemax(Dates.Time)
dr16 = typemin(Dates.Time):Dates.Hour(1000):typemax(Dates.Time)
dr17 = typemax(Dates.Time):Dates.Millisecond(-10000):typemin(Dates.Time)
dr18 = typemax(Dates.Time):Dates.Minute(-100):typemin(Dates.Time)
dr19 = typemax(Dates.Time):Dates.Hour(-10):typemin(Dates.Time)
dr20 = typemin(Dates.Time):Dates.Microsecond(2):typemax(Dates.Time)
drs = Any[dr, dr1, dr2, dr3, dr8, dr9, dr10,
dr11, dr12, dr13, dr14, dr15, dr16, dr17, dr18, dr19, dr20]
@test map(length, drs) == map(x->size(x)[1], drs)
@test all(x->findin(x, x) == [1:length(x);], drs[1:4])
@test isempty(dr2)
@test all(x->reverse(x) == last(x): - step(x):first(x), drs)
@test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end])
@test all(x->maximum(x) == (step(x) < zero(step(x)) ? first(x) : last(x)), drs[4:end])
@test_throws MethodError dr + 1
a = Dates.Time(23, 1, 1)
@test map(x->a in x, drs[1:4]) == [true, true, false, true]
@test a in dr
@test all(x->sort(x) == (step(x) < zero(step(x)) ? reverse(x) : x), drs)
@test all(x->step(x) < zero(step(x)) ? issorted(reverse(x)) : issorted(x), drs)

View File

@@ -0,0 +1,141 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Test conversion to and from the rounding epoch (ISO 8601 year 0000)
@test Dates.epochdays2date(-1) == Dates.Date(-1, 12, 31)
@test Dates.epochdays2date(0) == Dates.Date(0, 1, 1)
@test Dates.epochdays2date(1) == Dates.Date(0, 1, 2)
@test Dates.epochdays2date(736329) == Dates.Date(2016, 1, 1)
@test Dates.epochms2datetime(-86400000) == Dates.DateTime(-1, 12, 31)
@test Dates.epochms2datetime(0) == Dates.DateTime(0, 1, 1)
@test Dates.epochms2datetime(86400000) == Dates.DateTime(0, 1, 2)
@test Dates.epochms2datetime(Int64(736329) * 86400000) == Dates.DateTime(2016, 1, 1)
@test Dates.date2epochdays(Dates.Date(-1, 12, 31)) == -1
@test Dates.date2epochdays(Dates.Date(0, 1, 1)) == 0
@test Dates.date2epochdays(Dates.Date(2016, 1, 1)) == 736329
@test Dates.datetime2epochms(Dates.DateTime(-1, 12, 31)) == -86400000
@test Dates.datetime2epochms(Dates.DateTime(0, 1, 1)) == 0
@test Dates.datetime2epochms(Dates.DateTime(2016, 1, 1)) == Int64(736329) * 86400000
# Basic rounding tests
dt = Dates.Date(2016, 2, 28) # Sunday
@test floor(dt, Dates.Year) == Dates.Date(2016)
@test floor(dt, Dates.Year(5)) == Dates.Date(2015)
@test floor(dt, Dates.Year(10)) == Dates.Date(2010)
@test floor(dt, Dates.Month) == Dates.Date(2016, 2)
@test floor(dt, Dates.Month(6)) == Dates.Date(2016, 1)
@test floor(dt, Dates.Week) == Dates.toprev(dt, Dates.Monday)
@test ceil(dt, Dates.Year) == Dates.Date(2017)
@test ceil(dt, Dates.Year(5)) == Dates.Date(2020)
@test ceil(dt, Dates.Month) == Dates.Date(2016, 3)
@test ceil(dt, Dates.Month(6)) == Dates.Date(2016, 7)
@test ceil(dt, Dates.Week) == Dates.tonext(dt, Dates.Monday)
@test round(dt, Dates.Year) == Dates.Date(2016)
@test round(dt, Dates.Month) == Dates.Date(2016, 3)
@test round(dt, Dates.Week) == Dates.Date(2016, 2, 29)
dt = Dates.DateTime(2016, 2, 28, 15, 10, 50, 500)
@test floor(dt, Dates.Day) == Dates.DateTime(2016, 2, 28)
@test floor(dt, Dates.Hour) == Dates.DateTime(2016, 2, 28, 15)
@test floor(dt, Dates.Hour(2)) == Dates.DateTime(2016, 2, 28, 14)
@test floor(dt, Dates.Hour(12)) == Dates.DateTime(2016, 2, 28, 12)
@test floor(dt, Dates.Minute) == Dates.DateTime(2016, 2, 28, 15, 10)
@test floor(dt, Dates.Minute(15)) == Dates.DateTime(2016, 2, 28, 15, 0)
@test floor(dt, Dates.Second) == Dates.DateTime(2016, 2, 28, 15, 10, 50)
@test floor(dt, Dates.Second(30)) == Dates.DateTime(2016, 2, 28, 15, 10, 30)
@test ceil(dt, Dates.Day) == Dates.DateTime(2016, 2, 29)
@test ceil(dt, Dates.Hour) == Dates.DateTime(2016, 2, 28, 16)
@test ceil(dt, Dates.Hour(2)) == Dates.DateTime(2016, 2, 28, 16)
@test ceil(dt, Dates.Hour(12)) == Dates.DateTime(2016, 2, 29, 0)
@test ceil(dt, Dates.Minute) == Dates.DateTime(2016, 2, 28, 15, 11)
@test ceil(dt, Dates.Minute(15)) == Dates.DateTime(2016, 2, 28, 15, 15)
@test ceil(dt, Dates.Second) == Dates.DateTime(2016, 2, 28, 15, 10, 51)
@test ceil(dt, Dates.Second(30)) == Dates.DateTime(2016, 2, 28, 15, 11, 0)
@test round(dt, Dates.Day) == Dates.DateTime(2016, 2, 29)
@test round(dt, Dates.Hour) == Dates.DateTime(2016, 2, 28, 15)
@test round(dt, Dates.Hour(2)) == Dates.DateTime(2016, 2, 28, 16)
@test round(dt, Dates.Hour(12)) == Dates.DateTime(2016, 2, 28, 12)
@test round(dt, Dates.Minute) == Dates.DateTime(2016, 2, 28, 15, 11)
@test round(dt, Dates.Minute(15)) == Dates.DateTime(2016, 2, 28, 15, 15)
@test round(dt, Dates.Second) == Dates.DateTime(2016, 2, 28, 15, 10, 51)
@test round(dt, Dates.Second(30)) == Dates.DateTime(2016, 2, 28, 15, 11, 0)
# Rounding for dates at the rounding epoch (year 0000)
dt = Dates.DateTime(0)
@test floor(dt, Dates.Year) == dt
@test floor(dt, Dates.Month) == dt
@test floor(dt, Dates.Week) == Dates.Date(-1, 12, 27) # Monday prior to 0000-01-01
@test floor(Dates.Date(-1, 12, 27), Dates.Week) == Dates.Date(-1, 12, 27)
@test floor(dt, Dates.Day) == dt
@test floor(dt, Dates.Hour) == dt
@test floor(dt, Dates.Minute) == dt
@test floor(dt, Dates.Second) == dt
@test ceil(dt, Dates.Year) == dt
@test ceil(dt, Dates.Month) == dt
@test ceil(dt, Dates.Week) == Dates.Date(0, 1, 3) # Monday following 0000-01-01
@test ceil(Dates.Date(0, 1, 3), Dates.Week) == Dates.Date(0, 1, 3)
@test ceil(dt, Dates.Day) == dt
@test ceil(dt, Dates.Hour) == dt
@test ceil(dt, Dates.Minute) == dt
@test ceil(dt, Dates.Second) == dt
# Test rounding for multiples of a period (easiest to test close to rounding epoch)
dt = Dates.DateTime(0, 1, 19, 19, 19, 19, 19)
@test floor(dt, Dates.Year(2)) == DateTime(0)
@test floor(dt, Dates.Month(2)) == DateTime(0, 1) # Odd number; months are 1-indexed
@test floor(dt, Dates.Week(2)) == DateTime(0, 1, 17) # Third Monday of 0000
@test floor(dt, Dates.Day(2)) == DateTime(0, 1, 19) # Odd number; days are 1-indexed
@test floor(dt, Dates.Hour(2)) == DateTime(0, 1, 19, 18)
@test floor(dt, Dates.Minute(2)) == DateTime(0, 1, 19, 19, 18)
@test floor(dt, Dates.Second(2)) == DateTime(0, 1, 19, 19, 19, 18)
@test ceil(dt, Dates.Year(2)) == DateTime(2)
@test ceil(dt, Dates.Month(2)) == DateTime(0, 3) # Odd number; months are 1-indexed
@test ceil(dt, Dates.Week(2)) == DateTime(0, 1, 31) # Fifth Monday of 0000
@test ceil(dt, Dates.Day(2)) == DateTime(0, 1, 21) # Odd number; days are 1-indexed
@test ceil(dt, Dates.Hour(2)) == DateTime(0, 1, 19, 20)
@test ceil(dt, Dates.Minute(2)) == DateTime(0, 1, 19, 19, 20)
@test ceil(dt, Dates.Second(2)) == DateTime(0, 1, 19, 19, 19, 20)
# Test rounding for dates with negative years
dt = Dates.DateTime(-1, 12, 29, 19, 19, 19, 19)
@test floor(dt, Dates.Year(2)) == DateTime(-2)
@test floor(dt, Dates.Month(2)) == DateTime(-1, 11) # Odd number; months are 1-indexed
@test floor(dt, Dates.Week(2)) == DateTime(-1, 12, 20) # 2 weeks prior to 0000-01-03
@test floor(dt, Dates.Day(2)) == DateTime(-1, 12, 28) # Even; 4 days prior to 0000-01-01
@test floor(dt, Dates.Hour(2)) == DateTime(-1, 12, 29, 18)
@test floor(dt, Dates.Minute(2)) == DateTime(-1, 12, 29, 19, 18)
@test floor(dt, Dates.Second(2)) == DateTime(-1, 12, 29, 19, 19, 18)
@test ceil(dt, Dates.Year(2)) == DateTime(0)
@test ceil(dt, Dates.Month(2)) == DateTime(0, 1) # Odd number; months are 1-indexed
@test ceil(dt, Dates.Week(2)) == DateTime(0, 1, 3) # First Monday of 0000
@test ceil(dt, Dates.Day(2)) == DateTime(-1, 12, 30) # Even; 2 days prior to 0000-01-01
@test ceil(dt, Dates.Hour(2)) == DateTime(-1, 12, 29, 20)
@test ceil(dt, Dates.Minute(2)) == DateTime(-1, 12, 29, 19, 20)
@test ceil(dt, Dates.Second(2)) == DateTime(-1, 12, 29, 19, 19, 20)
# Test rounding for dates that should not need rounding
for dt in [Dates.DateTime(2016, 1, 1), Dates.DateTime(-2016, 1, 1)]
for p in [Dates.Year, Dates.Month, Dates.Day, Dates.Hour, Dates.Minute, Dates.Second]
@test floor(dt, p) == dt
@test ceil(dt, p) == dt
end
end
# Test available RoundingModes
dt = Dates.DateTime(2016, 2, 28, 12)
@test round(dt, Dates.Day, RoundNearestTiesUp) == Dates.DateTime(2016, 2, 29)
@test round(dt, Dates.Day, RoundUp) == Dates.DateTime(2016, 2, 29)
@test round(dt, Dates.Day, RoundDown) == Dates.DateTime(2016, 2, 28)
@test_throws DomainError round(dt, Dates.Day, RoundNearest)
@test_throws DomainError round(dt, Dates.Day, RoundNearestTiesAway)
@test_throws DomainError round(dt, Dates.Day, RoundToZero)
@test round(dt, Dates.Day) == round(dt, Dates.Day, RoundNearestTiesUp)
# Test rounding to invalid resolutions
dt = Dates.DateTime(2016, 2, 28, 12, 15)
for p in [Dates.Year, Dates.Month, Dates.Week, Dates.Day, Dates.Hour]
for v in [-1, 0]
@test_throws DomainError floor(dt, p(v))
@test_throws DomainError ceil(dt, p(v))
@test_throws DomainError round(dt, p(v))
end
end

View File

@@ -0,0 +1,210 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Date internal algorithms
@test Dates.totaldays(0, 2, 28) == -307
@test Dates.totaldays(0, 2, 29) == -306
@test Dates.totaldays(0, 3, 1) == -305
@test Dates.totaldays(0, 12, 31) == 0
# Rata Die Days # start from 0001-01-01
@test Dates.totaldays(1, 1, 1) == 1
@test Dates.totaldays(1, 1, 2) == 2
@test Dates.totaldays(2013, 1, 1) == 734869
@test Dates.daysinmonth(2000, 1) == 31
@test Dates.daysinmonth(2000, 2) == 29
@test Dates.daysinmonth(2000, 3) == 31
@test Dates.daysinmonth(2000, 4) == 30
@test Dates.daysinmonth(2000, 5) == 31
@test Dates.daysinmonth(2000, 6) == 30
@test Dates.daysinmonth(2000, 7) == 31
@test Dates.daysinmonth(2000, 8) == 31
@test Dates.daysinmonth(2000, 9) == 30
@test Dates.daysinmonth(2000, 10) == 31
@test Dates.daysinmonth(2000, 11) == 30
@test Dates.daysinmonth(2000, 12) == 31
@test Dates.daysinmonth(2001, 2) == 28
@test Dates.isleapyear(1900) == false
@test Dates.isleapyear(2000) == true
@test Dates.isleapyear(2004) == true
@test Dates.isleapyear(2008) == true
@test Dates.isleapyear(0) == true
@test Dates.isleapyear(1) == false
@test Dates.isleapyear(-1) == false
@test Dates.isleapyear(4) == true
@test Dates.isleapyear(-4) == true
# Create "test" check manually
test = Dates.DateTime(Dates.UTM(63492681600000))
# Test DateTime construction by parts
@test Dates.DateTime(2013) == test
@test Dates.DateTime(2013, 1) == test
@test Dates.DateTime(2013, 1, 1) == test
@test Dates.DateTime(2013, 1, 1, 0) == test
@test Dates.DateTime(2013, 1, 1, 0, 0) == test
@test Dates.DateTime(2013, 1, 1, 0, 0, 0) == test
@test Dates.DateTime(2013, 1, 1, 0, 0, 0, 0) == test
test = Dates.Date(Dates.UTD(734869))
# Test Date construction by parts
@test Dates.Date(2013) == test
@test Dates.Date(2013, 1) == test
@test Dates.Date(2013, 1, 1) == test
# Test Time construction by parts
t = Dates.Time(Dates.Nanosecond(82800000000000))
@test Dates.Time(23) == t
@test Dates.Time(23, 0) == t
@test Dates.Time(23, 0, 0) == t
@test Dates.Time(23, 0, 0, 0) == t
@test Dates.Time(23, 0, 0, 0, 0) == t
@test Dates.Time(23, 0, 0, 0, 0, 0) == t
# Test various input types for Date/DateTime
test = Dates.Date(1, 1, 1)
@test Dates.Date(Int8(1), Int8(1), Int8(1)) == test
@test Dates.Date(UInt8(1), UInt8(1), UInt8(1)) == test
@test Dates.Date(Int16(1), Int16(1), Int16(1)) == test
@test Dates.Date(UInt8(1), UInt8(1), UInt8(1)) == test
@test Dates.Date(Int32(1), Int32(1), Int32(1)) == test
@test Dates.Date(UInt32(1), UInt32(1), UInt32(1)) == test
@test Dates.Date(Int64(1), Int64(1), Int64(1)) == test
@test Dates.Date('\x01', '\x01', '\x01') == test
@test Dates.Date(true, true, true) == test
@test_throws ArgumentError Dates.Date(false, true, false)
@test Dates.Date(false, true, true) == test - Dates.Year(1)
@test_throws ArgumentError Dates.Date(true, true, false)
@test Dates.Date(UInt64(1), UInt64(1), UInt64(1)) == test
@test Dates.Date(-1, UInt64(1), UInt64(1)) == test - Dates.Year(2)
@test Dates.Date(Int128(1), Int128(1), Int128(1)) == test
@test_throws InexactError Dates.Date(170141183460469231731687303715884105727, Int128(1), Int128(1))
@test Dates.Date(UInt128(1), UInt128(1), UInt128(1)) == test
@test Dates.Date(big(1), big(1), big(1)) == test
@test Dates.Date(big(1), big(1), big(1)) == test
# Potentially won't work if can't losslessly convert to Int64
@test Dates.Date(BigFloat(1), BigFloat(1), BigFloat(1)) == test
@test Dates.Date(complex(1), complex(1), complex(1)) == test
@test Dates.Date(Float64(1), Float64(1), Float64(1)) == test
@test Dates.Date(Float32(1), Float32(1), Float32(1)) == test
@test Dates.Date(Float16(1), Float16(1), Float16(1)) == test
@test Dates.Date(Rational(1), Rational(1), Rational(1)) == test
@test_throws InexactError Dates.Date(BigFloat(1.2), BigFloat(1), BigFloat(1))
@test_throws InexactError Dates.Date(1 + im, complex(1), complex(1))
@test_throws InexactError Dates.Date(1.2, 1.0, 1.0)
@test_throws InexactError Dates.Date(1.2f0, 1.f0, 1.f0)
@test_throws InexactError Dates.Date(3//4, Rational(1), Rational(1)) == test
# Months, days, hours, minutes, seconds, and milliseconds must be in range
@test_throws ArgumentError Dates.Date(2013, 0, 1)
@test_throws ArgumentError Dates.Date(2013, 13, 1)
@test_throws ArgumentError Dates.Date(2013, 1, 0)
@test_throws ArgumentError Dates.Date(2013, 1, 32)
@test_throws ArgumentError Dates.DateTime(2013, 0, 1)
@test_throws ArgumentError Dates.DateTime(2013, 13, 1)
@test_throws ArgumentError Dates.DateTime(2013, 1, 0)
@test_throws ArgumentError Dates.DateTime(2013, 1, 32)
@test_throws ArgumentError Dates.DateTime(2013, 1, 1, 24)
@test_throws ArgumentError Dates.DateTime(2013, 1, 1, -1)
@test_throws ArgumentError Dates.DateTime(2013, 1, 1, 0, -1)
@test_throws ArgumentError Dates.DateTime(2013, 1, 1, 0, 60)
@test_throws ArgumentError Dates.DateTime(2013, 1, 1, 0, 0, -1)
@test_throws ArgumentError Dates.DateTime(2013, 1, 1, 0, 0, 60)
@test_throws ArgumentError Dates.DateTime(2013, 1, 1, 0, 0, 0, -1)
@test_throws ArgumentError Dates.DateTime(2013, 1, 1, 0, 0, 0, 1000)
@test_throws ArgumentError Dates.Time(24)
@test_throws ArgumentError Dates.Time(-1)
@test_throws ArgumentError Dates.Time(0, -1)
@test_throws ArgumentError Dates.Time(0, 60)
@test_throws ArgumentError Dates.Time(0, 0, -1)
@test_throws ArgumentError Dates.Time(0, 0, 60)
@test_throws ArgumentError Dates.Time(0, 0, 0, -1)
@test_throws ArgumentError Dates.Time(0, 0, 0, 1000)
@test_throws ArgumentError Dates.Time(0, 0, 0, 0, -1)
@test_throws ArgumentError Dates.Time(0, 0, 0, 0, 1000)
@test_throws ArgumentError Dates.Time(0, 0, 0, 0, 0, -1)
@test_throws ArgumentError Dates.Time(0, 0, 0, 0, 0, 1000)
# Test DateTime traits
a = Dates.DateTime(2000)
b = Dates.Date(2000)
c = Dates.Time(0)
@test Dates.calendar(a) == Dates.ISOCalendar
@test Dates.calendar(b) == Dates.ISOCalendar
@test eps(a) == Dates.Millisecond(1)
@test eps(b) == Dates.Day(1)
@test eps(c) == Dates.Nanosecond(1)
@test string(typemax(Dates.DateTime)) == "146138512-12-31T23:59:59"
@test string(typemin(Dates.DateTime)) == "-146138511-01-01T00:00:00"
@test typemax(Dates.DateTime) - typemin(Dates.DateTime) == Dates.Millisecond(9223372017043199000)
@test string(typemax(Dates.Date)) == "252522163911149-12-31"
@test string(typemin(Dates.Date)) == "-252522163911150-01-01"
@test string(typemax(Dates.Time)) == "23:59:59.999999999"
@test string(typemin(Dates.Time)) == "00:00:00"
@test isfinite(Dates.Date)
@test isfinite(Dates.DateTime)
@test isfinite(Dates.Time)
# Date-DateTime conversion/promotion
@test Dates.DateTime(a) == a
@test Dates.Date(a) == b
@test Dates.DateTime(b) == a
@test Dates.Date(b) == b
@test a == b
@test a == a
@test b == a
@test b == b
@test !(a < b)
@test !(b < a)
c = Dates.DateTime(2000)
d = Dates.Date(2000)
@test ==(a, c)
@test ==(c, a)
@test ==(d, b)
@test ==(b, d)
@test ==(a, d)
@test ==(d, a)
@test ==(b, c)
@test ==(c, b)
b = Dates.Date(2001)
@test b > a
@test a < b
@test a != b
@test Dates.Date(Dates.DateTime(Dates.Date(2012, 7, 1))) == Dates.Date(2012, 7, 1)
y = Dates.Year(1)
m = Dates.Month(1)
w = Dates.Week(1)
d = Dates.Day(1)
h = Dates.Hour(1)
mi = Dates.Minute(1)
s = Dates.Second(1)
ms = Dates.Millisecond(1)
@test Dates.DateTime(y) == Dates.DateTime(1)
@test Dates.DateTime(y, m) == Dates.DateTime(1, 1)
@test Dates.DateTime(y, m, d) == Dates.DateTime(1, 1, 1)
@test Dates.DateTime(y, m, d, h) == Dates.DateTime(1, 1, 1, 1)
@test Dates.DateTime(y, m, d, h, mi) == Dates.DateTime(1, 1, 1, 1, 1)
@test Dates.DateTime(y, m, d, h, mi, s) == Dates.DateTime(1, 1, 1, 1, 1, 1)
@test Dates.DateTime(y, m, d, h, mi, s, ms) == Dates.DateTime(1, 1, 1, 1, 1, 1, 1)
@test Dates.DateTime(Dates.Day(10), Dates.Month(2), y) == Dates.DateTime(1, 2, 10)
@test Dates.DateTime(Dates.Second(10), Dates.Month(2), y, Dates.Hour(4)) == Dates.DateTime(1, 2, 1, 4, 0, 10)
@test Dates.DateTime(Dates.Year(1), Dates.Month(2), Dates.Day(1),
Dates.Hour(4), Dates.Second(10)) == Dates.DateTime(1, 2, 1, 4, 0, 10)
@test Dates.Date(y) == Dates.Date(1)
@test Dates.Date(y, m) == Dates.Date(1, 1)
@test Dates.Date(y, m, d) == Dates.Date(1, 1, 1)
@test Dates.Date(m) == Dates.Date(1, 1, 1)
@test Dates.Date(d, y) == Dates.Date(1, 1, 1)
@test Dates.Date(d, m) == Dates.Date(1, 1, 1)
@test Dates.Date(m, y) == Dates.Date(1, 1, 1)
@test Dates.Date(Dates.Day(10), Dates.Month(2), y) == Dates.Date(1, 2, 10)
us = Dates.Microsecond(1)
ns = Dates.Nanosecond(1)
@test Dates.Time(h) == Dates.Time(1)
@test Dates.Time(h, mi) == Dates.Time(1, 1)
@test Dates.Time(h, mi, s) == Dates.Time(1, 1, 1)
@test Dates.Time(h, mi, s, ms) == Dates.Time(1, 1, 1, 1)
@test Dates.Time(h, mi, s, ms, us) == Dates.Time(1, 1, 1, 1, 1)
@test Dates.Time(h, mi, s, ms, us, ns) == Dates.Time(1, 1, 1, 1, 1, 1)
@test Dates.Time(us, h, s, ns, mi, ms) == Dates.Time(1, 1, 1, 1, 1, 1)
@test Dates.Time(Dates.Second(10), Dates.Minute(2), us, Dates.Hour(4)) == Dates.Time(4, 2, 10, 0, 1)
@test Dates.Time(Dates.Hour(4), Dates.Second(10), Dates.Millisecond(15),
Dates.Microsecond(20), Dates.Nanosecond(25)) == Dates.Time(4, 0, 10, 15, 20, 25)