Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Temporal goodness.
  • Loading branch information
Kodi Arfer authored and Carl Masak committed Jul 21, 2010
1 parent ac0987c commit c412170
Show file tree
Hide file tree
Showing 7 changed files with 472 additions and 422 deletions.
4 changes: 4 additions & 0 deletions CREDITS
Expand Up @@ -227,6 +227,10 @@ N: Klaas-Jan Stol
U: kjs
E: parrotcode@gmail.com

N: Kodi Arfer
U: Kodi
W: http://arfer.net

N: Kyle Hasselbacher
E: kyleha@gmail.com
U: KyleHa
Expand Down
3 changes: 1 addition & 2 deletions build/Makefile.in
Expand Up @@ -224,8 +224,7 @@ CORE_SOURCES = \
src/core/Substitution.pm \
src/core/system.pm \
src/cheats/process.pm \
src/core/Date.pm \
src/core/DateTime.pm \
src/core/Temporal.pm \
src/core/Match.pm \
src/core/Attribute.pm \
src/core/CallFrame.pm \
Expand Down
41 changes: 31 additions & 10 deletions lib/DateTime/strftime.pm
@@ -1,6 +1,8 @@
use v6;
# A strftime() subroutine.

module DateTime::strftime {

multi sub strftime( Str $format is copy, DateTime $dt ) is export(:DEFAULT) {
my %substitutions =
# Standard substitutions for yyyy mm dd hh mm ss output.
Expand All @@ -9,12 +11,12 @@ module DateTime::strftime {
'd' => { $dt.day.fmt( '%02d') },
'H' => { $dt.hour.fmt( '%02d') },
'M' => { $dt.minute.fmt('%02d') },
'S' => { $dt.second.fmt('%02d') },
'S' => { $dt.whole-second.fmt('%02d') },
# Special substitutions (Posix-only subset of DateTime or libc)
'a' => { $dt.day-name.substr(0,3) },
'A' => { $dt.day-name },
'b' => { $dt.month-name.substr(0,3) },
'B' => { $dt.month-name },
'a' => { day-name($dt.day-of-week).substr(0,3) },
'A' => { day-name($dt.day-of-week) },
'b' => { month-name($dt.month).substr(0,3) },
'B' => { month-name($dt.month) },
'C' => { ($dt.year/100).fmt('%02d') },
'e' => { $dt.day.fmt('%2d') },
'F' => { $dt.year.fmt('%04d') ~ '-' ~ $dt.month.fmt(
Expand All @@ -27,22 +29,29 @@ module DateTime::strftime {
'p' => { ($dt.hour < 12) ?? 'am' !! 'pm' },
'P' => { ($dt.hour < 12) ?? 'AM' !! 'PM' },
'r' => { (($dt.hour+23)%12+1).fmt('%02d') ~ ':' ~
$dt.minute.fmt('%02d') ~ ':' ~ $dt.second.fmt('%02d')
$dt.minute.fmt('%02d') ~ ':' ~ $dt.whole-second.fmt('%02d')
~ (($.hour < 12) ?? 'am' !! 'pm') },
'R' => { $dt.hour.fmt('%02d') ~ ':' ~ $dt.minute.fmt('%02d') },
's' => { $dt.to-epoch.fmt('%d') },
's' => { $dt.posix.fmt('%d') },
't' => { "\t" },
'T' => { $dt.hour.fmt('%02d') ~ ':' ~ $dt.minute.fmt('%02d') ~ ':' ~ $dt.second.fmt('%02d') },
'T' => { $dt.hour.fmt('%02d') ~ ':' ~ $dt.minute.fmt('%02d') ~ ':' ~ $dt.whole-second.fmt('%02d') },
'u' => { ~ $dt.day-of-week.fmt('%d') },
'w' => { ~ (($dt.day-of-week+6) % 7).fmt('%d') },
'x' => { $dt.year.fmt('%04d') ~ '-' ~ $dt.month.fmt('%02d') ~ '-' ~ $dt.day.fmt('%2d') },
'X' => { $dt.hour.fmt('%02d') ~ ':' ~ $dt.minute.fmt('%02d') ~ ':' ~ $dt.second.fmt('%02d') },
'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') },
'z' => { $dt.timezone }
'z' => { $dt.timezone ~~ Callable and die "stftime: Can't use 'z' with Callable time zones.";
my $o = $dt.timezone;
$o
?? sprintf '%s%02d%02d',
$o < 0 ?? '-' !! '+',
($o.abs / 60 / 60).floor,
($o.abs / 60 % 60).floor
!! 'Z' }
;
my $result = '';
while $format ~~ / ^ (<-['%']>*) '%' (.)(.*) $ / {
Expand All @@ -59,5 +68,17 @@ module DateTime::strftime {
# // die "Unknown format letter '\%$0'").() }, :global );
return $result ~ $format;
}

sub day-name($i) {
# ISO 8601 says Monday is the first day of the week.
<Monday Tuesday Wednesday Thursday
Friday Saturday Sunday>[$i - 1]
}

sub month-name($i) {
<January February March April May June July August
September October November December>[$i - 1]
}

}

161 changes: 0 additions & 161 deletions src/core/Date.pm

This file was deleted.

0 comments on commit c412170

Please sign in to comment.