Gianni Ceccarelli

NAME

DateTime::Format::GeekTime - parse and format GeekTime

SYNOPSIS

  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');

DESCRIPTION

This module formats and parses "GeekTime". See http://geektime.org/ for the inspiration.

METHODS

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.

format_datetime
  my $string=DateTime::Format::GeekTime->format_datetime($dt);

Returns the full GeekTime string, like 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.

parse_datetime
  my $dt=DateTime::Format::GeekTime->parse_datetime('0xb4b1 0x0042');

Parses a GeekTime and returns a DateTime object.

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.

NOTES

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.

AUTHOR

Gianni Ceccarelli <dakkar@thenautilus.net>

GeekTime http://geektime.org/ http://twitter.com/geektime

COPYRIGHT and LICENSE

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.

SEE ALSO

http://geektime.org/

DateTime