X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=FS%2FFS%2FMisc%2FDateTime.pm;h=2fff90647efd71610db91df7e016b685ee81ee29;hb=d86f30add230405cb3ff689846ecce7e639e461b;hp=e36f3a95a90921d35d47137f59ba2e349c122c8e;hpb=fb4ab1073f0d15d660c6cdc4e07afebf68ef3924;p=freeside.git diff --git a/FS/FS/Misc/DateTime.pm b/FS/FS/Misc/DateTime.pm index e36f3a95a..2fff90647 100644 --- a/FS/FS/Misc/DateTime.pm +++ b/FS/FS/Misc/DateTime.pm @@ -2,8 +2,8 @@ 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 FS::Conf; @@ -32,13 +32,14 @@ the date as an integer UNIX timestamp. sub parse_datetime { my $string = shift; return '' unless $string =~ /\S/; + my $tz = shift || 'local'; my $conf = new FS::Conf; my $format = $conf->config('date_format') || '%m/%d/%Y'; if ( $format eq '%d/%m/%Y' ) { # =~ /\%d.*\%m/ ) { #$format =~ s/\%//g; - my $parser = DateTime::Format::Natural->new( 'time_zone' => 'local', + my $parser = DateTime::Format::Natural->new( 'time_zone' => $tz, #'format'=>'d/m/y',#lc($format) ); $dt = $parser->parse_datetime($string); @@ -48,34 +49,27 @@ 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); + return str2time($string, $tz); } } =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 $conf = new FS::Conf; - return $time unless $conf->exists('next-bill-ignore-time'); - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time); - mktime(59,59,23,$mday,$mon,$year,$wday,$yday,$isdst); + timelocal(59,59,23,$mday,$mon,$year); } =back