diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index b0231478a..7c3cb711f 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,7 @@ - fixed #12179: DataTable Field types get reset to "Text" in Edit Schema (Amir Plivatsky) - added: FormField macro for rendering Form objects directly from templates - fixed: Generic Tax driver does not like spaces around commas + - fixed: Date formatting with WebGUI::DateTime has extra spaces for single digit months and days. 7.10.19 - fixed #12169: extras uploads symlink export diff --git a/lib/WebGUI/DateTime.pm b/lib/WebGUI/DateTime.pm index 2ff53a969..d5fd13a14 100644 --- a/lib/WebGUI/DateTime.pm +++ b/lib/WebGUI/DateTime.pm @@ -491,7 +491,9 @@ sub session { Change a WebGUI format into a Strftime format. NOTE: %M in WebGUI's format has no equivalent in strftime format, so it will -be replaced with "_varmonth_". Do something with it. +be replaced with "{month}". Single digit hours are handled similarly. DateTime's +strftime will use {method} to call a method on the object to fill in that part of +the format. =cut @@ -514,13 +516,13 @@ sub webguiToStrftime { "c" => "B", "C" => "b", "d" => "d", - "D" => "e", + "D" => "{day}", "h" => "I", "H" => "l", "j" => "H", "J" => "k", "m" => "m", - "M" => "_varmonth_", + "M" => "{month}", "n" => "M", "t" => "Z", "O" => "z", @@ -587,12 +589,7 @@ sub webguiDate { my $format = $self->webguiToStrftime( shift || "%z %Z" ); - #--- %M my $datestr = $self->strftime($format); - my $temp = int($self->month); - $datestr =~ s/\%_varmonth_/$temp/g; - - #--- return return $datestr; } ####################################################################### diff --git a/t/DateTime.t b/t/DateTime.t index 48026b902..3879f832a 100644 --- a/t/DateTime.t +++ b/t/DateTime.t @@ -26,7 +26,7 @@ my $session = WebGUI::Test->session; # put your tests here -plan tests => 30; +plan tests => 32; my $timeZoneUser = addUser($session); @@ -98,11 +98,15 @@ is( $nowDt->webguiToStrftime('%y-%m-%d'), '%Y-%m-%d', 'webgui to strftime conver $timeZoneUser->update({ 'dateFormat' => '%y-%M-%D' }); $timeZoneUser->update({ 'timeFormat' => '%H:%n %p' }); -is( $nowDt->webguiToStrftime, '%Y-%_varmonth_-%e %l:%M %P', 'default datetime string' ); +is( $nowDt->webguiToStrftime, '%Y-%{month}-%{day} %l:%M %P', 'default datetime string' ); +my $single_digit = WebGUI::DateTime->new($session, '2011-07-04 15:00:00'); +is $single_digit->webguiDate("%z"), '2011-7-4', 'single digit month and day check'; +is $single_digit->webguiDate("%z"), $session->datetime->epochToHuman($single_digit->epoch, '%z'), 'webguiDate, an exact match to session->datetime'; sub addUser { my $session = shift; + my $user = WebGUI::User->new($session, "new"); ##From my research, this particular time zone does NOT follow daylight savings,