Permalink
Browse files

DateTime::Utils works, I'm fixing DateTime::Math.

  • Loading branch information...
1 parent 39871c3 commit 8967e9da2f82cdb70c3fdadc6005b818d3c4c472 @supernovus committed Jan 16, 2012
Showing with 12 additions and 15 deletions.
  1. +7 −0 lib/DateTime/Math.pm6
  2. +5 −15 lib/DateTime/Utils.pm6
View
@@ -73,14 +73,21 @@ sub duration-from-to( Numeric $value, DurationUnits $in, DurationUnits $to)
}
multi infix:<+>(DateTime $dt, Numeric $x) is export {
+ $*ERR.say: "We're in the proper addition routine.";
DateTime.new(($dt.posix + $x).Int, :timezone($dt.timezone), :formatter($dt.formatter))
}
multi infix:<+>(Numeric $x, DateTime $dt) is export {
$dt + $x;
}
+multi infix:<->(DateTime $dt, Int $x) is export {
+ $*ERR.say: "We're in the Int version.";
+ DateTime.new(($dt.posix - $x).Int, :timezone($dt.timezone), :formatter($dt.formatter))
+}
+
multi infix:<->(DateTime $dt, Numeric $x) is export {
+ $*ERR.say: "We're in the proper substraction routine.";
DateTime.new(($dt.posix - $x).Int, :timezone($dt.timezone), :formatter($dt.formatter))
}
View
@@ -40,9 +40,9 @@ module DateTime::Utils {
'X' => { $dt.hour.fmt('%02d') ~ ':' ~ $dt.minute.fmt('%02d') ~ ':' ~ $dt.whole-second.fmt('%02d') },
'y' => { ($dt.year % 100).fmt('%02d') },
'%' => { '%' },
- '3' => { (($dt.second % 1)*1000).fmt('%03d') },
- '6' => { (($dt.second % 1)*1000000).fmt('%06d') },
- '9' => { (($dt.second % 1)*1000000000).fmt('%09d') },
+ '3N' => { (($dt.second % 1)*1000).fmt('%03d') },
+ '6N' => { (($dt.second % 1)*1000000).fmt('%06d') },
+ '9N' => { (($dt.second % 1)*1000000000).fmt('%09d') },
'z' => { $dt.timezone ~~ Callable and die "stftime: Can't use 'z' with Callable time zones.";
my $o = $dt.timezone;
$o
@@ -53,18 +53,8 @@ module DateTime::Utils {
!! 'Z' }
;
my $result = '';
- while $format ~~ / ^ (<-['%']>*) '%' (.)(.*) $ / {
- unless %substitutions.exists(~$1) { die "unknown strftime format: %$1"; }
- $result ~= $0 ~ %substitutions{~$1}();
- $format = ~$2;
- if $1 eq '3'|'6'|'9' {
- if $format.substr(0,1) ne 'N' { die "strftime format %$1 must be followed by N"; }
- $format = $format.substr(1);
- }
- }
- # The subst for masak++'s nicer-strftime branch is NYI
- # $format .= subst( /'%'(\w|'%')/, { (%substitutions{~$0}
- # // die "Unknown format letter '\%$0'").() }, :global );
+ $format .= subst( /'%'(\dN|\w|'%')/, -> $/ { (%substitutions{~$0}
+ // die "Unknown format letter '$0'").() }, :global );
return $result ~ $format;
}

0 comments on commit 8967e9d

Please sign in to comment.