Time::Piece::Plus - Subclass of Time::Piece with some useful method
use Time::Piece::Plus; my $now = localtime(); my $today = Time::Piece::Plus->today; #As class method my $today = Time::Piece::Plus->today; my $yesterday = Time::Piece::Plus->yesterday; my $tomorrow = Time::Piece::Plus->tomorrow; #As instance method my $time = Time::Piece::Plus->yesterday; my $two_days_ago = $time->yesterday; my $today = $time->tomorrow; #returns hour truncated object $time->truncate(to => 'day'); #parse MySQL DATE my $gm_date = Time::Piece::Plus->parse_mysql_date(str => "2011-11-26", as_localtime => 0); my $local_date = Time::Piece::Plus->parse_mysql_date(str => "2011-11-26", as_localtime => 1); #default is localtime my $local_date = Time::Piece::Plus->parse_mysql_date(str => "2011-11-26"); #parse MySQL DATETIME my $gm_datetime = Time::Piece::Plus->parse_mysql_datetime(str => "2011-11-26 23:28:50", as_localtime => 0); my $local_datetime = Time::Piece::Plus->parse_mysql_datetime(str => "2011-11-26 23:28:50", as_localtime => 1); #default is localtime my $datetime = Time::Piece::Plus->parse_mysql_datetime(str => "2011-11-26 23:28:50"); #calculete my $date = localtime(); $date = $date->add(10); $date = $date->add(Time::Seconds->new(10); $date = $date->add(days => 1, hours => 12); $date = $date + 3600; $date = $date->subtract(10); $date = $date->subtract(Time::Seconds->new(10); $date = $date->subtrace(days => 1, hours => 12); $date = $date - 3600; $time_seconds = $date - Time::Piece::Plus->today;
Time::Piece::Plus is subclass of Time::Piece with some useful method.
If called as a class method returns today. Also, if called as an instance method returns the day. And time is cut.
If called as a class method returns yesterday. Also, if called as an instance method returns the previous day. And time is cut.
If called as a class method returns tomorrow. Also, if called as an instance method returns the next day. And time is cut.
Cut the smaller units than those specified. For example, "day" if you will cut the time you specify. 2011-11-26 02:13:22 -> 2011-11-26 00:00:00 Each unit is a minimum cut.
Parse MySQL DATE string like "YYYY-mm-dd". as_localtime is optional, default is 1.
Parse MySQL DATETIME string like "YYYY-mm-dd HH:MM:SS". as_localtime is optional, default is 1.
Format MySQL DATE string like "YYYY-mm-dd". If you call a class method and returns the format today. Also, if called as an instance method returns the date and format of the instance.
Format MySQL DATE string like "YYYY-mm-dd HH:MM:SS". If you call a class method and returns the format now. Also, if called as an instance method returns the date and format of the instance.
Calculate and return new Time::Piece::Plus or Time::Seconds object using specified argument. If you specify Int, Time::Seconds or Time::Piece(::Plus)?, behavior is same as original Time::Piece. Operator overload is also available.
If you specify Hash(not HashRef), behavior is similar to DateTime's these methods. But, they don't change object itself and returns new object. Available Hash keys are as follows, and Hash values are Int.
Nishibayashi Takuji <takuji {at} senchan.jp>
Time::Piece,Time::Piece::MySQL,DateTime
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Time::Piece::Plus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Time::Piece::Plus
CPAN shell
perl -MCPAN -e shell install Time::Piece::Plus
For more information on module installation, please visit the detailed CPAN module installation guide.