Skip to content
Permalink
Browse files

Make sure $!daycount is nulled on subclasses of Date

The problem was that subclasses of Date do not use the fast-path creation of
objects, but go through .bless.  This missed an important part of the
initialization of $!daycount.  Fixes R#2615
  • Loading branch information...
lizmat committed Jan 18, 2019
1 parent 8e00261 commit 929561642281da874c86cfe82a32a2c1407f6a29
Showing with 11 additions and 9 deletions.
  1. +11 −9 src/core/Date.pm6
@@ -30,6 +30,10 @@ my class Date does Dateish {
nqp::isconcrete($daycount) ?? $daycount !! nqp::null);
self
}
method !SET-DAYCOUNT() {
nqp::bind($!daycount,nqp::null) unless nqp::isconcrete($!daycount);
self
}

proto method new(|) {*}
multi method new(Date:
@@ -45,7 +49,7 @@ my class Date does Dateish {
).throw;
nqp::eqaddr(self.WHAT,Date)
?? nqp::create(self)!SET-SELF($year,$month,$day,&formatter)
!! self.bless(:$year,:$month,:$day,:&formatter,|%_)
!! self.bless(:$year,:$month,:$day,:&formatter,|%_)!SET-DAYCOUNT
}
multi method new(Date:
Int:D() :$year!, Int:D() :$month = 1, Int:D() :$day = 1, :&formatter, *%_
@@ -60,7 +64,7 @@ my class Date does Dateish {
).throw;
nqp::eqaddr(self.WHAT,Date)
?? nqp::create(self)!SET-SELF($year,$month,$day,&formatter)
!! self.bless(:$year,:$month,:$day,:&formatter,|%_)
!! self.bless(:$year,:$month,:$day,:&formatter,|%_)!SET-DAYCOUNT
}
multi method new(Date: Str $date, :&formatter, *%_ --> Date:D) {
X::Temporal::InvalidFormat.new(
@@ -80,12 +84,8 @@ my class Date does Dateish {
nqp::eqaddr(self.WHAT,Date)
?? nqp::create(self)!SET-SELF($d.year,$d.month,$d.day,&formatter)
!! self.bless(
:year($d.year),
:month($d.month),
:day($d.day),
:&formatter,
|%_
)
:year($d.year),:month($d.month),:day($d.day),:&formatter, |%_
)!SET-DAYCOUNT
}
multi method new(Date: Instant $i, :&formatter, *%_ --> Date:D) {
self.new(DateTime.new($i),:&formatter,|%_)
@@ -94,7 +94,9 @@ my class Date does Dateish {
self!ymd-from-daycount($daycount, my $year, my $month, my $day);
nqp::eqaddr(self.WHAT,Date)
?? nqp::create(self)!SET-SELF($year,$month,$day,&formatter,$daycount)
!! self.bless(:$year,:$month,:$day,:&formatter,:$daycount)
!! self.bless(
:$year,:$month,:$day,:&formatter,:$daycount
)!SET-DAYCOUNT
}

method today(:&formatter --> Date:D) { self.new(DateTime.now, :&formatter) }

0 comments on commit 9295616

Please sign in to comment.
You can’t perform that action at this time.