Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 550 lines (485 sloc) 18.166 kb
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
1 use v6;
2 my class DateTime { ...}
3 my class Date { ...}
4
5 my role Dateish {
6 method is-leap-year($y = $.year) {
7 $y %% 4 and not $y %% 100 or $y %% 400
8 }
9
10 method days-in-month($year = $.year, $month = $.month) {
11 $month == 2 ?? self.is-leap-year($year) ?? 29 !! 28
12 !! $month == 4|6|9|11 ?? 30
13 !! 31
14 }
15
16 method daycount-from-ymd($y is copy, $m is copy, $d) {
17 # taken from <http://www.merlyn.demon.co.uk/daycount.htm>
18 $y .= Int;
19 $m .= Int;
20 if $m < 3 {
21 $m += 12;
22 --$y;
23 }
24 -678973 + $d + (153 * $m - 2) div 5
25 + 365 * $y + $y div 4
26 - $y div 100 + $y div 400;
27 }
28
29 method ymd-from-daycount($daycount) {
30 # taken from <http://www.merlyn.demon.co.uk/daycount.htm>
5dbca1f Jonathan Worthington Use native types in ymd-from-daycount, shaving ~7% off masak++'s example...
jnthn authored
31 my int $day = $daycount.Int + 678881;
32 my int $t = (4 * ($day + 36525)) div 146097 - 1;
33 my int $year = 100 * $t;
34 $day = $day - (36524 * $t + ($t +> 2));
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
35 $t = (4 * ($day + 366)) div 1461 - 1;
5dbca1f Jonathan Worthington Use native types in ymd-from-daycount, shaving ~7% off masak++'s example...
jnthn authored
36 $year = $year + $t;
37 $day = $day - (365 * $t + ($t +> 2));
38 my int $month = (5 * $day + 2) div 153;
39 $day = $day - ((2 + $month * 153) div 5 - 1);
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
40 if ($month > 9) {
5dbca1f Jonathan Worthington Use native types in ymd-from-daycount, shaving ~7% off masak++'s example...
jnthn authored
41 $month = $month - 12;
42 $year = $year + 1;
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
43 }
44 ($year, $month + 3, $day)
45 }
46
47 method get-daycount {
48 self.daycount-from-ymd($.year, $.month, $.day)
49 }
50
51 method day-of-month() { $.day }
52
53 method day-of-week($daycount = self.get-daycount) {
54 ($daycount + 2) % 7 + 1
55 }
56
57 method week() { # algorithm from Claus Tøndering
a48a985 Tadeusz Sośnierz More Temporal fixes
tadzik authored
58 my $a = $.year - ($.month <= 2).floor.Int;
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
59 my $b = $a div 4 - $a div 100 + $a div 400;
60 my $c = ($a - 1) div 4 - ($a - 1) div 100 + ($a - 1) div 400;
61 my $s = $b - $c;
62 my $e = $.month <= 2 ?? 0 !! $s + 1;
63 my $f = $.day + do $.month <= 2
64 ?? 31*($.month - 1) - 1
65 !! (153*($.month - 3) + 2) div 5 + 58 + $s;
66
67 my $g = ($a + $b) % 7;
68 my $d = ($f + $g - $e) % 7;
69 my $n = $f + 3 - $d;
70
71 $n < 0 ?? ($.year - 1, 53 - ($g - $s) div 5)
72 !! $n > 364 + $s ?? ($.year + 1, 1)
73 !! ($.year, $n div 7 + 1);
74 }
75
76 method week-year() {
77 self.week.[0]
78 }
79
80 method week-number() {
81 self.week.[1]
82 }
83
84 method weekday-of-month {
85 ($.day - 1) div 7 + 1
86 }
87
b952372 Tadeusz Sośnierz Uncomment Date.day-of-year. We now pass S32-temporal/calendar.t; track f...
tadzik authored
88 method day-of-year() {
89 [+] $.day, map { self.days-in-month($.year, $^m) }, 1 ..^ $.month
90 }
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
91
6fde31d Moritz Lenz two tiny Date fixes
moritz authored
92 method check-value($val is copy, $name, $range, :$allow-nonint) {
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
93 $val = $allow-nonint ?? +$val !! $val.Int;
12b860d Jonathan Worthington A doubled 'or' caught by work in the optimizer branch.
jnthn authored
94 $val ~~ $range
4b4f5ef Moritz Lenz throw X::OutOfRange exception from Date and DateTime constructors
moritz authored
95 or die X::OutOfRange.new(
96 what => $name,
97 got => $val,
c295b53 Moritz Lenz include actual Range object in X::OutOfRange error from Date.new
moritz authored
98 range => $range,
4b4f5ef Moritz Lenz throw X::OutOfRange exception from Date and DateTime constructors
moritz authored
99 );
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
100 }
101
102 method check-date {
103 self.check-value($.month, 'month', 1 .. 12);
104 self.check-value($.day, "day of $.year/$.month",
105 1 .. self.days-in-month);
106 }
107
3515e47 Moritz Lenz fix Dateish.truncate-parts signature; simplify eqv
moritz authored
108 method truncate-parts($unit, %parts? is copy) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
109 # Helper for DateTime.truncated-to and Date.truncated-to.
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
110 if $unit eq 'week' {
111 my $dc = self.get-daycount;
112 my $new-dc = $dc - self.day-of-week($dc) + 1;
113 %parts<year month day> =
114 self.ymd-from-daycount($new-dc);
115 } else { # $unit eq 'month'|'year'
116 %parts<day> = 1;
117 $unit eq 'year' and %parts<month> = 1;
118 }
119 %parts;
120 }
121
122 }
123
124 sub default-formatter(DateTime $dt, Bool :$subseconds) {
125 # ISO 8601 timestamp (well, not strictly ISO 8601 if $subseconds
126 # is true)
127 my $o = $dt.offset;
128 $o %% 60
129 or warn "Default DateTime formatter: offset $o not divisible by 60.\n";
130 sprintf '%04d-%02d-%02dT%02d:%02d:%s%s',
131 $dt.year, $dt.month, $dt.day, $dt.hour, $dt.minute,
132 $subseconds
133 ?? $dt.second.fmt('%09.6f')
134 !! $dt.whole-second.fmt('%02d'),
135 do $o
136 ?? sprintf '%s%02d%02d',
137 $o < 0 ?? '-' !! '+',
138 ($o.abs / 60 / 60).floor,
139 ($o.abs / 60 % 60).floor
140 !! 'Z';
141 }
142
143 my class DateTime-local-timezone does Callable {
144 method Str { '<local time zone>' }
145 method perl { '$*TZ' }
146
147 method postcircumfix:<( )>($args) { self.offset(|$args) }
148
149 method offset(DateTime:D $dt, $to-utc) {
150 # We construct local and UTC DateTimes, calculate POSIX times
151 # (pretending the local DateTime is actually in UTC), and
152 # return the difference. Surprisingly, this actually works!
153 if $to-utc {
154 my Mu $fia := pir::new__PS('FixedIntegerArray');
ab30d74 Moritz Lenz [Temporal] initialize length of FixedIntegerArray
moritz authored
155 pir::set__vPI($fia, 9);
a48a985 Tadeusz Sośnierz More Temporal fixes
tadzik authored
156 nqp::bindpos($fia, 0, nqp::unbox_i($dt.whole-second));
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
157 nqp::bindpos($fia, 1, nqp::unbox_i($dt.minute));
158 nqp::bindpos($fia, 2, nqp::unbox_i($dt.hour));
159 nqp::bindpos($fia, 3, nqp::unbox_i($dt.day));
160 nqp::bindpos($fia, 4, nqp::unbox_i($dt.month));
161 nqp::bindpos($fia, 5, nqp::unbox_i($dt.year));
162 nqp::bindpos($fia, 8, -1);
163 nqp::p6box_i(pir::encodelocaltime__IP($fia)) - $dt.posix(True);
164 } else {
165 my $p = $dt.posix;
166 my ($year, $month, $day, $hour, $minute, $second);
eb855f3 Tadeusz Sośnierz Fix DateTime.now
tadzik authored
167 my Mu $fia := pir::decodelocaltime__PI(nqp::unbox_i($p.Int));
168 $second = nqp::p6box_i(nqp::atpos($fia, 0));
169 $minute = nqp::p6box_i(nqp::atpos($fia, 1));
170 $hour = nqp::p6box_i(nqp::atpos($fia, 2));
171 $day = nqp::p6box_i(nqp::atpos($fia, 3));
172 $month = nqp::p6box_i(nqp::atpos($fia, 4));
173 $year = nqp::p6box_i(nqp::atpos($fia, 5));
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
174 DateTime\
175 .new(:$year, :$month, :$day, :$hour, :$minute, :$second)\
176 .posix - $p;
177 }
178 }
179 }
180
181 my class DateTime does Dateish {
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
182 has Int $.year;
183 has Int $.month = 1;
184 has Int $.day = 1;
185
186 has Int $.hour = 0;
187 has Int $.minute = 0;
188 has $.second = 0.0;
189 has $.timezone = 0; # UTC
190 has &.formatter = &default-formatter;
191 has Int $!saved-offset;
192 # Not an optimization but a necessity to ensure that
193 # $dt.utc.local.utc is equivalent to $dt.utc. Otherwise,
194 # DST-induced ambiguity could ruin our day.
195
196 multi method new(Int :$year!, :&formatter=&default-formatter, *%_) {
197 my $dt = self.bless(*, :$year, :&formatter, |%_);
198 $dt.check-date;
199 $dt.check-time;
200 $dt;
201 }
202
203 method check-time {
204 # Asserts the validity of and numifies $!hour, $!minute, and $!second.
205 self.check-value($!hour, 'hour', 0 ..^ 24);
206 self.check-value($!minute, 'minute', 0 ..^ 60);
207 self.check-value($!second, 'second', 0 ..^ 62, :allow-nonint);
208 if $!second >= 60 {
209 # Ensure this is an actual leap second.
210 self.second < 61
211 or die 'No second 61 has yet been defined';
212 my $dt = self.utc;
213 $dt.hour == 23 && $dt.minute == 59
214 or die 'A leap second can occur only at hour 23 and minute 59 UTC';
215 my $date = sprintf '%04d-%02d-%02d',
216 $dt.year, $dt.month, $dt.day;
217 $date eq any(tai-utc::leap-second-dates)
218 or die "There is no leap second on UTC $date";
219 }
220 }
221
222 multi method new(Date :$date!, *%_) {
223 self.new(year => $date.year, month => $date.month,
224 day => $date.day, |%_)
225 }
226
227 multi method new(Instant $i, :$timezone=0, :&formatter=&default-formatter) {
228 my ($p, $leap-second) = $i.to-posix;
375fa0a Tadeusz Sośnierz Small Temporal tune, fixes Date.new(Instant)
tadzik authored
229 my $dt = self.new: floor($p - $leap-second).Int, :&formatter;
eb855f3 Tadeusz Sośnierz Fix DateTime.now
tadzik authored
230 $dt.clone(second => ($dt.second + $p % 1 + $leap-second)
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
231 ).in-timezone($timezone);
232 }
233
234 multi method new(Int $time is copy, :$timezone=0, :&formatter=&default-formatter) {
235 # Interpret $time as a POSIX time.
236 my $second = $time % 60; $time = $time div 60;
237 my $minute = $time % 60; $time = $time div 60;
238 my $hour = $time % 24; $time = $time div 24;
239 # Day month and leap year arithmetic, based on Gregorian day #.
240 # 2000-01-01 noon UTC == 2451558.0 Julian == 2451545.0 Gregorian
241 $time += 2440588; # because 2000-01-01 == Unix epoch day 10957
242 my $a = $time + 32044; # date algorithm from Claus Tøndering
243 my $b = (4 * $a + 3) div 146097; # 146097 = days in 400 years
244 my $c = $a - (146097 * $b) div 4;
245 my $d = (4 * $c + 3) div 1461; # 1461 = days in 4 years
246 my $e = $c - ($d * 1461) div 4;
247 my $m = (5 * $e + 2) div 153; # 153 = days in Mar-Jul Aug-Dec
248 my $day = $e - (153 * $m + 2) div 5 + 1;
249 my $month = $m + 3 - 12 * ($m div 10);
250 my $year = $b * 100 + $d - 4800 + $m div 10;
251 self.bless(*, :$year, :$month, :$day,
252 :$hour, :$minute, :$second,
253 :&formatter).in-timezone($timezone);
254 }
255
256 multi method new(Str $format, :$timezone is copy = 0, :&formatter=&default-formatter) {
257 $format ~~ /^ (\d**4) '-' (\d\d) '-' (\d\d) T (\d\d) ':' (\d\d) ':' (\d\d) (Z || (<[\-\+]>) (\d\d)(\d\d))? $/
258 or die 'Invalid DateTime string; please an ISO 8601 timestamp';
259 my $year = (+$0).Int;
260 my $month = (+$1).Int;
261 my $day = (+$2).Int;
262 my $hour = (+$3).Int;
263 my $minute = (+$4).Int;
264 my $second = +$5;
265 if $6 {
266 $timezone
267 and die "DateTime.new(Str): :timezone argument not allowed with a timestamp offset";
268 if $6 eq 'Z' {
269 $timezone = 0;
270 } else {
271 $timezone = (($6[0][1]*60 + $6[0][2]) * 60).Int;
272 # RAKUDO: .Int is needed to avoid to avoid the nasty '-0'.
273 $6[0][0] eq '-' and $timezone = -$timezone;
274 }
275 }
276 self.new(:$year, :$month, :$day, :$hour, :$minute,
277 :$second, :$timezone, :&formatter);
278 }
279
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
280 method now(:$timezone=$*TZ, :&formatter=&default-formatter) {
281 self.new(now, :$timezone, :&formatter)
282 }
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
283
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
284 method clone(*%_) {
eb855f3 Tadeusz Sośnierz Fix DateTime.now
tadzik authored
285 my %args = { :$!year, :$!month, :$!day, :$!hour, :$!minute,
286 :$!second, :$!timezone, :&!formatter, %_ };
287 self.new(|%args);
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
288 }
289
290 method clone-without-validating(*%_) { # A premature optimization.
eb855f3 Tadeusz Sośnierz Fix DateTime.now
tadzik authored
291 my %args = { :$!year, :$!month, :$!day, :$!hour, :$!minute,
292 :$!second, :$!timezone, :&!formatter, %_ };
293 self.bless(*, |%args);
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
294 }
295
296 method Instant() {
297 Instant.from-posix: self.posix + $.second % 1, $.second >= 60;
298 }
299
300 method posix($ignore-timezone?) {
301 $ignore-timezone or self.offset == 0
302 or return self.utc.posix;
303 # algorithm from Claus Tøndering
304 my $a = (14 - $.month.Int) div 12;
305 my $y = $.year.Int + 4800 - $a;
306 my $m = $.month.Int + 12 * $a - 3;
307 my $jd = $.day + (153 * $m + 2) div 5 + 365 * $y
308 + $y div 4 - $y div 100 + $y div 400 - 32045;
309 ($jd - 2440588) * 24 * 60 * 60
310 + 60*(60*$.hour + $.minute) + self.whole-second;
311 }
312
313 method offset {
314 $!saved-offset or
315 $!timezone ~~ Callable
316 ?? $!timezone(self, True)
317 !! $!timezone
318 }
319
320 method truncated-to(*%args) {
321 %args.keys == 1
322 or die 'DateTime.truncated-to: exactly one named argument needed';
323 my $unit = %args.keys[0];
324 $unit eq any(<second minute hour day week month year>)
325 or die "DateTime.truncated-to: Unknown truncation unit '$unit'";
326 my %parts;
327 given $unit {
328 %parts<second> = self.whole-second;
329 when 'second' {}
330 %parts<second> = 0;
331 when 'minute' {}
332 %parts<minute> = 0;
333 when 'hour' {}
334 %parts<hour> = 0;
335 when 'day' {}
336 # Fall through to Dateish.
337 %parts = self.truncate-parts($unit, %parts);
338 }
339 self.clone-without-validating(|%parts);
340 }
341
342 method whole-second() {
a48a985 Tadeusz Sośnierz More Temporal fixes
tadzik authored
343 floor($.second).Int
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
344 }
345
346 method in-timezone($timezone) {
347 $timezone eqv $!timezone and return self;
348 my $old-offset = self.offset;
349 my $new-offset = $timezone ~~ Callable
350 ?? $timezone(self.utc, False)
351 !! $timezone;
352 my %parts;
353 # Is the logic for handling leap seconds right?
354 # I don't know, but it passes the tests!
355 my $a = ($!second >= 60 ?? 59 !! $!second)
356 + $new-offset - $old-offset;
eb855f3 Tadeusz Sośnierz Fix DateTime.now
tadzik authored
357 %parts<second> = $!second >= 60 ?? $!second !! ($a % 60).Int;
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
358 my $b = $!minute + floor $a / 60;
eb855f3 Tadeusz Sośnierz Fix DateTime.now
tadzik authored
359 %parts<minute> = ($b % 60).Int;
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
360 my $c = $!hour + floor $b / 60;
eb855f3 Tadeusz Sośnierz Fix DateTime.now
tadzik authored
361 %parts<hour> = ($c % 24).Int;
bb7c108 Jonathan Worthington Uncoment most of class DateTime.
jnthn authored
362 # Let Dateish handle any further rollover.
363 floor $c / 24 and %parts<year month day> =
364 self.ymd-from-daycount\
365 (self.get-daycount + floor $c / 24);
366 self.clone-without-validating:
367 :$timezone, saved-offset => $new-offset, |%parts;
368 }
369
370 method utc() {
371 self.in-timezone(0)
372 }
373 method local() {
374 self.in-timezone($*TZ)
375 }
376
377 method Date() {
378 Date.new(self)
379 }
380
381 method Str() {
382 &!formatter(self)
383 }
384
385 multi method perl(DateTime:D:) {
386 sprintf 'DateTime.new(%s)', join ', ', map { "{.key} => {.value}" }, do
387 :$.year, :$.month, :$.day, :$.hour, :$.minute,
388 second => $.second.perl,
389 (timezone => $.timezone.perl
390 unless $.timezone === 0),
391 (:$!saved-offset
392 if $!saved-offset and $.timezone ~~ Callable),
393 (formatter => $.formatter.perl
394 unless &.formatter eqv &default-formatter)
395 }
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
396 }
397
398 my class Date does Dateish {
399 has Int $.year;
400 has Int $.month = 1;
401 has Int $.day = 1;
402
403 has Int $.daycount;
404
405 method !set-daycount($dc) { $!daycount = $dc }
406
407 method get-daycount { $!daycount }
408
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
409 multi method new(:$year!, :$month, :$day) {
410 my $d = self.bless(*, :$year, :$month, :$day);
411 $d.check-date;
412 $d!set-daycount(self.daycount-from-ymd($year,$month,$day));
413 $d;
414 }
415
416 multi method new($year, $month, $day) {
417 self.new(:$year, :$month, :$day);
418 }
419
375fa0a Tadeusz Sośnierz Small Temporal tune, fixes Date.new(Instant)
tadzik authored
420 multi method new(Str $date) {
421 $date ~~ /^ \d\d\d\d '-' \d\d '-' \d\d $/
422 or die 'Invalid Date string; please use the format "yyyy-mm-dd"';
423 self.new(|$date.split('-').map({.Int}));
424 }
425
b8fdbea Moritz Lenz Date.new should not die with LTA error
moritz authored
426 multi method new() {
427 my $n = self.today;
428 if $n.month == 12 && $n.day >= 24 {
429 Date.new($n.year + 1, 12, 24);
430 } else {
431 Date.new($n.year, 12, 24);
432 }
433 }
434
375fa0a Tadeusz Sośnierz Small Temporal tune, fixes Date.new(Instant)
tadzik authored
435 multi method new(DateTime $dt) {
436 self.bless(*,
437 :year($dt.year), :month($dt.month), :day($dt.day),
438 :daycount(self.daycount-from-ymd($dt.year,$dt.month,$dt.day))
439 );
440 }
441
6f8846b Moritz Lenz custom Date.WHICH
moritz authored
442 multi method WHICH(Date:D:) {
443 nqp::box_s(
444 nqp::concat_s(
445 nqp::concat_s(nqp::unbox_s(self.^name), '|'),
446 nqp::unbox_i($!daycount)
447 ),
448 ObjAt
449 );
450 }
451
375fa0a Tadeusz Sośnierz Small Temporal tune, fixes Date.new(Instant)
tadzik authored
452 method new-from-daycount($daycount) {
453 my ($year, $month, $day) = self.ymd-from-daycount($daycount);
454 self.bless(*, :$daycount, :$year, :$month, :$day);
455 }
456
457 method today() {
458 self.new(DateTime.now);
459 }
460
461 method truncated-to(*%args) {
462 %args.keys == 1
463 or die "Date.truncated-to: exactly one named argument needed.";
464 my $unit = %args.keys[0];
465 $unit eq any(<week month year>)
466 or die "DateTime.truncated-to: Unknown truncation unit '$unit'";
467 self.clone(|self.truncate-parts($unit));
468 }
469
470 method clone(*%_) {
048cfd5 Tadeusz Sośnierz Fix Date.clone. We now pass S32-temporal/Date.t
tadzik authored
471 my %args = { :$!year, :$!month, :$!day, %_ };
472 self.new(|%args);
375fa0a Tadeusz Sośnierz Small Temporal tune, fixes Date.new(Instant)
tadzik authored
473 }
474
475 method succ() {
476 Date.new-from-daycount($!daycount + 1);
477 }
478 method pred() {
479 Date.new-from-daycount($!daycount - 1);
480 }
481
fa821c1 Moritz Lenz Date.gist should be the same as Date.Str
moritz authored
482 multi method gist(Date:D:) {
483 sprintf '%04d-%02d-%02d', $.year, $.month, $.day;
484 }
485
375fa0a Tadeusz Sośnierz Small Temporal tune, fixes Date.new(Instant)
tadzik authored
486 multi method Str(Date:D:) {
487 sprintf '%04d-%02d-%02d', $.year, $.month, $.day;
488 }
489
490 multi method perl(Date:D:) {
491 "Date.new($.year.perl(), $.month.perl(), $.day.perl())";
492 }
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
493 }
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
494
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
495 multi infix:<+>(Date:D $d, Int:D $x) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
496 Date.new-from-daycount($d.daycount + $x)
497 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
498 multi infix:<+>(Int:D $x, Date:D $d) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
499 Date.new-from-daycount($d.daycount + $x)
500 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
501 multi infix:<->(Date:D $d, Int:D $x) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
502 Date.new-from-daycount($d.daycount - $x)
503 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
504 multi infix:<->(Date:D $a, Date:D $b) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
505 $a.daycount - $b.daycount;
506 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
507 multi infix:<cmp>(Date:D $a, Date:D $b) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
508 $a.daycount cmp $b.daycount
509 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
510 multi infix:«<=>»(Date:D $a, Date:D $b) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
511 $a.daycount <=> $b.daycount
512 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
513 multi infix:<==>(Date:D $a, Date:D $b) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
514 $a.daycount == $b.daycount
515 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
516 multi infix:«<=»(Date:D $a, Date:D $b) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
517 $a.daycount <= $b.daycount
518 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
519 multi infix:«<»(Date:D $a, Date:D $b) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
520 $a.daycount < $b.daycount
521 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
522 multi infix:«>=»(Date:D $a, Date:D $b) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
523 $a.daycount >= $b.daycount
524 }
bbe78ec Jonathan Worthington Remove a bunch of 'is export's that shouldn't have been there. Not sure ...
jnthn authored
525 multi infix:«>»(Date:D $a, Date:D $b) {
118be55 Jonathan Worthington Uncomment rest of temporal stuff. Removed 'multi' in a couple of places ...
jnthn authored
526 $a.daycount > $b.daycount
527 }
528
eb855f3 Tadeusz Sośnierz Fix DateTime.now
tadzik authored
529 $PROCESS::TZ = DateTime-local-timezone.new;
530
9ca7ef7 Moritz Lenz partially put back Temporal
moritz authored
531 # =begin pod
532 #
533 # =head1 SEE ALSO
534 # Perl 6 spec <S32-Temporal|http://perlcabal.org/syn/S32/Temporal.html>.
535 # The Perl 5 DateTime Project home page L<http://datetime.perl.org>.
536 # Perl 5 perldoc L<doc:DateTime> and L<doc:Time::Local>.
537 #
538 # The best yet seen explanation of calendars, by Claus Tøndering
539 # L<Calendar FAQ|http://www.tondering.dk/claus/calendar.html>.
540 # Similar algorithms at L<http://www.hermetic.ch/cal_stud/jdn.htm>
541 # and L<http://www.merlyn.demon.co.uk/daycount.htm>.
542 #
543 # <ISO 8601|http://en.wikipedia.org/wiki/ISO_8601>
544 # <Time zones|http://en.wikipedia.org/wiki/List_of_time_zones>
545 #
546 # As per the recommendation, the strftime() method has bee moved into a
547 # loadable module called DateTime::strftime.
548 #
549 # =end pod
Something went wrong with that request. Please try again.