NAME
Apache2::API::DateTime - HTTP DateTime Manipulation and Formatting
SYNOPSIS
use Apache2::API::DateTime;
my $d = Apache2::API::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
v0.1.2
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.
METHODS
new
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
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
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"
parse_datetime
Provided with a date string, and this will parse it and return a DateTime object, or sets an error and return undef
or an empty list depending on the context.
str2datetime
Given a string that looks like a date, this will parse it and return a DateTime object.
str2time
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
Given a unix timestamp in seconds since epoch, this returns a DateTime object.
time2str
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>
SEE ALSO
COPYRIGHT & LICENSE
Copyright (c) 2023 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.