Skip to content

Commit

Permalink
Make DateTime and Date more friendly to subclassing
Browse files Browse the repository at this point in the history
jepeway++
  • Loading branch information
moritz committed Nov 2, 2014
1 parent 930bb08 commit 0a3c954
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/core/Temporal.pm
Expand Up @@ -340,7 +340,7 @@ my class DateTime does Dateish {

given $unit {
when 'second' | 'seconds' {
return DateTime.new(self.Instant + $amount);
return self.new(self.Instant + $amount);
}

when 'minute' | 'minutes' { $minute += $amount; proceed }
Expand Down Expand Up @@ -455,7 +455,7 @@ my class DateTime does Dateish {
}

multi method perl(DateTime:D:) {
sprintf 'DateTime.new(%s)', join ', ', map { "{.key} => {.value}" }, do
sprintf '%s.new(%s)', self.^name, join ', ', map { "{.key} => {.value}" }, do
:$.year, :$.month, :$.day, :$.hour, :$.minute,
second => $.second.perl,
(timezone => $.timezone.perl
Expand Down Expand Up @@ -503,9 +503,9 @@ my class Date does Dateish {
multi method new() {
my $n = self.today;
if $n.month == 12 && $n.day >= 24 {
Date.new($n.year + 1, 12, 24);
self.new($n.year + 1, 12, 24);
} else {
Date.new($n.year, 12, 24);
self.new($n.year, 12, 24);
}
}

Expand Down Expand Up @@ -568,17 +568,17 @@ my class Date does Dateish {
$month += $amount;
$year += floor(($month - 1) / 12);
$month = ($month - 1) % 12 + 1;
$date = Date.new(:$year, :$month, :$!day);
$date = self.new(:$year, :$month, :$!day);
succeed;
}

when 'year' | 'years' {
my $year = $!year + $amount;
$date = Date.new(:$year, :$!month, :$!day);
$date = self.new(:$year, :$!month, :$!day);
succeed;
}

$date = Date.new-from-daycount(self.daycount + $day-delta);
$date = self.new-from-daycount(self.daycount + $day-delta);
}

$date;
Expand All @@ -594,10 +594,10 @@ my class Date does Dateish {
}

method succ() {
Date.new-from-daycount($!daycount + 1);
self.new-from-daycount($!daycount + 1);
}
method pred() {
Date.new-from-daycount($!daycount - 1);
self.new-from-daycount($!daycount - 1);
}

multi method gist(Date:D:) {
Expand All @@ -609,7 +609,7 @@ my class Date does Dateish {
}

multi method perl(Date:D:) {
"Date.new($.year.perl(), $.month.perl(), $.day.perl())";
self.^name ~ ".new($.year.perl(), $.month.perl(), $.day.perl())";
}

multi method ACCEPTS(Date:D: DateTime:D $dt) {
Expand Down

0 comments on commit 0a3c954

Please sign in to comment.