| Apache2-WebApp-Plugin-DateTime documentation | Contained in the Apache2-WebApp-Plugin-DateTime distribution. |
Apache2::WebApp::Plugin::DateTime - Plugin providing Date/Time methods
my $obj = $c->plugin('DateTime')->method( ... ); # Apache2::WebApp::Plugin::DateTime->method()
or
$c->plugin('DateTime')->method( ... );
Common methods for dealing with Date/Time.
This package is part of a larger distribution and was NOT intended to be used directly. In order for this plugin to work properly, the following packages must be installed:
Apache2::WebApp Date::Calc Date::Format Date::Manip Params::Validate Time::ParseDate
From source:
$ tar xfz Apache2-WebApp-Plugin-DateTime-0.X.X.tar.gz $ perl MakeFile.PL PREFIX=~/path/to/custom/dir LIB=~/path/to/custom/lib $ make $ make test $ make install
Perl one liner using CPAN.pm:
$ perl -MCPAN -e 'install Apache2::WebApp::Plugin::DateTime'
Use of CPAN.pm in interactive mode:
$ perl -MCPAN -e shell cpan> install Apache2::WebApp::Plugin::DateTime cpan> quit
Just like the manual installation of Perl modules, the user may need root access during this process to insure write permission is allowed within the installation directory.
Return the total days between dates.
my $date1 = 'Sun Oct 18 15:14:48 2009'; # then and
my $date2 = localtime(time); # now
my $delta = $c->plugin('DateTime')->days_between_dates( $date1, $date2 );
Convert seconds-since-epoch to a human readable format.
my $date = $c->plugin('DateTime')->format_time( $unix_time, '%a %b %d %T %Y' );
See Date::Format for character conversion specification.
Apache2::WebApp, Apache2::WebApp::Plugin, Date::Calc, Date::Format, Date::Manip, Params::Validate, Time::ParseDate
Marc S. Brooks, <mbrooks@cpan.org> - http://mbrooks.info
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Apache2-WebApp-Plugin-DateTime documentation | Contained in the Apache2-WebApp-Plugin-DateTime distribution. |
#----------------------------------------------------------------------------+ # # Apache2::WebApp::Plugin::DateTime - Plugin providing Date/Time methods # # DESCRIPTION # Common methods for dealing with Date/Time. # # AUTHOR # Marc S. Brooks <mbrooks@cpan.org> # # This module is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # #----------------------------------------------------------------------------+ package Apache2::WebApp::Plugin::DateTime; use strict; use base 'Apache2::WebApp::Plugin'; use Date::Calc qw( Date_to_Days Delta_Days Today ); use Date::Manip; use Params::Validate qw( :all ); use POSIX qw( strftime ); use Time::ParseDate; our $VERSION = 0.07; #~~~~~~~~~~~~~~~~~~~~~~~~~~[ OBJECT METHODS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# #----------------------------------------------------------------------------+ # days_between_dates( $date1, $date2 ) # # Return the total days between dates. sub days_between_dates { my ( $self, $date1, $date2 ) = validate_pos( @_, { type => OBJECT }, { type => SCALAR }, { type => SCALAR } ); my $epoch1 = parsedate($date1); my $epoch2 = parsedate($date2); my @date_to = split(/\s+/, strftime( '%Y %m %e', localtime($epoch1) ) ); my @date_from = split(/\s+/, strftime( '%Y %m %e', localtime($epoch2) ) ); return Delta_Days( @date_to, @date_from ); } #----------------------------------------------------------------------------+ # format_time( $unix_time, $format ) # # Convert seconds-since-epoch to a human readable format. sub format_time { my ( $self, $unix_time, $format ) = validate_pos( @_, { type => OBJECT }, { type => SCALAR }, { type => SCALAR } ); require Date::Format; # since POSIX imports similiar methods return Date::Format::time2str($format, $unix_time, undef); } #~~~~~~~~~~~~~~~~~~~~~~~~~~[ PRIVATE METHODS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# #----------------------------------------------------------------------------+ # _init(\%params) # # Return a reference of $self to the caller. sub _init { my ( $self, $params ) = @_; return $self; } 1; __END__