-USING: accessors grouping kernel math math.order math.ranges
+USING: accessors grouping kernel math math.order ranges
math.vectors random sequences threads tools.test ;
IN: calendar
{ t } [
2009 1 29 <date> 1 months time+
- 2009 3 1 <date> =
+ 2009 2 28 <date> =
] unit-test
{ t } [
2008 2 29 <date> =
] unit-test
-{ t } [
- 2020 <year-gmt> dup 10000 >>second [ >gmt ] bi@ eq?
+{ { 1 1 1 2 2 2 3 3 3 4 4 4 } } [
+ 12 [1..b] [ 2020 swap 1 <date> quarter ] map
] unit-test
{ 0 }
{
T{ timestamp { year 2019 } { month 11 } { day 4 } }
-} [ 2019 308 year-ordinal>timestamp >gmt midnight ] unit-test
+} [ 2019 308 year-ordinal>timestamp ] unit-test
{
T{ timestamp { year 2020 } { month 11 } { day 3 } }
-} [ 2020 308 year-ordinal>timestamp >gmt midnight ] unit-test
+} [ 2020 308 year-ordinal>timestamp ] unit-test
{
T{ timestamp { year 2019 } { month 12 } { day 31 } }
-} [ 2019 365 year-ordinal>timestamp >gmt midnight ] unit-test
+} [ 2019 365 year-ordinal>timestamp ] unit-test
{
T{ timestamp { year 2020 } { month 12 } { day 31 } }
-} [ 2020 366 year-ordinal>timestamp >gmt midnight ] unit-test
+} [ 2020 366 year-ordinal>timestamp ] unit-test
{ t } [
2020 <year> timestamp>year-dates-gmt
] unit-test
{ t } [
- 1999 2025 [a,b] [
+ 1999 2025 [a..b] [
<year> timestamp>year-dates-gmt
[ >date< ymd>ordinal ] map [ < ] monotonic?
] map [ ] all?
] unit-test
{ t } [
- 1999 2025 [a,b] [
+ 1999 2025 [a..b] [
<year-gmt> timestamp>year-dates-gmt
[ >date< ymd>ordinal ] map [ < ] monotonic?
] map [ ] all?
{ 151 } [ 2014 1 10 <date> 2014 8 9 <date> weekdays-between ] unit-test
{ 151 } [ 2014 1 10 <date> 2014 8 10 <date> weekdays-between ] unit-test
+{ t } [ 2014 1 10 <date> weekday? ] unit-test
+{ f } [ 2014 1 10 <date> weekend? ] unit-test
+
+{ t } [ 2014 1 11 <date> weekend? ] unit-test
+{ f } [ 2014 1 11 <date> weekday? ] unit-test
+
{ t } [
2014 1 1 <date-gmt>
dup 1 tail swap v- [ 1 <= ] all?
] unit-test
-{ 0 } [
- 2014 1 1 <date-gmt>
- 2014 <year-gmt> timestamp>year-dates-gmt
- [ weekdays-between2 ] with map
-
- 2014 1 1 <date-gmt>
- 2014 <year-gmt> timestamp>year-dates-gmt
- [ weekdays-between ] with map
-
- v- sum
-] unit-test
-
{
{
T{ timestamp { year 2020 } { month 3 } { day 1 } }
T{ timestamp { year 2020 } { month 3 } { day 29 } }
}
} [
- 2020 march gmt 5 <iota> [ [ clone ] dip sunday-of-month ] with map
+ 2020 march gmt 5 <iota> [ sunday-of-month ] with map
] unit-test
T{ timestamp { year 2020 } { month 2 } { day 29 } }
}
} [
- 2020 february gmt 5 <iota> [ [ clone ] dip saturday-of-month ] with map
+ 2020 february gmt 5 <iota> [ saturday-of-month ] with map
] unit-test
T{ timestamp { year 2021 } { month 1 } { day 4 } }
}
} [
- 2020 december gmt 5 <iota> [ [ clone ] dip monday-of-month ] with map
+ 2020 december gmt 5 <iota> [ monday-of-month ] with map
+] unit-test
+
+{ t } [
+ now [ start-of-year ] [ end-of-year ] bi same-year?
+] unit-test
+
+{ t } [
+ now [ start-of-month ] [ end-of-month ] bi same-month?
+] unit-test
+
+{ t } [
+ now [ first-day-of-month ] [ last-day-of-month ] bi same-month?
+] unit-test
+
+! XXX: Different algorithm for start/end of week and week number
+! { t } [
+! now [ start-of-week ] [ end-of-week ] bi same-week?
+! ] unit-test
+
+{ t } [
+ now [ start-of-day ] [ end-of-day ] bi same-day?
+] unit-test
+
+{ t } [
+ now [ start-of-hour ] [ end-of-hour ] bi same-hour?
+] unit-test
+
+{ t } [
+ now [ start-of-minute ] [ end-of-minute ] bi same-minute?
] unit-test
+
+{ t } [
+ now [ start-of-second ] [ end-of-second ] bi same-second?
+] unit-test
+
+! Clone things by default
+{ f }
+[
+ now [ start-of-year ] [ end-of-year ] bi
+ [ month>> ] bi@ =
+] unit-test
+
+{ f } [
+ now [ first-day-of-month ] [ last-day-of-month ] bi
+ [ day>> ] bi@ =
+] unit-test
+
+
+{ f } [
+ now [ first-day-of-decade ] [ last-day-of-decade ] bi
+ [ year>> ] bi@ =
+] unit-test
+
+
+{ f } [
+ now [ start-of-millennium ] [ end-of-millennium ] bi
+ [ year>> ] bi@ =
+] unit-test
+
+{ f } [
+ now [ start-of-year ] [ end-of-year ] bi same-day?
+] unit-test
+
+{ f } [
+ now [ start-of-year ] [ end-of-year ] bi same-day-of-year?
+] unit-test
+
+
+{ t } [ 1999 1 1 <date> 2000 1 1 <date> same-day-of-year? ] unit-test
+{ f } [ 1999 1 1 <date> 2000 1 1 <date> same-day? ] unit-test
+{ t } [
+ 2000 1 1 <date> 4 >>hour
+ 2000 1 1 <date> same-day?
+] unit-test
+
+{
+ T{ timestamp { year 2023 } { month 4 } { day 9 } }
+ T{ timestamp
+ { year 2023 }
+ { month 4 }
+ { day 15 }
+ { hour 23 }
+ { minute 59 }
+ { second 59+999/1000 }
+ }
+} [ 2023 4 13 <date-gmt> start-of-week dup end-of-week ] unit-test
+
+{
+ T{ timestamp
+ { year 2024 }
+ { month 2 }
+ { day 15 }
+ { hour 7 }
+ }
+} [ 2024 02 15 <date-gmt> 48.87 2.67 sunrise >gmt ] unit-test
+
+{
+ T{ timestamp
+ { year 2024 }
+ { month 2 }
+ { day 15 }
+ { hour 17 }
+ { minute 7 }
+ }
+} [ 2024 02 15 <date-gmt> 48.87 2.67 sunset >gmt ] unit-test