[Jifty-commit] r4122 - in jifty/trunk: lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Sep 17 12:44:15 EDT 2007
Author: sartak
Date: Mon Sep 17 12:44:14 2007
New Revision: 4122
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/DateTime.pm
Log:
r42743 at onn: sartak | 2007-09-17 12:44:04 -0400
Add a 'now' method to Jifty::DateTime which sets the timezone to the current user's timezone.
DateTime::now passes time_zone => UTC to Jifty::DateTime::now, which caused it to skip over the currentuser/timezone magic.
Modified: jifty/trunk/lib/Jifty/DateTime.pm
==============================================================================
--- jifty/trunk/lib/Jifty/DateTime.pm (original)
+++ jifty/trunk/lib/Jifty/DateTime.pm Mon Sep 17 12:44:14 2007
@@ -57,15 +57,19 @@
# XXX What if they really mean midnight offset by time zone?
+ # this behavior is (sadly!) consistent with
+ # DateTime->truncate(to => 'day') and Jifty::DateTime::new_from_string
+ # suggestions for improvement are very welcome
+
# Do not bother with time zones unless time is used, we assume that
# 00:00:00 implies that no time is used
if ($self->hour || $self->minute || $self->second) {
# 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
+ # 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");
+ $self->set_time_zone("UTC"); # XXX: why are we doing this?
$self->set_time_zone( $tz );
}
}
@@ -78,6 +82,30 @@
return $self;
}
+=head2 now ARGS
+
+See L<DateTime/now>. If a time_zone argument is passed in, then this method
+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
+user's timezone (unless otherwise requested, of course).
+
+=cut
+
+sub now {
+ my $class = shift;
+ my %args = @_;
+ my $self = $class->SUPER::now(%args);
+
+ $self->set_time_zone($self->current_user_has_timezone || 'UTC')
+ unless $args{time_zone};
+
+ return $self;
+}
+
=head2 current_user_has_timezone
Return timezone if the current user has one. This is determined by checking to see if the current user has a user object. If it has a user object, then it checks to see if that user object has a C<time_zone> method and uses that to determine the value.
More information about the Jifty-commit
mailing list