From a7aa1d2fb2d32ca9b4d84052ab819b9509c2b970 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 1 Dec 2009 17:08:12 -0800 Subject: [PATCH] Fix epoch=0 issues with Session/DateTime and D_date macro. Add an edge case test for D_date macro. --- lib/WebGUI/Macro/D_date.pm | 13 +++++++------ lib/WebGUI/Session/DateTime.pm | 7 +++++-- t/Macro/D_date.t | 7 ++++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/WebGUI/Macro/D_date.pm b/lib/WebGUI/Macro/D_date.pm index c30535061..317acb236 100644 --- a/lib/WebGUI/Macro/D_date.pm +++ b/lib/WebGUI/Macro/D_date.pm @@ -37,12 +37,13 @@ time is used instead. #------------------------------------------------------------------- sub process { - my $session = shift; - my (@param, $temp, $time); - @param = @_; - $time = $param[1] ||time(); - $temp =$session->datetime->epochToHuman($time,$param[0]); - return $temp; + my $session = shift; + my $time = $_[1]; + if (! defined $time) { + $time = time(); + } + my $temp = $session->datetime->epochToHuman($time, $_[0]); + return $temp; } diff --git a/lib/WebGUI/Session/DateTime.pm b/lib/WebGUI/Session/DateTime.pm index 1dab2cb20..a07f4f832 100644 --- a/lib/WebGUI/Session/DateTime.pm +++ b/lib/WebGUI/Session/DateTime.pm @@ -298,8 +298,11 @@ A string representing the output format for the date. Defaults to '%z %Z'. You c =cut sub epochToHuman { - my $self = shift; - my $epoch = shift || time(); + my $self = shift; + my $epoch = shift; + if (!defined $epoch || $epoch eq '') { + $epoch = time(); + } my $i18n = WebGUI::International->new($self->session); my $language = $i18n->getLanguage($self->session->user->profileField('language')); my $locale = $language->{languageAbbreviation} || 'en'; diff --git a/t/Macro/D_date.t b/t/Macro/D_date.t index 05f6afad8..d6a857975 100644 --- a/t/Macro/D_date.t +++ b/t/Macro/D_date.t @@ -34,7 +34,7 @@ my @testSets = ( }, ); -my $numTests = scalar @testSets + 1; +my $numTests = scalar @testSets + 2; plan tests => $numTests; @@ -59,3 +59,8 @@ while ($time1 != $time2) { } is($output, $session->datetime->epochToHuman($time1), 'checking default time and format'); + +##Checking for edge case, time=0 +is WebGUI::Macro::D_date::process($session, '', 0), +'12/31/1969 6:00 pm', +'...checking for handling time=0';