Skip to content

Commit

Permalink
Time zone changes now preserve fractional seconds
Browse files Browse the repository at this point in the history
Also get rid of some supersticious use of float() and .Int, use int div.
Now 3% faster DateTime.now() ... still kinda slow.
  • Loading branch information
Brent Laabs committed Jul 7, 2015
1 parent 6e425fd commit da530e3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/core/Temporal.pm
Expand Up @@ -414,7 +414,7 @@ my class DateTime does Dateish {
}

method whole-second() {
floor($!second).Int
$!second.Int
}

method in-timezone($timezone) {
Expand All @@ -426,15 +426,17 @@ my class DateTime does Dateish {
# I don't know, but it passes the tests!
my $a = ($!second >= 60 ?? 59 !! $!second)
+ $new-offset - $old-offset;
%parts<second> = $!second >= 60 ?? $!second !! ($a % 60).Int;
my $b = $!minute + floor $a / 60;
%parts<minute> = ($b % 60).Int;
my $c = $!hour + floor $b / 60;
%parts<hour> = ($c % 24).Int;
%parts<second> = $!second >= 60 ?? $!second !! $a % 60;
my Int $b = $!minute + floor($a) div 60;
%parts<minute> = $b % 60;
my Int $c = $!hour + $b div 60;
%parts<hour> = $c % 24;

# Let Dateish handle any further rollover.
floor $c / 24 and %parts<year month day> =
self.ymd-from-daycount\
(self.get-daycount + floor $c / 24);
if ($c div 24) {
%parts<year month day> =
self.ymd-from-daycount(self.get-daycount + $c div 24);
}
self.clone-without-validating:
:$timezone, |%parts;
}
Expand Down

0 comments on commit da530e3

Please sign in to comment.