New methods in WebGUI::DateTime that clearly state how they handle timezones.

The standard is everything going into the DB is in UTC.  Timezones have to be
manually handled after being fetched.
Added a test for the new methods and for object construction.
Changed Calendar and Event Assets to use the new methods.
Interim checkin to get some debug help from Doug.
This commit is contained in:
Colin Kuskie 2007-01-19 05:16:57 +00:00
parent f6a956c447
commit 17fac4a7cb
4 changed files with 394 additions and 52 deletions

79
t/DateTime.pm Normal file
View file

@ -0,0 +1,79 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::User;
# load your modules here
use Test::More;
my $session = WebGUI::Test->session;
# put your tests here
my $numTests = 1 + 12;
plan tests => $numTests;
my $loaded = use_ok("WebGUI::DateTime");
my $timeZoneUser = addUser($session);
SKIP: {
skip "Unable to load WebGUI::DateTime", $numTests-1 unless $loaded;
my $dt = WebGUI::DateTime->new($session,"2006-11-06 21:12:45");
isa_ok($dt, "WebGUI::DateTime", "constructor");
isa_ok($dt, "DateTime", "constructor");
is($dt->toDatabase, "2006-11-06 21:12:45", "toDatabase returns the identical string since it is in UTC");
is($dt->toDatabaseDate, "2006-11-06", "toDatabaseDate returns the identical date since it is in UTC");
is($dt->toDatabaseTime, "21:12:45", "toDatabaseTime returns the identical time since it is in UTC");
$session->user({user => $timeZoneUser});
my $copiedDt = $dt->cloneToUserTimeZone;
isa_ok($copiedDt, "WebGUI::DateTime", "cloneToUserTimeZone");
is($copiedDt->time_zone()->name, "America/Hermosillo", "cloned object has correct time zone");
is($dt->time_zone()->name, "UTC", "original object is still UTC");
is($copiedDt->toUserTimeZone(), "2006-11-06 14:12:45", "toUserTimeZone obeys the time zone");
is($copiedDt->toUserTimeZoneDate(), "2006-11-06", "toUserTimeZoneDate obeys the time zone");
is($copiedDt->toUserTimeZoneTime(), "14:12:45", "toUserTimeZoneTime obeys the time zone");
my $epochDt = WebGUI::DateTime->new($session, "1169141075");
isa_ok($epochDt, "WebGUI::DateTime", "epochal construction");
}
sub addUser {
my $session = shift;
my $user = WebGUI::User->new($session, "new");
##From my research, this particular time zone does NOT follow daylight savings,
##so the test will not fail in the summer
$user->profileField("timeZone","America/Hermosillo");
$user->username("Time Zone");
return $user;
}
END { ##Clean-up after yourself, always
foreach my $dude ($timeZoneUser) {
$dude->delete if (defined $dude and ref $dude eq 'WebGUI::User');
}
}