Fixed bug in setToEpoch which would throw an error instead of returning gracefully if date format was wrong. It now returns today's date in this case

This commit is contained in:
Frank Dillon 2006-05-07 20:30:15 +00:00
parent fd32315866
commit 8dae97b372

View file

@ -867,14 +867,18 @@ A string in the format of YYYY-MM-DD or YYYY-MM-DD HH:MM:SS.
sub setToEpoch {
my $self = shift;
my $set = shift;
return undef unless $set;
my $set = shift;
return undef unless $set;
my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S' );
my $dt = $parser->parse_datetime($set);
unless ($dt) {
$parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' );
$dt = $parser->parse_datetime($set);
}
unless ($dt) {
$self->session->errorHandler->warn("Could not format date $set for epoch. Returning current time");
return $self->time()
}
# in epochToSet we apply the user's time zone, so now we have to remove it.
$dt->set_time_zone($self->session->user->profileField("timeZone")|| "America/Chicago"); # assign the user's timezone
return $dt->epoch;