[Jifty-commit] r6556 - in jifty/trunk: . lib/Jifty
Jifty commits
jifty-commit at lists.jifty.org
Tue Mar 3 19:40:50 EST 2009
Author: sartak
Date: Tue Mar 3 19:40:49 2009
New Revision: 6556
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/DateTime.pm
jifty/trunk/lib/Jifty/Filter/DateTime.pm
Log:
r80849 at onn: sartak | 2009-03-03 19:40:43 -0500
Some cleanup and more fixes
Modified: jifty/trunk/lib/Jifty/DateTime.pm
==============================================================================
--- jifty/trunk/lib/Jifty/DateTime.pm (original)
+++ jifty/trunk/lib/Jifty/DateTime.pm Tue Mar 3 19:40:49 2009
@@ -47,16 +47,19 @@
=head2 new ARGS
-See L<DateTime/new>. If we get what appears to be a date, then we
-keep this in the floating datetime. Otherwise, set this object's
-timezone to the current user's time zone, if the current user has a
-method called C<time_zone>.
+See L<DateTime/new>. If we get what appears to be a date, then we keep this in
+the floating datetime. Otherwise, set this object's timezone to the current
+user's time zone, if the current user's user object has a method called
+C<time_zone>.
=cut
sub new {
my $class = shift;
- my %args = @_;
+ my %args = (
+ current_user => undef,
+ @_,
+ );
my $current_user = delete $args{current_user};
@@ -65,16 +68,26 @@
my $is_date = $self->hms eq '00:00:00'
&& $self->time_zone->name eq 'floating';
+ # The output time_zone is the *current user's* time zone. It's okay that
+ # $current_user can be undef; we'll still find and set the right current
+ # user then set the time zone.
$self->current_user($current_user);
- if ($args{time_zone}) {
- $self->set_time_zone($args{time_zone});
- }
- elsif ($is_date) {
- $self->set_hour(0);
- $self->set_minute(0);
- $self->set_second(0);
+ # If we were given a date, then we need to make sure its output time zone
+ # is Floating and it's set to 00:00:00.
+ # This sucks when you want a timestamp (not just a datestamp) at midnight
+ # in the floating time zone but we don't have any better way to make this
+ # work.
+ if ($is_date) {
$self->set_time_zone('floating');
+
+ # Without this check we loop infinitely, because set_hour constructs
+ # a new Jifty::DateTime object.
+ if ($self->hms ne '00:00:00') {
+ $self->set_hour(0);
+ $self->set_minute(0);
+ $self->set_second(0);
+ }
}
return $self;
@@ -82,25 +95,33 @@
=head2 now ARGS
-See L<DateTime/now>. If a time_zone argument is passed in, then this method
+See L<DateTime/now>. If a time_zone argument is passed in, then this wrapper
is effectively a no-op.
OTHERWISE this will always set this object's timezone to the current user's
-timezone (or UTC if that's not available). Without this, DateTime's C<now> will
-set the timezone to UTC always (by passing C<< time_zone => 'UTC' >> to
-C<Jifty::DateTime::new>. We want Jifty::DateTime to always reflect the current
+timezone. Without this, DateTime's C<now> will set the timezone to UTC always
+(by passing C<< time_zone => 'UTC' >> to C<Jifty::DateTime::new>. We want
+Jifty::DateTime to always reflect the current
user's timezone (unless otherwise requested, of course).
=cut
sub now {
my $class = shift;
- my %args = @_;
+ my %args = (
+ current_user => undef,
+ time_zone => undef,
+ @_,
+ );
my $current_user = delete $args{current_user};
my $self = $class->SUPER::now(%args);
$self->current_user($current_user);
+
+ # We set time_zone here since saying
+ # "Jifty::DateTime->now(time_zone => 'UTC')" is obviously referring the
+ # output time zone; the input time zone doesn't matter at all.
$self->set_time_zone($args{time_zone}) if $args{time_zone};
return $self;
@@ -120,6 +141,10 @@
my $self = $class->SUPER::from_epoch(%args);
$self->current_user($current_user);
+
+ # We set time_zone here since saying
+ # "Jifty::DateTime->now(time_zone => 'UTC')" is obviously referring the
+ # output time zone; the input time zone doesn't matter at all.
$self->set_time_zone($args{time_zone}) if $args{time_zone};
return $self;
@@ -129,6 +154,9 @@
When setting the current user, update the timezone appropriately.
+If an C<undef> current user is passed, this method will find the correct
+current user and set the time zone.
+
=cut
sub current_user {
@@ -143,6 +171,7 @@
}
my $ret = $self->SUPER::current_user(@_);
+
$self->set_current_user_timezone();
return $ret;
}
Modified: jifty/trunk/lib/Jifty/Filter/DateTime.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Filter/DateTime.pm (original)
+++ jifty/trunk/lib/Jifty/Filter/DateTime.pm Tue Mar 3 19:40:49 2009
@@ -54,7 +54,7 @@
# XXX There has to be a better way to do this
my %args;
- for (qw(year month day hour minute second nanosecond formatter)) {
+ for (qw(year month day hour minute second nanosecond formatter time_zone)) {
$args{$_} = $$value_ref->$_ if(defined($$value_ref->$_));
}
More information about the Jifty-commit
mailing list