Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't use junctions to determine validity of units
  • Loading branch information
lizmat committed May 22, 2015
1 parent 51e529d commit 2e63ee4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/Temporal.pm
@@ -1,7 +1,7 @@
my class DateTime { ... }
my class Date { ... }

my @UNITS = <second minute hour day week month year> X~ '', 's';
my %UNITS = (<second minute hour day week month year> X~ "","s").map: {$_ => 1};

my role Dateish {
has Int $.year;
Expand Down Expand Up @@ -113,7 +113,7 @@ my role Dateish {
method truncate-parts(Cool:D $unit, %parts? is copy) {
# Helper for DateTime.truncated-to and Date.truncated-to.
X::DateTime::InvalidDeltaUnit.new(:$unit).throw
unless $unit eq any(@UNITS);
unless %UNITS.EXISTS-KEY($unit);
if $unit eq 'week' | 'weeks' {
my $dc = self.get-daycount;
my $new-dc = $dc - self.day-of-week($dc) + 1;
Expand Down Expand Up @@ -333,7 +333,7 @@ my class DateTime does Dateish {
my ($unit, $amount) = %unit.kv;

X::DateTime::InvalidDeltaUnit.new(:$unit).throw
unless $unit eq any(@UNITS);
unless %UNITS.EXISTS-KEY($unit);

my ($hour, $minute) = $!hour, $!minute;
my $date;
Expand Down Expand Up @@ -547,7 +547,7 @@ my class Date does Dateish {
my ($unit, $amount) = %unit.kv;

X::DateTime::InvalidDeltaUnit.new(:$unit).throw
unless $unit eq any(@UNITS);
unless %UNITS.EXISTS-KEY($unit);

my $date;

Expand Down

0 comments on commit 2e63ee4

Please sign in to comment.