Allow a bare MySQL date (no time) to be used in WebGUI::DateTime's constructor.
This commit is contained in:
parent
ca7a285ace
commit
48b4d91231
2 changed files with 19 additions and 7 deletions
|
|
@ -599,14 +599,18 @@ sub _splitMysql
|
||||||
(\d+) # Month
|
(\d+) # Month
|
||||||
\D*
|
\D*
|
||||||
(\d+) # Day
|
(\d+) # Day
|
||||||
\D*
|
(?: \D*
|
||||||
(\d+) # Hours
|
(\d+) # Hours
|
||||||
\D*
|
\D*
|
||||||
(\d+) # Minutes
|
(\d+) # Minutes
|
||||||
\D*
|
\D*
|
||||||
(\d+) # Seconds
|
(\d+) # Seconds
|
||||||
|
)?
|
||||||
}x;
|
}x;
|
||||||
|
|
||||||
|
foreach my $unit (qw/hour minute second/) {
|
||||||
|
$hash{$unit} = 0 if ($hash{$unit} eq '');
|
||||||
|
}
|
||||||
return %hash;
|
return %hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
10
t/DateTime.t
10
t/DateTime.t
|
|
@ -26,7 +26,7 @@ my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
# put your tests here
|
# put your tests here
|
||||||
|
|
||||||
plan tests => 23;
|
plan tests => 25;
|
||||||
|
|
||||||
my $timeZoneUser = addUser($session);
|
my $timeZoneUser = addUser($session);
|
||||||
|
|
||||||
|
|
@ -76,6 +76,14 @@ my $dt1970 = WebGUI::DateTime->new($session, 0);
|
||||||
isa_ok($dt1970, 'WebGUI::DateTime', 'constructed with 0');
|
isa_ok($dt1970, 'WebGUI::DateTime', 'constructed with 0');
|
||||||
is($dt1970->epoch, 0, '... uses 0 for epoch');
|
is($dt1970->epoch, 0, '... uses 0 for epoch');
|
||||||
|
|
||||||
|
my $bday = WebGUI::DateTime->new($session, '2001-08-16');
|
||||||
|
isa_ok($bday, 'WebGUI::DateTime', 'constructed with mysql date, no time');
|
||||||
|
is(
|
||||||
|
$bday->epoch,
|
||||||
|
WebGUI::DateTime->new($session, WebGUI::Test->webguiBirthday)->truncate( to => 'day')->epoch,
|
||||||
|
'... has correct epoch'
|
||||||
|
);
|
||||||
|
|
||||||
sub addUser {
|
sub addUser {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $user = WebGUI::User->new($session, "new");
|
my $user = WebGUI::User->new($session, "new");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue