[Jifty-commit] r1734 - jifty/trunk/lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Aug 3 00:14:51 EDT 2006
Author: clkao
Date: Thu Aug 3 00:14:48 2006
New Revision: 1734
Modified:
jifty/trunk/lib/Jifty/DateTime.pm
Log:
Jifty::DateTime cleanups.
Modified: jifty/trunk/lib/Jifty/DateTime.pm
==============================================================================
--- jifty/trunk/lib/Jifty/DateTime.pm (original)
+++ jifty/trunk/lib/Jifty/DateTime.pm Thu Aug 3 00:14:48 2006
@@ -35,19 +35,27 @@
# Unless the user has explicitly said they want a floating time,
# we want to convert to the end-user's timezone. This is
# complicated by the fact that DateTime auto-appends
- $self->_get_current_user();
- my $user_obj = $self->current_user->user_object;
- if ( $user_obj
- and $user_obj->can('time_zone')
- and $user_obj->time_zone )
- {
+ if (my $tz = $self->current_user_has_timezone) {
$self->set_time_zone("UTC");
- $self->set_time_zone( $user_obj->time_zone );
-
+ $self->set_time_zone( $tz );
}
return $self;
}
+=head2 current_user_has_timezone
+
+Return timezone if the current user has it
+
+=cut
+
+sub current_user_has_timezone {
+ my $self = shift;
+ $self->_get_current_user();
+ my $user_obj = $self->current_user->user_object or return;
+ my $f = $user_obj->can('time_zone') or return;
+ return $f->($user_obj);
+}
+
=head2 new_from_string STRING
Take some user defined string like "tomorrow" and turn it into a
@@ -74,22 +82,10 @@
}
return undef unless $now;
my $self = $class->from_epoch( epoch => $now, time_zone => 'gmt' );
- $self->_get_current_user();
- if ( $self->current_user->user_object
- and $self->current_user->user_object->can('time_zone')
- and $self->current_user->user_object->time_zone )
- {
-
- # If the DateTime we've been handed appears to actually be at
- # a "time" then we want to make sure we get it to be that time
- # in the local timezone
- #
- # If we had only a date, then we want to switch it to the
- # user's timezone without adjusting the "time", as that could
- # make 2006-12-01 into 2006-11-30
+ if (my $tz = $self->current_user_has_timezone) {
$self->set_time_zone("floating")
unless ( $self->hour or $self->minute or $self->second );
- $self->set_time_zone( $self->current_user->user_object->time_zone );
+ $self->set_time_zone( $tz );
}
return $self;
}
More information about the Jifty-commit
mailing list