[Jifty-commit] r4380 - in jifty/trunk: lib/Jifty t/TestApp/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Nov 5 20:25:17 EST 2007
Author: sartak
Date: Mon Nov 5 20:25:16 2007
New Revision: 4380
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/DateTime.pm
jifty/trunk/t/TestApp/t/11-current_user.t
Log:
r44707 at onn: sartak | 2007-11-05 20:24:45 -0500
Add Jifty::DateTime::from_epoch which does our usual timezone magic, use set_current_user_timezone more, too
Modified: jifty/trunk/lib/Jifty/DateTime.pm
==============================================================================
--- jifty/trunk/lib/Jifty/DateTime.pm (original)
+++ jifty/trunk/lib/Jifty/DateTime.pm Mon Nov 5 20:25:16 2007
@@ -69,7 +69,10 @@
# we want to convert to the end-user's timezone. If we ignore
# $args{time_zone}, then DateTime::from_epoch will get very confused
if (!$args{time_zone} and my $tz = $self->current_user_has_timezone) {
- $self->set_time_zone("UTC"); # XXX: why are we doing this?
+
+ # XXX: we do this because of the floating timezone
+ $self->set_time_zone("UTC");
+
$self->set_time_zone( $tz );
}
}
@@ -100,7 +103,24 @@
my %args = @_;
my $self = $class->SUPER::now(%args);
- $self->set_time_zone($self->current_user_has_timezone || 'UTC')
+ $self->set_current_user_timezone()
+ unless $args{time_zone};
+
+ return $self;
+}
+
+=head2 from_epoch ARGS
+
+See L<DateTime/from_epoch> and L<Jifty::DateTime/now>.
+
+=cut
+
+sub from_epoch {
+ my $class = shift;
+ my %args = @_;
+ my $self = $class->SUPER::from_epoch(%args);
+
+ $self->set_current_user_timezone()
unless $args{time_zone};
return $self;
@@ -117,7 +137,7 @@
$self->_get_current_user();
# Can't continue if we have no notion of a user_object
- return unless $self->current_user->can('user_object');
+ $self->current_user->can('user_object') or return;
# Can't continue unless the user object is defined
my $user_obj = $self->current_user->user_object or return;
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:25:16 2007
@@ -11,7 +11,7 @@
use lib 't/lib';
use Jifty::SubTest;
-use Jifty::Test tests => 32;
+use Jifty::Test tests => 33;
use Jifty::Test::WWW::Mechanize;
use_ok('TestApp::Model::User');
@@ -62,12 +62,15 @@
$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");
+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");
+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 $dt = Jifty::DateTime->from_epoch(epoch => time);
+like($now->time_zone, qr{America::Anchorage}, "from_epoch correctly gets the user's timezone");
+
my $server = Jifty::Test->make_server;
isa_ok($server, 'Jifty::Server');
More information about the Jifty-commit
mailing list