Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 466 lines (410 sloc) 22.807 kb
7d2cc0e6 » mberends
2010-04-21 [spec/S32-temporal/DateTime.t] renamed from Temporal.t, add 2 strftim…
1 use v6;
2 use Test;
3
9c5f9049 » Kodi Arfer
2010-12-03 Added tests for DateTime.perl.
4 plan 173;
42149985 » Kodi
2010-07-07 [t/spec] Cleaned up DateTime.t a bit. (I hadn't meant to commit it yet.)
5
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
6 my $orwell = DateTime.new(year => 1984);
7
62ecf0f1 » tadzik
2011-09-18 [DateTime.t] Avoid passing doubled named parameters; some implementat…
8 sub dt(*%args) { DateTime.new(|{year => 1984, %args}) }
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
9 sub dtc(*%args) { $orwell.clone(|%args) }
7d2cc0e6 » mberends
2010-04-21 [spec/S32-temporal/DateTime.t] renamed from Temporal.t, add 2 strftim…
10
d8786c3e » moritz
2011-08-08 [DateTime.t] avoid passing the same named argument twice
11 sub ymd($year, $month, $day) { DateTime.new: :$year, :$month, :$day }
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
12 sub ymdc($year, $month, $day) { dtc :$year, :$month, :$day }
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
13
14 sub ds(Str $s) { DateTime.new($s) }
15
16 sub tz($tz) { ds "2005-02-04T15:25:00$tz" }
17
18 sub show-dt($dt) {
19 join ' ', floor($dt.second), $dt.minute, $dt.hour,
20 $dt.day, $dt.month, $dt.year, $dt.day-of-week
21 }
7d2cc0e6 » mberends
2010-04-21 [spec/S32-temporal/DateTime.t] renamed from Temporal.t, add 2 strftim…
22
23 # An independent calculation to cross check the Temporal algorithms.
33344605 » Kodi
2010-07-15 [t/spec/S32-temporal] Reorganization and many additions.
24 sub test-gmtime( Int $t is copy ) {
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
25 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);
7d2cc0e6 » mberends
2010-04-21 [spec/S32-temporal/DateTime.t] renamed from Temporal.t, add 2 strftim…
26 $sec = $t % 60; $t div= 60; # $t is now epoch minutes
27 $min = $t % 60; $t div= 60; # $t is now epoch hours
28 $hour = $t % 24; $t div= 24; # $t is now epoch days
29 # Not a sophisticated or fast algorithm, just an understandable one
30 # only valid from 1970-01-01 until 2100-02-28
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
31 $wday = ($t+3) % 7; # 1970-01-01 was a Thursday
32 # Monday is $wday 0, unlike Perl 5.
7d2cc0e6 » mberends
2010-04-21 [spec/S32-temporal/DateTime.t] renamed from Temporal.t, add 2 strftim…
33 $year = 70; # (Unix epoch 0) == (Gregorian 1970) == (Perl year 70)
34 loop ( $yday = 365; $t >= $yday; $year++ ) {
35 $t -= $yday; # count off full years of 365 or 366 days
36 $yday = (($year+1) % 4 == 0) ?? 366 !! 365;
37 }
38 $yday = $t;
39 # Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
40 my @days = 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31;
41 @days[1] = ($year % 4 == 0) ?? 29 !! 28; # calibrate February
42 loop ( $mon = 0; $t >= @days[$mon]; $mon++ ) {
43 $t -= @days[$mon]; # count off full months of whatever days
44 }
45 $mday = $t + 1;
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
46 return ($sec, $min, $hour, $mday, $mon + 1, $year + 1900, $wday + 1);
47 } # 0 1 2 3 4 5 6
42149985 » Kodi
2010-07-07 [t/spec] Cleaned up DateTime.t a bit. (I hadn't meant to commit it yet.)
48
ce9b56d6 » Kodi
2010-07-07 [S32] Dropped mention of quarters from Temporal.pod. I don't think qu…
49 # --------------------------------------------------------------------
e033ea55 » Kodi
2010-07-18 [t/spec/S32-temporal] Fixed smart links.
50 # L<S32::Temporal/C<time>>
33344605 » Kodi
2010-07-15 [t/spec/S32-temporal] Reorganization and many additions.
51 # --------------------------------------------------------------------
52
53 isa_ok time, Int, 'time returns an Int';
54
55 # --------------------------------------------------------------------
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
56 # L<S32::Temporal/C<DateTime>/immutable>
57 # --------------------------------------------------------------------
58
59 {
60 my $dt = ymd 1999, 5, 6;
61 dies_ok { $dt.year = 2000 }, 'DateTimes are immutable (1)';
62 dies_ok { $dt.minute = 30 }, 'DateTimes are immutable (2)';
63 dies_ok { $dt.timezone = 0 }, 'DateTimes are immutable (3)';
64 dies_ok { $dt.formatter = { $dt.hour } }, 'DateTimes are immutable (4)';
65 }
66
67 # --------------------------------------------------------------------
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
68 # Input validation
ce9b56d6 » Kodi
2010-07-07 [S32] Dropped mention of quarters from Temporal.pod. I don't think qu…
69 # --------------------------------------------------------------------
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
70
e033ea55 » Kodi
2010-07-18 [t/spec/S32-temporal] Fixed smart links.
71 # L<S32::Temporal/C<DateTime>/outside of the ranges specified>
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
72
73 lives_ok { dt month => 1 }, 'DateTime accepts January';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
74 dies_ok { dt month => 0 }, 'DateTime rejects month 0';
75 dies_ok { dt month => -1 }, 'DateTime rejects month -1';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
76 lives_ok { dt month => 12 }, 'DateTime accepts December';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
77 dies_ok { dt month => 13 }, 'DateTime rejects month 13';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
78 lives_ok { dt month => 1, day => 31 }, 'DateTime accepts January 31';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
79 dies_ok { dt month => 1, day => 32 }, 'DateTime rejects January 32';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
80 lives_ok { dt month => 6, day => 30 }, 'DateTime accepts June 30';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
81 dies_ok { dt month => 6, day => 31 }, 'DateTime rejects June 31';
82 dies_ok { dt month => 2, day => 30 }, 'DateTime rejects February 30';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
83 lives_ok { ymd 1996, 2, 29 }, 'DateTime accepts 29 Feb 1996';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
84 dies_ok { ymd 1995, 2, 29 }, 'DateTime rejects 29 Feb 1995';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
85 lives_ok { ymd 2000, 2, 29 }, 'DateTime accepts 29 Feb 2000';
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
86 lives_ok { ymdc 2000, 2, 29 }, 'DateTime accepts 29 Feb 2000 (clone)';
87 lives_ok { ds '2000-02-29T22:33:44' }, 'DateTime accepts 29 Feb 2000 (ISO)';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
88 dies_ok { ymd 1900, 2, 29 }, 'DateTime rejects 29 Feb 1900';
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
89 dies_ok { ymdc 1900, 2, 29 }, 'DateTime rejects 29 Feb 1900 (clone)';
90 dies_ok { ds '1900-02-29T22:33:44' }, 'DateTime rejects 29 Feb 1900 (ISO)';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
91 lives_ok { dt hour => 0 }, 'DateTime accepts hour 0';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
92 dies_ok { dt hour => -1 }, 'DateTime rejects hour 0';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
93 lives_ok { dt hour => 23 }, 'DateTime accepts hour 23';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
94 dies_ok { dt hour => 24 }, 'DateTime rejects hour 24';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
95 lives_ok { dt minute => 0 }, 'DateTime accepts minute 0';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
96 dies_ok { dt minute => -1 }, 'DateTime rejects minute -1';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
97 lives_ok { dt minute => 59 }, 'DateTime accepts minute 59';
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
98 lives_ok { dtc minute => 59 }, 'DateTime accepts minute 59 (clone)';
99 lives_ok { ds '1999-01-01T00:59:22' }, 'DateTime accepts minute 59 (ISO)';
6edbf450 » tadzik
2011-09-18 [S32-temporal/DateTime.t] Avoid some named params magic.
100 lives_ok { DateTime.new: date => Date.new(1999, 1, 1), minute => 59 }, 'DateTime accepts minute 59 (with Date)';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
101 dies_ok { dt minute => 60 }, 'DateTime rejects minute 60';
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
102 dies_ok { dtc minute => 60 }, 'DateTime rejects minute 60 (clone)';
103 dies_ok { ds '1999-01-01T00:60:22' }, 'DateTime rejects minute 60 (ISO)';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
104 dies_ok { dt date => Date.new(1999, 1, 1), minute => 60 }, 'DateTime rejects minute 60 (with Date)';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
105 lives_ok { dt second => 0 }, 'DateTime accepts second 0';
106 lives_ok { dt second => 1/2 }, 'DateTime accepts second 1/2';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
107 dies_ok { dt second => -1 }, 'DateTime rejects second -1';
108 dies_ok { dt second => -1/2 }, 'DateTime rejects second -1/2';
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
109 lives_ok { dt second => 59.5 }, 'DateTime accepts second 59.5';
110 lives_ok { dtc second => 59.5 }, 'DateTime accepts second 59.5 (clone)';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
111 dies_ok { dt second => 62 }, 'DateTime rejects second 62';
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
112 dies_ok { dtc second => 62 }, 'DateTime rejects second 62 (clone)';
113 dies_ok { ds '1999-01-01T12:10:62' }, 'DateTime rejects second 62 (ISO)';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
114 dies_ok { dt date => Date.new(1999, 1, 1), second => 62 }, 'DateTime rejects second 62 (with Date)';
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
115
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
116 # Validate leap seconds.
117
118 dies_ok { ds '1999-01-01T12:10:60' }, 'Leap-second validation: Wrong time and date';
119 dies_ok { ds '1999-01-01T23:59:60' }, 'Leap-second validation: Wrong date';
120 dies_ok { ds '1999-06-30T23:59:60' }, 'Leap-second validation: Wrong year (1)';
121 dies_ok { ds '1999-12-31T23:59:60' }, 'Leap-second validation: Wrong year (2)';
122 dies_ok { ds '1998-06-30T23:59:60' }, 'Leap-second validation: Wrong; June 30 on a year with a leap second in December 31';
123 dies_ok { ds '1998-12-31T23:58:60' }, 'Leap-second validation: Wrong minute';
124 dies_ok { ds '1998-12-31T22:59:60' }, 'Leap-second validation: Wrong hour';
125 lives_ok { ds '1998-12-31T23:59:60' }, 'Leap-second validation: Okay; December 31';
126 dies_ok { ds '1997-12-31T23:59:60' }, 'Leap-second validation: Wrong; December 31 on a year with a leap second in June 30';
127 dies_ok { dt year => 1997, month => 12, day => 31,
128 hour => 23, minute => 59, second => 60.9 }, 'Leap-second validation: Wrong; December 31 on a year with a leap second in June 30 (second 60.9)';
129 lives_ok { ds '1997-06-30T23:59:60' }, 'Leap-second validation: Okay; June 30';
130 lives_ok { dt year => 1997, month => 6, day => 30,
131 hour => 23, minute => 59, second => 60.9 }, 'Leap-second validation: Okay; June 30 (second 60.9)';
132 dies_ok { ds '1997-06-30T23:59:61' }, 'Leap-second validation: Wrong; there are no seconds 61 (in the 20th century, anyway).';
133
134 dies_ok { ds '1998-12-31T23:59:60+0200' }, 'Leap-second validation: Wrong because of TZ; December 31';
135 lives_ok { ds '1999-01-01T01:59:60+0200' }, 'Leap-second validation: Okay because of TZ; January 1';
136 dies_ok { ds '1997-06-30T23:59:60-0200' }, 'Leap-second validation: Wrong because of TZ; June 30';
137 lives_ok { ds '1997-06-30T21:59:60-0200' }, 'Leap-second validation: Okay because of TZ; June 30';
138 dies_ok { dt year => 1998, month => 12, day => 31,
139 hour => 23, minute => 59, second => 60.9,
140 timezone => 2*60*60 }, 'Leap-second validation: Wrong because of TZ; December 31 (second 60.9)';
141 lives_ok { dt year => 1999, month => 1, day => 1,
142 hour => 1, minute => 59, second => 60.9,
143 timezone => 2*60*60 }, 'Leap-second validation: Okay because of TZ; January 1 (second 60.9)';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
144
ce9b56d6 » Kodi
2010-07-07 [S32] Dropped mention of quarters from Temporal.pod. I don't think qu…
145 # --------------------------------------------------------------------
62da93ee » Kodi
2010-07-26 [t/spec] More Temporal tests.
146 # DateTime.new(Int)
ce9b56d6 » Kodi
2010-07-07 [S32] Dropped mention of quarters from Temporal.pod. I don't think qu…
147 # --------------------------------------------------------------------
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
148
62da93ee » Kodi
2010-07-26 [t/spec] More Temporal tests.
149 # L<S32::Temporal/C<DateTime>/DateTime.new(time)>
150
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
151 is show-dt(DateTime.new(0)), '0 0 0 1 1 1970 4', 'DateTime at beginning of Unix epoch';
152 is show-dt(DateTime.new(946684799)), '59 59 23 31 12 1999 5', 'from POSIX at 1999-12-31T23:59:59Z';
153 # last second of previous millennium, FSVO 'millennium'.
154 is show-dt(DateTime.new(946684800)), '0 0 0 1 1 2000 6', 'from POSIX at 2000-01-01T00:00:00Z';
155 # one second later, sing Auld Lang Syne.
156
157 # compare dates for a series of times earlier and later than "now", so
158 # that every test run will use different values
9c5f9049 » Kodi Arfer
2010-12-03 Added tests for DateTime.perl.
159 # and test round-tripping with .perl while we're at it
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
160 {
33344605 » Kodi
2010-07-15 [t/spec/S32-temporal] Reorganization and many additions.
161 my $t = time;
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
162 my $t1 = $t;
163 my $t2 = $t;
164 # the offset changes all time components and causes overflow/underflow
165 my $offset = ((((7*31+1)*24+10)*60+21)*60+21);
166 for 1, 2, 3 {
167 $t1 -= $offset;
168 my $dt = DateTime.new($t1);
169 is show-dt($dt), join(' ', test-gmtime $t1), "crosscheck $dt";
9c5f9049 » Kodi Arfer
2010-12-03 Added tests for DateTime.perl.
170 is show-dt($dt), show-dt(eval $dt.perl), ".perl round-tripping with $dt";
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
171 $t2 += $offset;
172 $dt = DateTime.new($t2);
173 is show-dt($dt), join(' ', test-gmtime $t2), "crosscheck $dt";
9c5f9049 » Kodi Arfer
2010-12-03 Added tests for DateTime.perl.
174 is show-dt($dt), show-dt(eval $dt.perl), ".perl round-tripping with $dt";
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
175 }
176 }
177
178 {
179 my $dt = DateTime.new(946684799,
180 timezone => -(5*60*60 + 55*60),
181 formatter => { .day ~ '/' ~ .month ~ '/' ~ .year ~ ' ' ~
182 .second ~ 's' ~ .minute ~ 'm' ~ .hour ~ 'h' });
61aae6fc » Kodi
2010-07-25 [t/spec] More tests for Instants and Durations.
183 is ~$dt, '31/12/1999 59s4m18h', 'DateTime.new(Int) with time zone and formatter';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
184 }
185
62da93ee » Kodi
2010-07-26 [t/spec] More Temporal tests.
186 # L<S32::Temporal/C<DateTime>/'Ambiguous POSIX times'>
187
188 is show-dt(DateTime.new(915148800)), '0 0 0 1 1 1999 5', 'from POSIX at 1999-01-01T00:00:00Z';
189 # 915148800 is also the POSIX time of the leap second
190 # 1998-12-31T23:59:60.
191 is show-dt(DateTime.new(425865600)), '0 0 0 1 7 1983 5', 'from POSIX at 1983-07-01T00:00:00Z';
192 # 425865600 is also the POSIX time of the leap second
193 # 1983-06-30T23:59:60.
194
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
195 # --------------------------------------------------------------------
e033ea55 » Kodi
2010-07-18 [t/spec/S32-temporal] Fixed smart links.
196 # L<S32::Temporal/C<DateTime>/'A shorter way to send in date'>
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
197 # DateTime.new(Str)
198 # --------------------------------------------------------------------
199
200 is ds('2009-12-31T22:33:44Z'), '2009-12-31T22:33:44Z', 'round-tripping ISO 8601 (Z)';
201 is ds('2009-12-31T22:33:44+0000'), '2009-12-31T22:33:44Z', 'round-tripping ISO 8601 (+0000 to Z)';
202 is ds('2009-12-31T22:33:44+1100'), '2009-12-31T22:33:44+1100', 'round-tripping ISO 8601 (+1100)';
203 is ds('2009-12-31T22:33:44'), '2009-12-31T22:33:44Z', 'DateTime.new(Str) defaults to UTC';
204 is DateTime.new('2009-12-31T22:33:44',
205 timezone => 12*60*60 + 34*60),
206 '2009-12-31T22:33:44+1234', 'DateTime.new(Str) with :timezone';
207 is DateTime.new('2009-12-31T22:33:44',
208 formatter => { ($^dt.hour % 12) ~ 'ish' } ),
209 '10ish', 'DateTime.new(Str) with formatter';
210
211 # --------------------------------------------------------------------
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
212 # L<S32::Temporal/C<DateTime>/'truncated-to'>
213 # --------------------------------------------------------------------
214
215 {
216 my $moon-landing = dt # Although the seconds part is fictional.
217 year => 1969, month => 7, day => 20,
218 hour => 8, minute => 17, second => 32.4;
219 my $dt = $moon-landing.truncated-to(:second);
220 is $dt.second, 32, 'DateTime.truncated-to(:second)';
221 $dt = $moon-landing.truncated-to(:minute);
222 is ~$dt, '1969-07-20T08:17:00Z', 'DateTime.truncated-to(:minute)';
223 $dt = $moon-landing.truncated-to(:hour);
224 is ~$dt, '1969-07-20T08:00:00Z', 'DateTime.truncated-to(:hour)';
225 $dt = $moon-landing.truncated-to(:day);
226 is ~$dt, '1969-07-20T00:00:00Z', 'DateTime.truncate-to(:day)';
227 }
228
229 # --------------------------------------------------------------------
e033ea55 » Kodi
2010-07-18 [t/spec/S32-temporal] Fixed smart links.
230 # L<S32::Temporal/C<DateTime>/'one additional constructor: now'>
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
231 # --------------------------------------------------------------------
232
233 {
33344605 » Kodi
2010-07-15 [t/spec/S32-temporal] Reorganization and many additions.
234 my $t = time;
235 1 while time == $t; # loop until the next second
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
236 $t = time;
237 my $dt1 = DateTime.new($t);
61aae6fc » Kodi
2010-07-25 [t/spec] More tests for Instants and Durations.
238 my $dt2 = DateTime.now.utc; # $dt1 and $dt2 might differ very occasionally
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
239 is show-dt($dt1), show-dt($dt2), 'DateTime.now uses current time';
240
33344605 » Kodi
2010-07-15 [t/spec/S32-temporal] Reorganization and many additions.
241 $t = time;
242 1 while time == $t;
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
243 $t = time;
244 $dt1 = DateTime.new($t);
245 $dt2 = DateTime.now(
246 timezone => 22*60*60,
247 formatter => { ~($^x.hour) });
248 is ~$dt2, ~(($dt1.hour + 22) % 24), 'DateTime.now with time zone and formatter';
249 }
250
251 # --------------------------------------------------------------------
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
252 # L<S32::Temporal/Accessors/'the method posix'>
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
253 # --------------------------------------------------------------------
254
255 {
256 is dt(year => 1970).posix, 0, 'DateTime.posix (1970-01-01T00:00:00Z)';
257 my $dt = dt
258 year => 1970, month => 1, day => 1,
259 hour => 1, minute => 1, second => 1;
260 is $dt.posix, 3661, 'DateTime.posix (1970-01-01T01:01:01Z)';
261 $dt = dt
262 year => 1970, month => 1, day => 1,
263 hour => 1, minute => 1, second => 1,
264 timezone => -1*60*60 -1*60;
265 is $dt.posix, 7321, 'DateTime.posix (1970-01-01T01:01:01-0101)';
266 # round-trip test for the current time
33344605 » Kodi
2010-07-15 [t/spec/S32-temporal] Reorganization and many additions.
267 my $t = time;
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
268 my @t = test-gmtime $t;
269 $dt = dt
270 year => @t[5], month => @t[4], day => @t[3],
271 hour => @t[2], minute => @t[1], second => @t[0];
272 is $dt.posix, $t, "at $dt, POSIX is {$dt.posix}";
273 }
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
274
ce9b56d6 » Kodi
2010-07-07 [S32] Dropped mention of quarters from Temporal.pod. I don't think qu…
275 # --------------------------------------------------------------------
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
276 # L<S32::Temporal/Accessors/'The method whole-second'>
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
277 # --------------------------------------------------------------------
278
279 is dt(second => 22).whole-second, 22, 'DateTime.whole-second (22)';
280 is dt(second => 22.1).whole-second, 22, 'DateTime.whole-second (22.1)';
281 is dt(second => 15.9).whole-second, 15, 'DateTime.whole-second (15.9)';
282 is dt(second => 0).whole-second, 0, 'DateTime.whole-second (0)';
283 is dt(second => 0.9).whole-second, 0, 'DateTime.whole-second (0.9)';
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
284 is ds('1997-06-30T23:59:60Z').whole-second, 60, 'DateTime.whole-second (60)';
285
286 {
287 my $dt = dt year => 1997, month => 6, day => 30,
288 hour => 23, minute => 59, second => 60.5;
289 is $dt.whole-second, 60, 'DateTime.whole-second (60.5)';
290 }
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
291
292 # --------------------------------------------------------------------
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
293 # L<S32::Temporal/Accessors/'The Date method'>
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
294 # --------------------------------------------------------------------
295
296 {
297 my $dt = ymd 2010, 6, 4;
298 my $date;
299 lives_ok { $date = $dt.Date(); }, 'DateTime.Date';
300 isa_ok $date, Date, 'Date object is correct class';
301 is $date.year, 2010, 'Date year';
302 is $date.month, 6, 'Date month';
303 is $date.day, 4, 'Date day';
304 }
305
306 # --------------------------------------------------------------------
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
307 # L<S32::Temporal/Accessors/'The method offset'>
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
308 # --------------------------------------------------------------------
309
310 is tz( 'Z').offset, 0, 'DateTime.offset (Z)';
311 is tz('+0000').offset, 0, 'DateTime.offset (+0000)';
312 is tz('-0000').offset, 0, 'DateTime.offset (-0000)';
313 is tz('+0015').offset, 900, 'DateTime.offset (+0015)';
314 is tz('-0015').offset, -900, 'DateTime.offset (-0015)';
315 is tz('+0700').offset, 25200, 'DateTime.offset (+0700)';
316 is tz('-0700').offset, -25200, 'DateTime.offset (-0700)';
317 is tz('+1433').offset, 52380, 'DateTime.offset (+1433)';
318 is tz('-1433').offset, -52380, 'DateTime.offset (-1433)';
319 is dt(timezone => 3661).offset, 3661, 'DateTime.offset (1 hour, 1 minute, 1 second)';
320
321 {
322 my $tz = sub ($dt, $to-utc) {
323 $to-utc
324 ?? $dt.year == 2001 ?? 1 !! 2
325 !! 3
326 };
327 my $dt = dt year => 2001, timezone => $tz;
328 is $dt.offset, 1, 'DateTime.offset (function, 1)';
329 $dt = dt year => 2000, timezone => $tz;
330 is $dt.offset, 2, 'DateTime.offset (function, 2)';
331 }
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
332
ce9b56d6 » Kodi
2010-07-07 [S32] Dropped mention of quarters from Temporal.pod. I don't think qu…
333 # --------------------------------------------------------------------
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
334 # L<S32::Temporal/C<DateTime>/in-timezone>
ce9b56d6 » Kodi
2010-07-07 [S32] Dropped mention of quarters from Temporal.pod. I don't think qu…
335 # --------------------------------------------------------------------
336
337 {
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
338 sub with-tz($dt, $hours, $minutes=0, $seconds=0) {
339 $dt.in-timezone($hours*60*60 + $minutes*60 + $seconds);
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
340 }
341 sub hms($dt) {
342 $dt.hour ~ ',' ~ $dt.minute ~ ',' ~ $dt.second
343 }
344
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
345 my $dt = with-tz(tz('+0200'), 4);
346 is ~$dt, '2005-02-04T17:25:00+0400', 'DateTime.in-timezone (adding hours)';
347 $dt = with-tz(tz('+0000'), -1);
348 is ~$dt, '2005-02-04T14:25:00-0100', 'DateTime.in-timezone (subtracting hours)';
349 $dt = with-tz(tz('-0100'), 0);
350 is ~$dt, '2005-02-04T16:25:00Z', 'DateTime.in-timezone (-0100 to UTC)';
351 $dt = tz('-0100').utc;
352 is ~$dt, '2005-02-04T16:25:00Z', 'DateTime.utc (from -0100)';
353 $dt = with-tz(tz('+0100'), -1);
354 is ~$dt, '2005-02-04T13:25:00-0100', 'DateTime.in-timezone (+ hours to - hours)';
355 $dt = with-tz(tz('-0200'), -5);
356 is ~$dt, '2005-02-04T12:25:00-0500', 'DateTime.in-timezone (decreasing negative hours)';
357 $dt = with-tz(tz('+0000'), 0, -13);
358 is ~$dt, '2005-02-04T15:12:00-0013', 'DateTime.in-timezone (negative minutes)';
359 $dt = with-tz(tz('+0000'), 0, 0, -5);
360 is hms($dt), '15,24,55', 'DateTime.in-timezone (negative seconds)';
361 $dt = with-tz(tz('+0000'), 0, -27);
362 is ~$dt, '2005-02-04T14:58:00-0027', 'DateTime.in-timezone (hour rollover 1)';
363 $dt = with-tz(tz('+0000'), 0, 44);
364 is ~$dt, '2005-02-04T16:09:00+0044', 'DateTime.in-timezone (hour rollover 2)';
365 $dt = with-tz(tz('+0311'), -2, -27);
366 is ~$dt, '2005-02-04T09:47:00-0227', 'DateTime.in-timezone (hours and minutes)';
367 $dt = with-tz(tz('+0311'), -2, -27, -19);
368 is hms($dt), '9,46,41', 'DateTime.in-timezone (hours, minutes, and seconds)';
369 $dt = with-tz(tz('+0000'), -18, -55);
370 is ~$dt, '2005-02-03T20:30:00-1855', 'DateTime.in-timezone (one-day rollover)';
371 $dt = with-tz(tz('-1611'), 16, 55);
372 is ~$dt, '2005-02-06T00:31:00+1655', 'DateTime.in-timezone (two-day rollover)';
373 $dt = with-tz(ds('2005-01-01T02:22:00+0300'), 0, 35);
374 is ~$dt, '2004-12-31T23:57:00+0035', 'DateTime.in-timezone (year rollover)';
375
376 $dt = with-tz(dt(second => 15.5), 0, 0, 5);
377 is $dt.second, 20.5, 'DateTime.in-timezone (fractional seconds)';
378
379 $dt = dt(year => 2005, month => 1, day => 3,
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
380 hour => 2, minute => 22, second => 4,
d9c99354 » tadzik
2011-09-18 DateTime.in-timezone doesn't take named parameters, use positionals
381 timezone => 13).in-timezone(-529402);
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
382 # A difference from UTC of 6 days, 3 hours, 3 minutes, and
383 # 22 seconds.
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
384 is show-dt($dt), '29 18 23 27 12 2004 1', 'DateTime.in-timezone (big rollover)';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
385
386 # DateTime doesn't implement DST, but it ought to make
387 # implementing DST possible. We test that here.
388
389 sub nyc-tz($dt, $to-utc) { # America/New_York
390 3600 * (us2007dst($dt, $to-utc ?? 2 !! 7) ?? -4 !! -5)
391 }
392
393 sub lax-tz($dt, $to-utc) { # America/Los_Angeles
394 3600 * (us2007dst($dt, $to-utc ?? 2 !! 10) ?? -7 !! -8)
395 }
396
397 sub us2007dst($dt, $critical-hour) {
592eef19 » Kodi Arfer
2010-10-16 [DateTime.t] Golfed &us2007dst using hyperspaceships.
398 my $t = ($dt.month, $dt.day, $dt.hour);
399 ([or] (3, 11, $critical-hour) »<=>« $t) == 0|-1
400 and ([or] $t »<=>« (11, 4, $critical-hour)) == -1
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
401 }
402
403 sub nyc-dt($year, $month, $day, $hour, $minute) {
404 dt :$year, :$month, :$day, :$hour, :$minute,
405 timezone => &nyc-tz
406 }
407
39241a21 » masak
2010-07-22 [t/spec] updated Date.t, calendar.t and DateTime.t to follow spec
408 $dt = ds('2007-01-02T02:22:00Z').in-timezone(&nyc-tz);
409 is ~$dt, '2007-01-01T21:22:00-0500', 'DateTime.in-timezone (UTC to NYC, outside of DST)';
410 $dt = ds('2007-08-01T02:22:00Z').in-timezone(&nyc-tz);
411 is ~$dt, '2007-07-31T22:22:00-0400', 'DateTime.in-timezone (UTC to NYC, during DST)';
412 $dt = ds('2007-03-11T06:55:00Z').in-timezone(&nyc-tz);
413 is ~$dt, '2007-03-11T01:55:00-0500', 'DateTime.in-timezone (UTC to NYC, just before DST)';
414 $dt = ds('2007-03-11T07:02:00Z').in-timezone(&nyc-tz);
415 is ~$dt, '2007-03-11T03:02:00-0400', 'DateTime.in-timezone (UTC to NYC, just after DST)';
416 $dt = ds('2007-03-11T09:58:00+0303').in-timezone(&nyc-tz);
417 is ~$dt, '2007-03-11T01:55:00-0500', 'DateTime.in-timezone (+0303 to NYC, just before DST)';
418 $dt = ds('2007-03-10T14:50:00-1612').in-timezone(&nyc-tz);
419 is ~$dt, '2007-03-11T03:02:00-0400', 'DateTime.in-timezone (-1612 to NYC, just after DST)';
420 $dt = nyc-dt(2007, 1, 1, 21, 22).utc;
421 is ~$dt, '2007-01-02T02:22:00Z', 'DateTime.utc (from NYC, outside of DST)';
422 $dt = nyc-dt(2007, 7, 31, 22, 22).utc;
423 is ~$dt, '2007-08-01T02:22:00Z', 'DateTime.utc (from NYC, during DST)';
424 $dt = nyc-dt(2007, 7, 31, 22, 22).utc;
425 is ~$dt, '2007-08-01T02:22:00Z', 'DateTime.utc (from NYC, during DST)';
426 $dt = nyc-dt(2007, 3, 11, 1, 55).utc;
427 is ~$dt, '2007-03-11T06:55:00Z', 'DateTime.utc (from NYC, just before DST)';
428 $dt = with-tz(nyc-dt(2007, 3, 11, 3, 2), -16, -12);
429 is ~$dt, '2007-03-10T14:50:00-1612', 'DateTime.in-timezone (NYC to -1612, just after DST)';
430 $dt = nyc-dt(2007, 3, 11, 1, 55).in-timezone(&lax-tz);
431 is ~$dt, '2007-03-10T22:55:00-0800', 'DateTime.in-timezone (NYC to LAX, just before NYC DST)';
432 $dt = nyc-dt(2007, 3, 11, 3, 2).in-timezone(&lax-tz);
433 is ~$dt, '2007-03-10T23:02:00-0800', 'DateTime.in-timezone (NYC to LAX, just after NYC DST)';
434 $dt = nyc-dt(2007, 3, 11, 6, 2).in-timezone(&lax-tz);
435 is ~$dt, '2007-03-11T03:02:00-0700', 'DateTime.in-timezone (NYC to LAX, just after LAX DST)';
f03f623b » Kodi
2010-07-11 [t/spec] Overhauled DateTime.t. Rakudo can pass all of these with my …
436 }
ef575e23 » Kodi
2010-07-06 [t/spec/S32-temporal/DateTime] Corrected and extended. Rakudo should …
437
a32217d5 » Kodi Arfer
2010-09-18 [DateTime.t] Added tests for RT #77910.
438 # --------------------------------------------------------------------
439 # Miscellany
440 # --------------------------------------------------------------------
441
442 # RT #77910
443 # Ensure that any method of producing a DateTime keeps attributes
444 # that should be Ints Ints.
445 {
446 isa_ok dt(second => 1/3).year, Int, 'DateTime.new(...).year isa Int';
447 isa_ok dt(second => 1/3).hour, Int, 'DateTime.new(...).hour isa Int';
448 isa_ok dt(hour => 13, second => 1/3).hour, Int, 'DateTime.new(..., hour => 13).hour isa Int';
449 isa_ok dtc(second => 1/3).year, Int, '$dt.clone(...).year isa Int';
450 isa_ok dtc(second => 1/3).hour, Int, '$dt.clone(...).hour isa Int';
451 isa_ok dtc(hour => 13, second => 1/3).hour, Int, '$dt.clone(..., hour => 13).hour isa Int';
452 isa_ok DateTime.new(5).year, Int, 'DateTime.new(Int).year isa Int';
453 isa_ok DateTime.new(5).hour, Int, 'DateTime.new(Int).hour isa Int';
454 isa_ok DateTime.new(now).year, Int, 'DateTime.new(Instant).year isa Int';
455 isa_ok DateTime.new(now).hour, Int, 'DateTime.new(Instant).hour isa Int';
456 isa_ok ds('2005-02-04T15:25:00Z').year, Int, 'ds(Str).year isa Int';
457 isa_ok ds('2005-02-04T15:25:00Z').hour, Int, 'ds(Str).hour isa Int';
458 isa_ok dt.in-timezone(60*60).year, Int, 'dt.in-timezone(Int).year isa Int';
459 isa_ok dt.in-timezone(60*60).hour, Int, 'dt.in-timezone(Int).hour isa Int';
460 isa_ok dt.truncated-to(:week).year, Int, 'dt.truncated-to(:week).year isa Int';
461 isa_ok dt.truncated-to(:week).hour, Int, 'dt.truncated-to(:week).hour isa Int';
462 isa_ok DateTime.now.year, Int, 'DateTime.now.year isa Int';
463 isa_ok DateTime.now.hour, Int, 'DateTime.now.hour isa Int';
464 }
465
e76dd4c7 » moritz
2010-12-31 s/done_testing/done/ as per recent S24 changes
466 done;
Something went wrong with that request. Please try again.