Skip to content

Commit

Permalink
Make timezone *always* a named on DateTime.new
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Dec 30, 2015
1 parent adb1608 commit eca5df7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
23 changes: 10 additions & 13 deletions src/core/DateTime.pm
Expand Up @@ -63,7 +63,7 @@ my class DateTime does Dateish {
Int() $hour,
Int() $minute,
$second,
Int() $timezone,
:$timezone = 0,
:&formatter,
) {
(1..12).in-range($month,'Month');
Expand Down Expand Up @@ -105,7 +105,7 @@ my class DateTime does Dateish {
:$timezone = 0,
:&formatter,
) {
self.new($year,$month,$day,$hour,$minute,$second,$timezone,:&formatter)
self.new($year,$month,$day,$hour,$minute,$second,:$timezone,:&formatter)
}
multi method new(DateTime: Date:D :$date!, *%_) {
self.new(:year($date.year),:month($date.month),:day($date.day),|%_)
Expand Down Expand Up @@ -140,7 +140,7 @@ my class DateTime does Dateish {
);
$timezone ?? $dt.in-timezone($timezone) !! $dt
}
multi method new(Str $datetime, :$timezone, :&formatter) {
multi method new(Str $datetime, :$timezone is copy, :&formatter) {
X::Temporal::InvalidFormat.new(
invalid-str => $datetime,
target => 'DateTime',
Expand All @@ -160,26 +160,23 @@ my class DateTime does Dateish {
(<[Zz]> || (<[\-\+]>) (\d\d) (':'? (\d\d))? )? # timezone
$/;

my int $tz = 0;
if $6 {
X::DateTime::TimezoneClash.new.throw if $timezone;
X::DateTime::TimezoneClash.new.throw with $timezone;
if $6.chars != 1 {
X::OutOfRange.new(
what => "minutes of timezone",
got => +$6[2][0],
range => "0..^60",
).throw if $6[2] && $6[2][0] > 59;

$tz = (($6[1]*60 + ($6[2][0] // 0)) * 60).Int;
$timezone = (($6[1]*60 + ($6[2][0] // 0)) * 60).Int;
# RAKUDO: .Int is needed to avoid to avoid the nasty '-0'.
$tz = -$tz if $6[0] eq '-';
$timezone = -$timezone if $6[0] eq '-';
}
}
elsif $timezone {
$tz = $timezone;
}
$timezone //= 0;

self.new($0,$1,$2,$3,$4,+(~$5.subst(",",".")),$tz,:&formatter)
self.new($0,$1,$2,$3,$4,+(~$5.subst(",",".")),:$timezone,:&formatter)
}

method now(:$timezone=$*TZ, :&formatter) returns DateTime:D {
Expand All @@ -195,7 +192,7 @@ my class DateTime does Dateish {
nqp::existskey($h,'hour') ?? nqp::atkey($h,'hour') !! $!hour,
nqp::existskey($h,'minute') ?? nqp::atkey($h,'minute') !! $!minute,
nqp::existskey($h,'second') ?? nqp::atkey($h,'second') !! $!second,
nqp::existskey($h,'timezone')
timezone => nqp::existskey($h,'timezone')
?? nqp::atkey($h,'timezone') !! $!timezone,
formatter => nqp::existskey($h,'formatter')
?? nqp::atkey($h,'formatter') !! &!formatter,
Expand Down Expand Up @@ -344,7 +341,7 @@ my class DateTime does Dateish {

multi method perl(DateTime:D:) {
self.^name
~ ".new($!year,$!month,$!day,$!hour,$!minute,$!second,$!timezone)"
~ ".new($!year,$!month,$!day,$!hour,$!minute,$!second,{:$!timezone.perl})"
}
}

Expand Down
1 change: 0 additions & 1 deletion src/core/Rakudo/Internals.pm
Expand Up @@ -689,7 +689,6 @@ my class Rakudo::Internals {
nqp::atpos_i($fia,2),
nqp::atpos_i($fia,1),
nqp::atpos_i($fia,0),
0,
).posix(True) - $utc;
}

Expand Down

0 comments on commit eca5df7

Please sign in to comment.