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/;
36 my $conf = new FS::Conf;
37 my $format = $conf->config('date_format') || '%m/%d/%Y';
39 if ( $format eq '%d/%m/%Y' ) { # =~ /\%d.*\%m/ ) {
41 my $parser = DateTime::Format::Natural->new( 'time_zone' => 'local',
42 #'format'=>'d/m/y',#lc($format)
44 $dt = $parser->parse_datetime($string);
45 if ( $parser->success ) {
48 #carp "WARNING: can't parse date: ". $parser->error;
50 #huh, very common, we still need the "partially" (fully enough for our purposes) parsed date.
54 return str2time($string);
61 If the next-bill-ignore-time configuration setting is turned off, just
62 returns the passed-in value.
64 If the next-bill-ignore-time configuration setting is turned on, parses TIME
65 as an integer UNIX timestamp and returns a new timestamp with the same date but
66 23:59:59 for the time.
73 my $conf = new FS::Conf;
74 return $time unless $conf->exists('next-bill-ignore-time');
76 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
78 mktime(59,59,23,$mday,$mon,$year,$wday,$yday,$isdst);