[Jifty-commit] r942 - in jifty/trunk: lib lib/Jifty lib/Jifty/Action

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Apr 27 01:06:38 EDT 2006


Author: jesse
Date: Thu Apr 27 01:06:38 2006
New Revision: 942

Added:
   jifty/trunk/lib/Jifty/DateTime.pm
Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/Makefile.PL
   jifty/trunk/lib/Jifty.pm
   jifty/trunk/lib/Jifty/Action/Record.pm
   jifty/trunk/lib/Jifty/Everything.pm

Log:
 r11966 at hualien:  jesse | 2006-04-27 00:18:41 -0400
 * Added suppport for native support for dates and timestamps with time zones 
 
 NOTE: JIFTY NOW SETS $ENV{TZ'} TO GMT work around a bug in Time::Local


Modified: jifty/trunk/Makefile.PL
==============================================================================
--- jifty/trunk/Makefile.PL	(original)
+++ jifty/trunk/Makefile.PL	Thu Apr 27 01:06:38 2006
@@ -13,6 +13,7 @@
 requires('Compress::Zlib');
 requires('DBD::SQLite');
 requires('Data::Page');
+requires('DateTime');
 requires('Date::Manip');
 requires('Email::Folder');
 requires('Email::LocalDelivery');

Modified: jifty/trunk/lib/Jifty.pm
==============================================================================
--- jifty/trunk/lib/Jifty.pm	(original)
+++ jifty/trunk/lib/Jifty.pm	Thu Apr 27 01:06:38 2006
@@ -3,7 +3,7 @@
 
 package Jifty;
 use encoding 'utf8';
-
+$ENV{'TZ'} = "GMT";
 our $VERSION = '0.60321';
 
 =head1 NAME

Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Thu Apr 27 01:06:38 2006
@@ -263,10 +263,8 @@
     my $self = shift;
     my $val = shift;
     return undef unless defined $val and $val =~ /\S/;
-    my $epoch =  Date::Manip::UnixDate(Date::Manip::ParseDate($val),'%s');
-    return undef unless $epoch;
-    my $dt  = DateTime->from_epoch( epoch =>$epoch, time_zone => 'local');
-    return $dt->ymd;
+    return undef unless my $obj = Jifty::DateTime->new_from_string($val);
+    return $obj->ymd;
 }
 
 =head2 take_action

Added: jifty/trunk/lib/Jifty/DateTime.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/DateTime.pm	Thu Apr 27 01:06:38 2006
@@ -0,0 +1,83 @@
+use warnings;
+use strict;
+package Jifty::DateTime;
+
+
+=head1 NAME
+
+Jifty::DateTime - a DateTime subclass that knows about Jifty users 
+
+=head1 DESCRIPTION
+
+Jifty natively stores timestamps in the database in GMT.  Dates are stored
+without timezone. This class loads and parses dates and sets them 
+into the proper timezone.
+
+=cut
+
+use base qw'Jifty::Object DateTime';
+
+use Date::Manip ();
+
+=head2 new ARGS
+
+See L<DateTime/new>.  After calling that method, set this object's timezone
+to the current user's time zone, if the current user has a method called C<time_zone>.
+
+=cut
+
+sub new {
+  my $class = shift;
+  my %args  = (@_);
+  my $self  = $class->SUPER::new(%args);
+
+  # 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();
+  if ( $self->current_user->user_object
+        and  $self->current_user->user_object->can('time_zone')
+        and $self->current_user->user_object->time_zone )
+  {
+    $self->set_time_zone("UTC");
+    $self->set_time_zone( $self->current_user->user_object->time_zone );
+
+  }
+  return $self;
+}
+
+=head2 new_from_string STRING
+
+Take some user defined string like "tomorrow" and turn it into a C<Jifty::Datetime> object.  If the string appears to be a _date_, keep it in the floating timezone, otherwise, set it to the current user's timezone.
+
+
+=cut
+
+sub new_from_string {
+  my $class  = shift;
+  my $string = shift;
+
+  my $now = Date::Manip::UnixDate( $string, "%o" );
+  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
+    $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 );
+  }
+  return $self;
+}
+
+1;

Modified: jifty/trunk/lib/Jifty/Everything.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Everything.pm	(original)
+++ jifty/trunk/lib/Jifty/Everything.pm	Thu Apr 27 01:06:38 2006
@@ -18,7 +18,7 @@
 use Jifty::ClassLoader ();
 use Jifty::Util ();
 use Jifty::API ();
-
+use Jifty::DateTime ();
 use Jifty::Record ();
 use Jifty::Collection ();
 use Jifty::Action ();


More information about the Jifty-commit mailing list