From c96d19fca5094995d02911dd293e10e716ed7ce3 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 8 Mar 2010 16:57:13 +0000 Subject: first idea --- Makefile.PL | 8 ++++++++ lib/DateTime/Format/GeekTime.pm | 32 ++++++++++++++++++++++++++++++++ t/format.t | 8 ++++++++ 3 files changed, 48 insertions(+) create mode 100644 Makefile.PL create mode 100644 lib/DateTime/Format/GeekTime.pm create mode 100644 t/format.t diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..722d778 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,8 @@ +use inc::Module::Install; + +name 'DateTime-Format-GeekTime'; +all_from 'lib/DateTime/Format/GeekTime.pm'; + +requires 'DateTime' => 0; + +WriteAll; diff --git a/lib/DateTime/Format/GeekTime.pm b/lib/DateTime/Format/GeekTime.pm new file mode 100644 index 0000000..534e86a --- /dev/null +++ b/lib/DateTime/Format/GeekTime.pm @@ -0,0 +1,32 @@ +package DateTime::Format::GeekTime; +use strict; +use warnings; +use DateTime; +use vars '$VERSION'; + +$VERSION='1.000_001'; +$VERSION=eval $VERSION; + +sub parse_datetime { + my ($self,$string)=@_; +} + +sub format_datetime { + my ($self,$dt)=@_; + + my $start_of_day=$dt->clone->truncate(to=>'day')->set_time_zone('UTC'); + my $start_of_year=$dt->clone->truncate(to=>'year')->set_time_zone('UTC'); + + my $seconds=$dt->subtract_datetime_absolute($start_of_day)->in_units('seconds'); + my $days=$dt->subtract_datetime_absolute($start_of_year)->in_units('days'); + + $seconds*=(65_536/86_400); + + my $chr=eval { chr($seconds) }; + if (!defined $chr) {$chr=''} + else {$chr=" $chr"}; + + return sprintf '0x%04X 0x%04X%s',$seconds,$days,chr($seconds); +} + +1; diff --git a/t/format.t b/t/format.t new file mode 100644 index 0000000..b94c327 --- /dev/null +++ b/t/format.t @@ -0,0 +1,8 @@ +#!perl +use Test::More; +use DateTime; +use DateTime::Format::GeekTime; + +my $dt=DateTime->new(year=>2010,month=>3,day=>8, + hour=>16,minute=>56,seconds=>23); +diag DateTime::Format::GeekTime->format_datetime($dt); -- cgit v1.2.3