DateTime::Format::GeekTime - parse and format GeekTime
use DateTime::Format::GeekTime; use DateTime; my $dt=DateTime->now(); print DateTime::Format::GeekTime->format_datetime($dt); $dt=DateTime::Format::GeekTime->parse_datetime('0xBA45 on day 0x042'); $dt=DateTime::Format::GeekTime->new(2010) ->parse_datetime('0xBA45 on day 0x042');
This module formats and parses "GeekTime". See http://geektime.org/ for the inspiration.
new
my $dtf=DateTime::Format::GeekTime->new(2010);
The single optional parameter to new is the year to use for parsing. Since GeekTime does not carry this information, we have to supply it externally. If you don't specify it, or if you call parse_datetime as a class method, the current yuor will be used.
parse_datetime
format_datetime
my $string=DateTime::Format::GeekTime->format_datetime($dt);
Returns the full GeekTime string, like 0x0041 on day 0x042 A.
0x0041 on day 0x042 A
Note the character at the end of the string: it's the character corresponding to the Unicode codepoint with the same value as the first word in the string. If the codepoint corresponds to a "high surrogate" or a "low surrogate", the character (and the preceding space) will not be returned.
my $dt=DateTime::Format::GeekTime->parse_datetime('0xb4b1 0x0042');
Parses a GeekTime and returns a DateTime object.
DateTime
The parsing is somewhat lenient: you can omit the 0x, you can express the day as 3 or 4 digits, all space is optional (as is the "on day" in the middle). The character after the day number is ignored, if present.
0x
Since GeekTime divides the day in 65536 intervals, but we usually divide it in 86400 seconds, don't expect all times to round-trip correctly: some loss of precision is to be expected. Note that going from GeekTime to a DateTime object and back to GeekTime is guaranteed to give you the same numbers you started from. Going the other way can lose one second.
Gianni Ceccarelli <dakkar@thenautilus.net>
GeekTime http://geektime.org/ http://twitter.com/geektime
This program is © 2010 Gianni Ceccarelli. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
http://geektime.org/
To install DateTime::Format::GeekTime, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DateTime::Format::GeekTime
CPAN shell
perl -MCPAN -e shell install DateTime::Format::GeekTime
For more information on module installation, please visit the detailed CPAN module installation guide.