USING: accessors grouping kernel math math.order math.ranges math.vectors random sequences threads tools.test ; IN: calendar [ 2004 12 32 0 0 0 instant ] [ not-in-interval? ] must-fail-with [ 2004 2 30 0 0 0 instant ] [ not-in-interval? ] must-fail-with [ 2003 2 29 0 0 0 instant ] [ not-in-interval? ] must-fail-with [ 2004 -2 9 0 0 0 instant ] [ not-in-interval? ] must-fail-with [ 2004 12 0 0 0 0 instant ] [ not-in-interval? ] must-fail-with [ 2004 12 1 24 0 0 instant ] [ not-in-interval? ] must-fail-with [ 2004 12 1 23 60 0 instant ] [ not-in-interval? ] must-fail-with [ 2004 12 1 23 59 60 instant ] [ not-in-interval? ] must-fail-with { } [ 2014 12 1 23 59 59+99/100 instant drop ] unit-test { f } [ 1900 leap-year? ] unit-test { t } [ 1904 leap-year? ] unit-test { t } [ 2000 leap-year? ] unit-test { f } [ 2001 leap-year? ] unit-test { f } [ 2006 leap-year? ] unit-test { t } [ 2006 10 10 0 0 0 instant 1 seconds time+ 2006 10 10 0 0 1 instant = ] unit-test { t } [ 2006 10 10 0 0 0 instant 100 seconds time+ 2006 10 10 0 1 40 instant = ] unit-test { t } [ 2006 10 10 0 0 0 instant -100 seconds time+ 2006 10 9 23 58 20 instant = ] unit-test { t } [ 2006 10 10 0 0 0 instant 86400 seconds time+ 2006 10 11 0 0 0 instant = ] unit-test { t } [ 2006 10 10 0 0 0 instant 10 minutes time+ 2006 10 10 0 10 0 instant = ] unit-test { +eq+ } [ 2006 10 10 0 0 0 instant 10.5 minutes time+ 2006 10 10 0 10 30 instant <=> ] unit-test { t } [ 2006 10 10 0 0 0 instant 3/4 minutes time+ 2006 10 10 0 0 45 instant = ] unit-test { t } [ 2006 10 10 0 0 0 instant -3/4 minutes time+ 2006 10 9 23 59 15 instant = ] unit-test { t } [ 2006 10 10 0 0 0 instant 7200 minutes time+ 2006 10 15 0 0 0 instant = ] unit-test { t } [ 2006 10 10 0 0 0 instant -10 minutes time+ 2006 10 9 23 50 0 instant = ] unit-test { t } [ 2006 10 10 0 0 0 instant -100 minutes time+ 2006 10 9 22 20 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 1 hours time+ 2006 1 1 1 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 24 hours time+ 2006 1 2 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -24 hours time+ 2005 12 31 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 12 hours time+ 2006 1 1 12 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 72 hours time+ 2006 1 4 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 1 days time+ 2006 1 2 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -1 days time+ 2005 12 31 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 365 days time+ 2007 1 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -365 days time+ 2005 1 1 0 0 0 instant = ] unit-test { t } [ 2004 1 1 0 0 0 instant 365 days time+ 2004 12 31 0 0 0 instant = ] unit-test { t } [ 2004 1 1 0 0 0 instant 366 days time+ 2005 1 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 11 months time+ 2006 12 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 12 months time+ 2007 1 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 24 months time+ 2008 1 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 13 months time+ 2007 2 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 1 months time+ 2006 2 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 0 months time+ 2006 1 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -1 months time+ 2005 12 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -2 months time+ 2005 11 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -13 months time+ 2004 12 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -24 months time+ 2004 1 1 0 0 0 instant = ] unit-test { t } [ 2004 2 29 0 0 0 instant 12 months time+ 2005 3 1 0 0 0 instant = ] unit-test { t } [ 2004 2 29 0 0 0 instant -12 months time+ 2003 3 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 0 years time+ 2006 1 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant 1 years time+ 2007 1 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -1 years time+ 2005 1 1 0 0 0 instant = ] unit-test { t } [ 2006 1 1 0 0 0 instant -100 years time+ 1906 1 1 0 0 0 instant = ] unit-test ! [ t ] [ 2004 2 29 0 0 0 instant -1 years time+ ! 2003 2 28 0 0 0 instant = ] unit-test { 5 } [ 2006 7 14 0 0 0 instant day-of-week ] unit-test { t } [ 2006 7 14 [ julian-day-number julian-day-number>date 0 0 0 instant ] 3keep 0 0 0 instant = ] unit-test { 1 } [ 2006 1 1 0 0 0 instant day-of-year ] unit-test { 60 } [ 2004 2 29 0 0 0 instant day-of-year ] unit-test { 61 } [ 2004 3 1 0 0 0 instant day-of-year ] unit-test { 366 } [ 2004 12 31 0 0 0 instant day-of-year ] unit-test { 365 } [ 2003 12 31 0 0 0 instant day-of-year ] unit-test { 60 } [ 2003 3 1 0 0 0 instant day-of-year ] unit-test { t } [ 2004 12 31 0 0 0 instant dup = ] unit-test { t } [ 2004 1 1 0 0 0 instant 10 seconds 5 years time+ time+ 2009 1 1 0 0 10 instant = ] unit-test { t } [ 2004 1 1 0 0 0 instant -10 seconds -5 years time+ time+ 1998 12 31 23 59 50 instant = ] unit-test { t } [ 2004 1 1 23 0 0 12 hours >gmt 2004 1 1 11 0 0 instant = ] unit-test { t } [ 2004 1 1 5 0 0 -11 hours >gmt 2004 1 1 16 0 0 instant = ] unit-test { t } [ 2004 1 1 23 0 0 9+1/2 hours >gmt 2004 1 1 13 30 0 instant = ] unit-test { +eq+ } [ 2004 1 1 13 30 0 instant 2004 1 1 12 30 0 -1 hours <=> ] unit-test { +gt+ } [ 2004 1 1 13 30 0 instant 2004 1 1 12 30 0 instant <=> ] unit-test { +lt+ } [ 2004 1 1 12 30 0 instant 2004 1 1 13 30 0 instant <=> ] unit-test { +gt+ } [ 2005 1 1 12 30 0 instant 2004 1 1 13 30 0 instant <=> ] unit-test { t } [ 0 micros>timestamp unix-1970 = ] unit-test { t } [ 123456789000000 [ micros>timestamp timestamp>micros ] keep = ] unit-test { t } [ 123456789123456000 [ micros>timestamp timestamp>micros ] keep = ] unit-test : checktime+ ( duration -- ? ) now dup clone [ rot time+ drop ] keep = ; { t } [ 5 seconds checktime+ ] unit-test { t } [ 5 minutes checktime+ ] unit-test { t } [ 5 hours checktime+ ] unit-test { t } [ 5 days checktime+ ] unit-test { t } [ 5 weeks checktime+ ] unit-test { t } [ 5 months checktime+ ] unit-test { t } [ 5 years checktime+ ] unit-test { t } [ now 50 milliseconds sleep now before? ] unit-test { t } [ now 50 milliseconds sleep now swap after? ] unit-test { t } [ now 50 milliseconds sleep now 50 milliseconds sleep now swapd between? ] unit-test { 4 12 } [ 2009 easter [ month>> ] [ day>> ] bi ] unit-test { 4 2 } [ 1961 easter [ month>> ] [ day>> ] bi ] unit-test { f } [ now dup midnight eq? ] unit-test { f } [ now dup easter eq? ] unit-test { f } [ now dup start-of-year eq? ] unit-test { t } [ 1325376000 unix-time>timestamp 2012 = ] unit-test { t } [ 1356998399 unix-time>timestamp 2013 1 seconds time- = ] unit-test { t } [ 1500000000 random [ unix-time>timestamp timestamp>unix-time ] keep = ] unit-test { t } [ 2009 1 29 1 months time+ 2009 3 1 = ] unit-test { t } [ 2008 1 29 1 months time+ 2008 2 29 = ] unit-test { 0 } [ gmt gmt-offset>> duration>seconds ] unit-test ! am [ now 30 am ] [ not-in-interval? ] must-fail-with ! pm [ now 30 pm ] [ not-in-interval? ] must-fail-with { 1 } [ 2018 12 31 week-number ] unit-test { 16 } [ 2019 4 17 week-number ] unit-test { 53 } [ 2021 1 1 week-number ] unit-test { 53 } [ 2004 weeks-in-week-year ] unit-test { 52 } [ 2013 weeks-in-week-year ] unit-test { f } [ now dup start-of-day eq? ] unit-test { f } [ now dup end-of-day eq? ] unit-test { t } [ now dup end-of-day! eq? ] unit-test { f } [ now dup start-of-month eq? ] unit-test { f } [ now dup end-of-month eq? ] unit-test { f } [ now dup start-of-year eq? ] unit-test { f } [ now dup end-of-year eq? ] unit-test { f } [ now dup midnight eq? ] unit-test { t } [ now dup midnight! eq? ] unit-test { T{ timestamp { year 2019 } { month 11 } { day 4 } } } [ 2019 308 year-ordinal>timestamp >gmt midnight ] unit-test { T{ timestamp { year 2020 } { month 11 } { day 3 } } } [ 2020 308 year-ordinal>timestamp >gmt midnight ] unit-test { T{ timestamp { year 2019 } { month 12 } { day 31 } } } [ 2019 365 year-ordinal>timestamp >gmt midnight ] unit-test { T{ timestamp { year 2020 } { month 12 } { day 31 } } } [ 2020 366 year-ordinal>timestamp >gmt midnight ] unit-test { t } [ 2020 timestamp>year-dates [ >date< ymd>ordinal ] map [ < ] monotonic? ] unit-test { t } [ 1999 2025 [a,b] [ timestamp>year-dates [ >date< ymd>ordinal ] map [ < ] monotonic? ] map [ ] all? ] unit-test { t } [ 1999 2025 [a,b] [ timestamp>year-dates [ >date< ymd>ordinal ] map [ < ] monotonic? ] map [ ] all? ] unit-test { 136 } [ 2014 1 10 2014 7 20 weekdays-between ] unit-test { 137 } [ 2014 1 10 2014 7 21 weekdays-between ] unit-test { 138 } [ 2014 1 10 2014 7 22 weekdays-between ] unit-test { 139 } [ 2014 1 10 2014 7 23 weekdays-between ] unit-test { 140 } [ 2014 1 10 2014 7 24 weekdays-between ] unit-test { 141 } [ 2014 1 10 2014 7 25 weekdays-between ] unit-test { 141 } [ 2014 1 10 2014 7 26 weekdays-between ] unit-test { 141 } [ 2014 1 10 2014 7 27 weekdays-between ] unit-test { 142 } [ 2014 1 10 2014 7 28 weekdays-between ] unit-test { 143 } [ 2014 1 10 2014 7 29 weekdays-between ] unit-test { 144 } [ 2014 1 10 2014 7 30 weekdays-between ] unit-test { 145 } [ 2014 1 10 2014 7 31 weekdays-between ] unit-test { 146 } [ 2014 1 10 2014 8 1 weekdays-between ] unit-test { 146 } [ 2014 1 10 2014 8 2 weekdays-between ] unit-test { 146 } [ 2014 1 10 2014 8 3 weekdays-between ] unit-test { 147 } [ 2014 1 10 2014 8 4 weekdays-between ] unit-test { 148 } [ 2014 1 10 2014 8 5 weekdays-between ] unit-test { 149 } [ 2014 1 10 2014 8 6 weekdays-between ] unit-test { 150 } [ 2014 1 10 2014 8 7 weekdays-between ] unit-test { 151 } [ 2014 1 10 2014 8 8 weekdays-between ] unit-test { 151 } [ 2014 1 10 2014 8 9 weekdays-between ] unit-test { 151 } [ 2014 1 10 2014 8 10 weekdays-between ] unit-test { t } [ 2014 1 1 2014 timestamp>year-dates [ weekdays-between ] with map [ <= ] monotonic? ] unit-test { t } [ 2020 1 1 2020 timestamp>year-dates [ weekdays-between ] with map [ <= ] monotonic? ] unit-test { t } [ 2014 1 1 2014 timestamp>year-dates [ weekdays-between ] with map dup 1 tail swap v- [ 1 <= ] all? ] unit-test { t } [ 2020 1 1 2020 timestamp>year-dates [ weekdays-between ] with map dup 1 tail swap v- [ 1 <= ] all? ] unit-test { 0 } [ 2014 1 1 2014 timestamp>year-dates [ weekdays-between2 ] with map 2014 1 1 2014 timestamp>year-dates [ weekdays-between ] with map v- sum ] unit-test