X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FMisc%2FDateTime.pm;h=56baec3ed96558310815ae24ab43bda7d6d17f43;hp=9c12e6408fdcafdb808331b3bc992afd37f1f5fa;hb=376794a00e837317e35fefd61a29ab58c0303b35;hpb=d77fe06b27410a41855e1425114ab8d9cdae4ff0 diff --git a/FS/FS/Misc/DateTime.pm b/FS/FS/Misc/DateTime.pm index 9c12e6408..56baec3ed 100644 --- a/FS/FS/Misc/DateTime.pm +++ b/FS/FS/Misc/DateTime.pm @@ -2,13 +2,14 @@ package FS::Misc::DateTime; use base qw( Exporter ); use vars qw( @EXPORT_OK ); -use POSIX; use Carp; +use Time::Local; use Date::Parse; use DateTime::Format::Natural; +use Date::Format; use FS::Conf; -@EXPORT_OK = qw( parse_datetime day_end ); +@EXPORT_OK = qw( parse_datetime day_end iso8601 ); =head1 NAME @@ -49,7 +50,7 @@ sub parse_datetime { #carp "WARNING: can't parse date: ". $parser->error; #return ''; #huh, very common, we still need the "partially" (fully enough for our purposes) parsed date. - $dt->epoch; + return $dt->epoch; } } else { return str2time($string, $tz); @@ -59,24 +60,28 @@ sub parse_datetime { =item day_end TIME -If the next-bill-ignore-time configuration setting is turned off, just -returns the passed-in value. - -If the next-bill-ignore-time configuration setting is turned on, parses TIME -as an integer UNIX timestamp and returns a new timestamp with the same date but -23:59:59 for the time. +Parses TIME as an integer UNIX timestamp and returns a new timestamp with the +same date but 23:59:59 for the time. =cut sub day_end { - my $time = shift; + my $time = shift; + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = + localtime($time); + timelocal(59,59,23,$mday,$mon,$year); +} - my $conf = new FS::Conf; - return $time unless $conf->exists('next-bill-ignore-time'); +=item iso8601 TIME + +Parses time as an integer UNIX timestamp and returns the ISO 8601 formatted +date and time. + +=cut - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = - localtime($time); - mktime(59,59,23,$mday,$mon,$year,$wday,$yday,$isdst); +sub iso8601 { + time2str('%Y-%m-%dT%T', @_); } =back