summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2010-03-08 16:57:13 +0000
committerdakkar <dakkar@thenautilus.net>2010-03-08 16:57:13 +0000
commitc96d19fca5094995d02911dd293e10e716ed7ce3 (patch)
treee52f6cd712e75ebfc360ae72b504073177c14c82
downloadDateTime-Format-GeekTime-c96d19fca5094995d02911dd293e10e716ed7ce3.tar.gz
DateTime-Format-GeekTime-c96d19fca5094995d02911dd293e10e716ed7ce3.tar.bz2
DateTime-Format-GeekTime-c96d19fca5094995d02911dd293e10e716ed7ce3.zip
first idea
-rw-r--r--Makefile.PL8
-rw-r--r--lib/DateTime/Format/GeekTime.pm32
-rw-r--r--t/format.t8
3 files changed, 48 insertions, 0 deletions
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);