projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add condition_sql optimization to "Package definitions" condition, RT#74456
[freeside.git]
/
FS
/
FS
/
Misc
/
DateTime.pm
diff --git
a/FS/FS/Misc/DateTime.pm
b/FS/FS/Misc/DateTime.pm
index
e36f3a9
..
08cf9a9
100644
(file)
--- 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 base qw( Exporter );
use vars qw( @EXPORT_OK );
-use POSIX;
use Carp;
use Carp;
+use Time::Local;
use Date::Parse;
use DateTime::Format::Natural;
use Date::Parse;
use DateTime::Format::Natural;
+use Date::Format;
use FS::Conf;
use FS::Conf;
-@EXPORT_OK = qw( parse_datetime day_end );
+@EXPORT_OK = qw( parse_datetime day_end
iso8601
);
=head1 NAME
=head1 NAME
@@
-32,13
+33,14
@@
the date as an integer UNIX timestamp.
sub parse_datetime {
my $string = shift;
return '' unless $string =~ /\S/;
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 $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);
#'format'=>'d/m/y',#lc($format)
);
$dt = $parser->parse_datetime($string);
@@
-48,34
+50,38
@@
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.
#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 {
}
} else {
- return str2time($string);
+ return str2time($string
, $tz
);
}
}
=item day_end TIME
}
}
=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 {
=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', shift);
}
=back
}
=back