DateTimeX::Auto

Use DateTime without needing to call constructors
Download

DateTimeX::Auto Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Toby Inkster
  • Publisher web site:
  • http://search.cpan.org/~tobyink/

DateTimeX::Auto Tags


DateTimeX::Auto Description

DateTime is awesome, but constructing DateTime objects can be annoying. You often need to use one of the formatter modules, or call DateTime->new() with a bunch of values. If you've got a bunch of constant dates in your code, then the DateTimeX::Auto Perl module makes all this a bit simpler.It uses overload to overload the q() operator, automatically turning all string constants that match particular regular expressions into DateTime objects. It also overloads stringification to make sure that DateTime objects get stringified back to exactly the format they were given in.The date formats supported are: yyyy-mm-dd yyyy-mm-ddZ yyyy-mm-ddThh:mm:ss yyyy-mm-ddThh:mm:ssZThe optional trailing 'Z' puts the datetime into the UTC timezone. Otherwise the datetime will be in DateTime's default (floating) timezone.Fractional seconds are also supported, to an arbitrary number of decimal places. However, as DateTime only supports nanosecond precision, any digits after the ninth will be zeroed out. my $dt ='1234-12-12T12:34:56.123456789123456789'; print "$dt\n"; # 1234-12-12T12:34:56.123456789000000000Objects are blessed into the DateTimeX::Auto class which inherits from DateTime. They use UNIVERSAL::ref to masquerade as plain DateTime objects. print ref('2000-01-01')."\n"; # DateTimeSYNOPSIS use DateTimeX::Auto ':auto'; my $ga_start = '2000-04-06'; $ga_start->add(years => 10); printf("%s %s\n", $ga_start, ref $ga_start); # 2010-04-06 DateTime { no DateTimeX::Auto; my $string = '2000-04-06'; printf( "%s\n", ref($string)?'Ref':'NoRef' ); # NoRef }Product's homepage


DateTimeX::Auto Related Software