From 19a87ea0038723f82e46aba6a5e00719eaec93cc Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 18 Oct 2010 10:32:45 -0700 Subject: [PATCH] Variable hour formats don't add an extra space any longer. Fixes bug #11915. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Session/DateTime.pm | 10 +++++++--- t/Form/DateTime.t | 4 ++-- t/Macro/D_date.t | 4 ++-- t/Session/DateTime.t | 10 ++++++++-- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index e414f1def..dbd2a9a8a 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -8,6 +8,7 @@ - fixed #11900: Request Approval for Version Tag Workflow activity can't select --Continue with this workflow - fixed #11898: String eval used in Image::Graph - fixed #11913: Editing the survey doesn't work + - fixed #11915: Date macro returns hour value w/ leading space 7.10.2 - fixed #11884: Editing Templates impossible / Code editor not loaded diff --git a/lib/WebGUI/Session/DateTime.pm b/lib/WebGUI/Session/DateTime.pm index 9128e6394..04c69e3bc 100644 --- a/lib/WebGUI/Session/DateTime.pm +++ b/lib/WebGUI/Session/DateTime.pm @@ -325,7 +325,7 @@ sub epochToHuman { "d" => "d", "D" => "_varday_", "h" => "I", - "H" => "l", + "H" => "_varhour_", "j" => "H", "J" => "k", "m" => "m", @@ -351,11 +351,15 @@ sub epochToHuman { $output = $dt->strftime($output); #--- %M - $temp = int($dt->month); + $temp = $dt->month; $output =~ s/\%_varmonth_/$temp/g; #-- %D - $temp = int($dt->day); + $temp = $dt->day; $output =~ s/\%_varday_/$temp/g; + #-- %H, variable digit hour, 12 hour clock + $temp = $dt->hour; + $temp -= 12 if ($temp > 12); + $output =~ s/\%_varhour_/$temp/g; #--- return return $output; } diff --git a/t/Form/DateTime.t b/t/Form/DateTime.t index 3504fa3b0..ad06395d4 100644 --- a/t/Form/DateTime.t +++ b/t/Form/DateTime.t @@ -130,7 +130,7 @@ is( ); $date2 = WebGUI::Form::DateTime->new($session, {defaultValue => -1}); -is($date2->getValueAsHtml(), '12/31/1969 5:59 pm', "getValueAsHtml: defaultValue as negative epoch, returns as user's format"); +is($date2->getValueAsHtml(), '12/31/1969 5:59 pm', "getValueAsHtml: defaultValue as negative epoch, returns as user's format"); is( getValueFromForm($session, $date2->toHtmlAsHidden), '1969-12-31 17:59:59', @@ -158,7 +158,7 @@ is( $date2 = WebGUI::Form::DateTime->new($session, {defaultValue => '2008-08-01 11:34:26', value => $bday, }); -is($date2->getValueAsHtml(), '8/16/2001 8:00 am', "getValueAsHtml: defaultValue in mysql format, value as epoch returns value in user's format"); +is($date2->getValueAsHtml(), '8/16/2001 8:00 am', "getValueAsHtml: defaultValue in mysql format, value as epoch returns value in user's format"); is( getValueFromForm($session, $date2->toHtmlAsHidden), '2001-08-16 08:00:00', diff --git a/t/Macro/D_date.t b/t/Macro/D_date.t index 7eb07cc94..7495492ba 100644 --- a/t/Macro/D_date.t +++ b/t/Macro/D_date.t @@ -29,7 +29,7 @@ my @testSets = ( }, { format => '', - output =>'8/16/2001 8:00 am', + output =>'8/16/2001 8:00 am', }, ); @@ -61,7 +61,7 @@ is($output, $session->datetime->epochToHuman($time1), 'checking default time and ##Checking for edge case, time=0 is WebGUI::Macro::D_date::process($session, '', 0), - '12/31/1969 6:00 pm', + '12/31/1969 6:00 pm', '...checking for handling time=0'; lives_ok { WebGUI::Macro::D_date::process($session, '', ' 0') } diff --git a/t/Session/DateTime.t b/t/Session/DateTime.t index e2a066319..7b4d077c8 100644 --- a/t/Session/DateTime.t +++ b/t/Session/DateTime.t @@ -17,7 +17,7 @@ use File::Spec; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 92; # increment this value for each test you create +use Test::More tests => 95; # increment this value for each test you create installBadLocale(); WebGUI::Test->addToCleanup(sub { unlink File::Spec->catfile(WebGUI::Test->lib, qw/WebGUI i18n BadLocale.pm/); }); @@ -298,9 +298,15 @@ cmp_ok( $dude->profileField('language', 'BadLocale'); $session->user({user => $dude}); -is($dt->epochToHuman($wgbday), '8/16/2001 9:00 pm', 'epochToHuman: constructs a default locale if the language does not provide one.'); +is($dt->epochToHuman($wgbday), '8/16/2001 9:00 pm', 'epochToHuman: constructs a default locale if the language does not provide one.'); $session->user({userId => 1}); +##Variable digit days, months and hours +is($dt->epochToHuman($wgbday,'%M'), '8', '... single digit month'); +my $dayEpoch = DateTime->from_epoch(epoch => $wgbday)->subtract(days => 10)->epoch; +is($dt->epochToHuman($dayEpoch,'%D'), '6', '... single digit day'); +is($dt->epochToHuman($dayEpoch,'%H'), '8', '... single digit hour'); + sub installBadLocale { copy( WebGUI::Test->getTestCollateralPath('BadLocale.pm'),