ASNMTAP
view release on metacpan or search on metacpan
lib/ASNMTAP/Time.pm view on Meta::CPAN
EPOCHTIME => [ qw(SEC MIN HOUR DAY WEEK) ],
LOCALTIME => [ qw(&get_timeslot
&get_yearMonthDay
&get_yyyymmddhhmmsswday
&get_datetimeSignal &get_datetime
&get_logfiledate &get_csvfiledate &get_csvfiletime
&get_epoch &get_week &get_wday &get_hour &get_min &get_seconds &get_day &get_month &get_year) ] );
@ASNMTAP::Time::EXPORT_OK = ( @{ $ASNMTAP::Time::EXPORT_TAGS{ALL} } );
$ASNMTAP::Time::VERSION = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
}
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Constants = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
use constant SEC => 1;
use constant MIN => SEC * 60;
use constant HOUR => MIN * 60;
use constant DAY => HOUR * 24;
use constant WEEK => DAY * 7;
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Private subs = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
sub _checkReadOnly0 { if ( @_ > 0 ) { cluck "Syntax error: Can't change value of read-only function ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
sub _checkReadOnly1 { if ( @_ > 1 ) { cluck "Syntax error: Can't change value of read-only function ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
sub _checkReadOnly2 { if ( @_ > 2 ) { cluck "Syntax error: Can't change value of read-only function ". (caller 1)[3]; exit $ERRORS{UNKNOWN} } }
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Public subs = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Epochtime:
#
# To get the current time, Perl has a built-in function called time().
# This simply returns the number of non-leap seconds that have elapsed
# since 00:00:00 January 1, 1970 UTC.
#
# current epochtime equal to time()
#
# timelocal((localtime)[0,1,2,3,4,5]) = timelocal(localtime)
# List Element Description:
#
# localtime() converts the UTC time into the correct values for the local time zone.
#
# localtime() uses the current time -> localtime(time()) equal to localtime(time)
#
# (localtime)[0]: sec Seconds after each minute (0 - 59)
# (localtime)[1]: min Minutes after each hour (0 - 59)
# (localtime)[2]: hour Hour since midnight (0 - 23)
# (localtime)[3]: monthday Numeric day of the month (1 - 31)
# (localtime)[4]: month Number of months since January (0 - 11)
# (localtime)[5]: year Number of years since 1900
# (localtime)[6]: weekday Number of days since Sunday (0 - 6)
# (localtime)[7]: yearday Number of days since January 1 (0 - 365)
# (localtime)[8]: isdaylight A flag for daylight savings time
#
# ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime( time() );
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub get_timeslot {
&_checkReadOnly1;
my $timeslot;
if (defined $_[0]) {
$timeslot = timelocal ( 0, (localtime($_[0]))[1,2,3,4,5] );
} else {
$timeslot = timelocal ( 0, (localtime)[1,2,3,4,5] );
}
return ( $timeslot );
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub get_yearMonthDay {
&_checkReadOnly1;
if (defined $_[0]) {
return (sprintf ("%04d%02d%02d", (localtime($_[0]))[5]+1900, (localtime($_[0]))[4]+1, (localtime($_[0]))[3]));
} else {
return (sprintf ("%04d%02d%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3]));
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub get_yyyymmddhhmmsswday { &_checkReadOnly0; return sprintf ("%04d:%02d:%02d:%02d:%02d:%02d:%d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3,2,1,0,6]); }
sub get_datetimeSignal { &_checkReadOnly0; return sprintf ("%04d/%02d/%02d %02d:%02d:%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3,2,1,0]); }
sub get_datetime { &_checkReadOnly0; return sprintf ("%02d%02d%02d%02d%02d%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3,2,1,0]); }
sub get_logfiledate { &_checkReadOnly0; return sprintf ("%04d%02d%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3]); }
sub get_csvfiledate { &_checkReadOnly0; return sprintf ("%04d/%02d/%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3]); }
sub get_csvfiletime { &_checkReadOnly0; return sprintf ("%02d:%02d:%02d", (localtime)[2,1,0]); }
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
sub get_epoch {
return ( undef ) unless ( defined $_[0] ); &_checkReadOnly2;
my ($string, $time) = @_;
my $delta = 0;
my $tTime = ( defined $time ? $time : time() );
my ($sign, $number, $type) = ( $string =~ /^\s*([+-])\s*(\d+)\s+(sec|min|hour|(?:day|week|month|year))s?\s*$/ );
if ( defined $type ) {
my $deltaDays = 0;
my $multiplyer = ($sign eq '+' ? 1 : -1);
my $signedNumber = $number * $multiplyer;
my ($year, $month, $day) = ( (localtime($tTime))[5]+1900, (localtime($tTime))[4]+1, (localtime($tTime))[3] );
for ($type) {
/^sec$/ && do { $delta = $signedNumber * SEC; last; };
( run in 0.983 second using v1.01-cache-2.11-cpan-140bd7fdf52 )