From 8dae97b3721f2c08e649c4a966d1dcc87b9bb926 Mon Sep 17 00:00:00 2001 From: Frank Dillon Date: Sun, 7 May 2006 20:30:15 +0000 Subject: [PATCH] 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 --- lib/WebGUI/Session/DateTime.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Session/DateTime.pm b/lib/WebGUI/Session/DateTime.pm index 15522ce1d..f76322944 100644 --- a/lib/WebGUI/Session/DateTime.pm +++ b/lib/WebGUI/Session/DateTime.pm @@ -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;