DateTimeX::TO_JSON - Adds a TO_JSON method to DateTime
version 0.0.1
use DateTime; use JSON; use DateTimeX::TO_JSON formatter => 'DateTime::Format::RFC3339'; my $dt = DateTime->now; my $out = JSON->new->convert_blessed(1)->encode([$dt]);
Adds a TO_JSON method to DateTime so that JSON and other JSON serializers can serialize it when it encounters it a data structure.
Can be given an optional DateTime formatter on import such as DateTime::Format::RFC3339. Any formatter that supports new and format_datetime will work. Defaults to turning DateTime into a string by calling "datetime" in DateTime
If you want to format the date in your own way, then just define the following function in your code instead of using this module:
sub DateTime::TO_JSON { my $dt = shift; # do something with $dt, such as: return $dt->ymd; }
DateTimeX::TO_JSON
Steven Humphrey <shumphrey@cpan.org>
This software is copyright (c) 2014 by Steven Humphrey.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install DateTimeX::TO_JSON, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DateTimeX::TO_JSON
CPAN shell
perl -MCPAN -e shell install DateTimeX::TO_JSON
For more information on module installation, please visit the detailed CPAN module installation guide.