1 package FS::Misc::DateTime;
3 use base qw( Exporter );
4 use vars qw( @EXPORT_OK );
8 use DateTime::Format::Natural;
11 @EXPORT_OK = qw( parse_datetime day_end );
15 FS::Misc::DateTime - Date and time subroutines
19 use FS::Misc::DateTime qw( parse_datetime );
25 =item parse_datetime STRING
27 Parses a date (and possibly time) from the supplied string and returns
28 the date as an integer UNIX timestamp.
34 return '' unless $string =~ /\S/;
35 my $tz = shift || 'local';
37 my $conf = new FS::Conf;
38 my $format = $conf->config('date_format') || '%m/%d/%Y';
40 if ( $format eq '%d/%m/%Y' ) { # =~ /\%d.*\%m/ ) {
42 my $parser = DateTime::Format::Natural->new( 'time_zone' => $tz,
43 #'format'=>'d/m/y',#lc($format)
45 $dt = $parser->parse_datetime($string);
46 if ( $parser->success ) {
49 #carp "WARNING: can't parse date: ". $parser->error;
51 #huh, very common, we still need the "partially" (fully enough for our purposes) parsed date.
55 return str2time($string, $tz);
62 Parses TIME as an integer UNIX timestamp and returns a new timestamp with the
63 same date but 23:59:59 for the time.
70 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
72 timelocal(59,59,23,$mday,$mon,$year);