NAME
Net::API::REST::DateTime - HTTP DateTime Manipulation and Formatting
SYNOPSIS
use Net::API::REST::DateTime;
my $d = Net::API::REST::DateTime->new( debug => 3 );
my $dt = DateTime->now;
$dt->set_formatter( $d );
print( "$dt\n" );
## will produce
Sun, 15 Dec 2019 15:32:12 GMT
my( @parts ) = $d->parse_date( $date_string );
my $datetime_object = $d->str2datetime( $date_string );
$datetime_object->set_formatter( $d );
my $timestamp_in_seconds = $d->str2time( $date_string );
my $datetime_object = $d->time2datetime( $timestamp_in_seconds );
my $datetime_string = $d->time2str( $timestamp_in_seconds );
VERSION
v1.0.0
DESCRIPTION
This module contains methods to create and manipulate datetime representation from and to DateTime
object or unix timestamps.
When using it as a formatter to a DateTime
object, this will make sure it is properly formatted for its use in http headers and cookies.
As of version <v1.0.0> it completely inherits from Apache2::API::DateTime
METHODS
new( hash )
This initiates the package and take the following parameters:
- debug
-
Optional. If set with a positive integer, this will activate verbose debugging message
format_datetime( $date_time_object )
Provided a DateTime
object, this returns a http compliant string representation, such as:
Sun, 15 Dec 2019 15:32:12 GMT
that can be used in http headers and cookies' expires property as per rfc6265.
parse_date( string )
Given a datetime string, this returns, in list context, a list of day, month, year, hour, minute, second and time zone or an iso 8601 datetime string in scalar context.
This is used by the method str2datetime
str2datetime( string )
Given a string that looks like a date, this will parse it and return a DateTime
object.
str2time( string )
Given a string that looks like a date, this returns its representation as a unix timestamp in second since epoch.
In the background, it calls str2datetime for parsing.
time2datetime( timestamp in seconds )
Given a unix timestamp in seconds since epoch, this returns a DateTime
object.
time2str( timestamp in seconds )
Given a unix timestamp in seconds since epoch, this returns a string representation of the timestamp suitable for http headers and cookies. The format is like Sat, 14 Dec 2019 22:12:30 GMT
AUTHOR
Jacques Deguest <jack@deguest.jp>
CPAN ID: jdeguest
https://gitlab.com/jackdeguest/Net-API-REST
SEE ALSO
DateTime
COPYRIGHT & LICENSE
Copyright (c) 2018-2019 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.