[Jifty-commit] r4379 - in jifty/trunk: lib/Jifty t/TestApp/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Nov 5 20:09:50 EST 2007
Author: sartak
Date: Mon Nov 5 20:09:50 2007
New Revision: 4379
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/DateTime.pm
jifty/trunk/t/TestApp/t/11-current_user.t
Log:
r44697 at onn: sartak | 2007-11-05 20:08:14 -0500
Add a Jifty::DateTime set_current_user_timezone method
Modified: jifty/trunk/lib/Jifty/DateTime.pm
==============================================================================
--- jifty/trunk/lib/Jifty/DateTime.pm (original)
+++ jifty/trunk/lib/Jifty/DateTime.pm Mon Nov 5 20:09:50 2007
@@ -127,6 +127,23 @@
return $f->($user_obj);
}
+=head2 set_current_user_timezone [DEFAULT_TZ]
+
+Set this Jifty::DateTime's timezone to the current user's timezone. If that's
+not available, then use the passed in DEFAULT_TZ (or GMT if not passed in).
+Returns the Jifty::DateTime object itself.
+
+=cut
+
+sub set_current_user_timezone {
+ my $self = shift;
+ my $default = shift || 'GMT';
+ my $tz = $self->current_user_has_timezone || $default;
+
+ $self->set_time_zone($tz);
+ return $self;
+}
+
=head2 new_from_string STRING
Take some user defined string like "tomorrow" and turn it into a
Modified: jifty/trunk/t/TestApp/t/11-current_user.t
==============================================================================
--- jifty/trunk/t/TestApp/t/11-current_user.t (original)
+++ jifty/trunk/t/TestApp/t/11-current_user.t Mon Nov 5 20:09:50 2007
@@ -11,7 +11,7 @@
use lib 't/lib';
use Jifty::SubTest;
-use Jifty::Test tests => 27;
+use Jifty::Test tests => 32;
use Jifty::Test::WWW::Mechanize;
use_ok('TestApp::Model::User');
@@ -37,6 +37,12 @@
like($o->created_on->time_zone, qr/Floating/, "User's created_on date is in the floating timezone");
like($o->current_time->time_zone, qr/UTC/, "Jifty::DateTime::now defaults to UTC (superuser has no user_object)");
+my $now = $o->current_time->clone;
+$now->set_current_user_timezone('America/Chicago');
+like($now->time_zone, , qr{America::Chicago}, "set_current_user_timezone defaults to the passed in timezone");
+$now->set_current_user_timezone();
+like($now->time_zone, , qr{UTC}, "set_current_user_timezone defaults to UTC if no passed in timezone");
+
is($o->email, 'bob at example.com', 'email initially set correctly');
$o->set_email('bob+jifty at example.com');
is($o->email, 'bob+jifty at example.com', 'email updated correctly');
@@ -54,6 +60,14 @@
like($bob->user_object->created_on->time_zone, qr/Floating/, "User's created_on date is in the floating timezone");
like($bob->user_object->current_time->time_zone, qr{America::Anchorage}, "Jifty::DateTime::now correctly peers into current_user->user_object->time_zone");
+$now = $bob->user_object->current_time->clone;
+$now->set_time_zone('America/New_York');
+like($now->time_zone, , qr{America::New_York}, "setting up other tests");
+$now->set_current_user_timezone();
+like($now->time_zone, , qr{America::Anchorage}, "set_current_user_timezone correctly gets the user's timezone");
+$now->set_current_user_timezone('America/Chicago');
+like($now->time_zone, , qr{America::Anchorage}, "set_current_user_timezone uses the user's in timezone even if one is passed in");
+
my $server = Jifty::Test->make_server;
isa_ok($server, 'Jifty::Server');
More information about the Jifty-commit
mailing list