[Rt-commit] r18786 - in rt/3.999/branches/datetime: . etc lib/RT lib/RT/Action lib/RT/Condition lib/RT/Crypt lib/RT/DateTime lib/RT/Interface lib/RT/Model lib/RT/Report lib/RT/ScripAction lib/RT/Shredder/Plugin sbin share/html/Approvals/Elements share/html/Dashboards share/html/Elements share/html/Elements/RT__Model__Ticket share/html/Install share/html/NoAuth/iCal share/html/Ticket/Elements share/html/User t/api t/ticket

sartak at bestpractical.com sartak at bestpractical.com
Fri Mar 13 14:21:34 EDT 2009


Author: sartak
Date: Fri Mar 13 14:21:34 2009
New Revision: 18786

Added:
   rt/3.999/branches/datetime/lib/RT/DateTime/
   rt/3.999/branches/datetime/lib/RT/DateTime.pm
   rt/3.999/branches/datetime/lib/RT/DateTime/Duration.pm
Modified:
   rt/3.999/branches/datetime/Makefile.PL
   rt/3.999/branches/datetime/etc/RT_Config.pm
   rt/3.999/branches/datetime/etc/initialdata
   rt/3.999/branches/datetime/lib/RT/Action/Install.pm
   rt/3.999/branches/datetime/lib/RT/Action/UpdateTicket.pm
   rt/3.999/branches/datetime/lib/RT/Condition/BeforeDue.pm
   rt/3.999/branches/datetime/lib/RT/Condition/Overdue.pm
   rt/3.999/branches/datetime/lib/RT/Config.pm
   rt/3.999/branches/datetime/lib/RT/Crypt/GnuPG.pm
   rt/3.999/branches/datetime/lib/RT/Date.pm
   rt/3.999/branches/datetime/lib/RT/Interface/Email.pm
   rt/3.999/branches/datetime/lib/RT/Interface/Web.pm
   rt/3.999/branches/datetime/lib/RT/Model/Attachment.pm
   rt/3.999/branches/datetime/lib/RT/Model/Ticket.pm
   rt/3.999/branches/datetime/lib/RT/Model/TicketCollection.pm
   rt/3.999/branches/datetime/lib/RT/Model/Transaction.pm
   rt/3.999/branches/datetime/lib/RT/Model/User.pm
   rt/3.999/branches/datetime/lib/RT/Record.pm
   rt/3.999/branches/datetime/lib/RT/Report/Tickets.pm
   rt/3.999/branches/datetime/lib/RT/ScripAction/CreateTickets.pm
   rt/3.999/branches/datetime/lib/RT/ScripAction/EscalatePriority.pm
   rt/3.999/branches/datetime/lib/RT/ScripAction/LinearEscalate.pm
   rt/3.999/branches/datetime/lib/RT/Shredder/Plugin/Users.pm
   rt/3.999/branches/datetime/sbin/rt-email-dashboards
   rt/3.999/branches/datetime/share/html/Approvals/Elements/PendingMyApproval
   rt/3.999/branches/datetime/share/html/Dashboards/Subscription.html
   rt/3.999/branches/datetime/share/html/Elements/ColumnMap
   rt/3.999/branches/datetime/share/html/Elements/MyReminders
   rt/3.999/branches/datetime/share/html/Elements/RT__Model__Ticket/ColumnMap
   rt/3.999/branches/datetime/share/html/Install/Global.html
   rt/3.999/branches/datetime/share/html/NoAuth/iCal/dhandler
   rt/3.999/branches/datetime/share/html/Search/Results.rdf
   rt/3.999/branches/datetime/share/html/Search/Results.tsv
   rt/3.999/branches/datetime/share/html/Ticket/Elements/EditDates
   rt/3.999/branches/datetime/share/html/Ticket/Elements/Reminders
   rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowAttachments
   rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowDates
   rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowTransaction
   rt/3.999/branches/datetime/share/html/User/Prefs.html
   rt/3.999/branches/datetime/t/api/date.t
   rt/3.999/branches/datetime/t/api/ticket.t
   rt/3.999/branches/datetime/t/ticket/search_by_txn.t

Log:
Pull my datetime refactoring into a branch

Modified: rt/3.999/branches/datetime/Makefile.PL
==============================================================================
--- rt/3.999/branches/datetime/Makefile.PL	(original)
+++ rt/3.999/branches/datetime/Makefile.PL	Fri Mar 13 14:21:34 2009
@@ -41,6 +41,7 @@
     'File::Glob'                 => 0,
     'Devel::StackTrace'          => '1.19',
     'Text::Naming::Convention'   => 0,
+    'DateTime'                   => '0.46',
 );
 
 features(

Modified: rt/3.999/branches/datetime/etc/RT_Config.pm
==============================================================================
--- rt/3.999/branches/datetime/etc/RT_Config.pm	(original)
+++ rt/3.999/branches/datetime/etc/RT_Config.pm	Fri Mar 13 14:21:34 2009
@@ -81,14 +81,14 @@
 
 set($MinimumPasswordLength , "5");
 
-=item C<$Timezone>
+=item C<$TimeZone>
 
-C<$Timezone> is used to convert times entered by users into GMT and back again
-It should be set to a timezone recognized by your local unix box.
+C<$TimeZone> is used to convert times entered by users into GMT and back again
+It should be set to a time zone recognized by L<DateTime::TimeZone>.
 
 =cut
 
-set($Timezone , 'US/Eastern');
+set($TimeZone, 'America/New_York');
 
 =back
 
@@ -1280,18 +1280,19 @@
 
 =item C<$DateTimeFormat>
 
-You can choose date and time format.  See "Output formatters"
-section in perldoc F<lib/RT/Date.pm> for more options.  This option can
-be overridden by users in their preferences.
+You can choose date and time format. This takes a L<DateTime/strftime> format
+specification. See L<DateTime/strftime_Patterns> for a full list of variables.
+
+This option can be overridden by users in their preferences.
+
 Some examples:
 
-C<set($DateTimeFormat, { Format => 'ISO', Seconds => 0 });>
-C<set($DateTimeFormat, 'RFC2822');>
-C<set($DateTimeFormat, { Format => 'RFC2822', Seconds => 0, DayOfWeek => 0 });>
+C<set($DateTimeFormat, '%a, %d %b %Y %H:%M:%S %z');> # RFC2822
+C<set($DateTimeFormat, '%Y-%m-%d %H:%M:%S');> # ISO
 
 =cut
 
-set($DateTimeFormat, 'DefaultFormat');
+set($DateTimeFormat, '%Y-%m-%d %H:%M:%S');
 
 # Next two options are for Time::ParseDate
 

Modified: rt/3.999/branches/datetime/etc/initialdata
==============================================================================
--- rt/3.999/branches/datetime/etc/initialdata	(original)
+++ rt/3.999/branches/datetime/etc/initialdata	Fri Mar 13 14:21:34 2009
@@ -231,7 +231,7 @@
        content     => 'RT-Attach-Message: yes
 
 
-{$transaction->created_as_string}: Request {$ticket->id} was acted upon.
+{$transaction->created}: Request {$ticket->id} was acted upon.
 Transaction: {$transaction->description}
        Queue: {$ticket->queue->name}
      Subject: {$transaction->subject || $ticket->subject || "(No subject given)"}

Modified: rt/3.999/branches/datetime/lib/RT/Action/Install.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Action/Install.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Action/Install.pm	Fri Mar 13 14:21:34 2009
@@ -136,8 +136,8 @@
         hints is
               'which port your web server will listen to, e.g. 8080',    #loc
         default is defer { RT->config->get( 'web_port' ) };
-    param timezone =>
-        label is 'Timezone',                                   #loc
+    param time_zone =>
+        label is 'Time Zone',                                   #loc
         render as 'Select',
         available are defer {
                 my %map = ( '' => 'System Default' );

Modified: rt/3.999/branches/datetime/lib/RT/Action/UpdateTicket.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Action/UpdateTicket.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Action/UpdateTicket.pm	Fri Mar 13 14:21:34 2009
@@ -30,13 +30,8 @@
         my $value = $self->argument_value($field);
         if ( defined $value ) {
 
-            # convert date to be as utc
-            my $date = RT::Date->new();
-            $date->set(
-                format => 'unknown',
-                value  => $value,
-            );
-
+            # convert date to be as UTC
+            my $date = RT::Date->new_from_string($value);
             $self->argument_value( $field, $date->iso );
         }
     }

Modified: rt/3.999/branches/datetime/lib/RT/Condition/BeforeDue.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Condition/BeforeDue.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Condition/BeforeDue.pm	Fri Mar 13 14:21:34 2009
@@ -66,8 +66,8 @@
 
     my $cur = RT::Date->new( RT->system_user );
     $cur->set_to_now();
-    my $due = $self->ticket_obj->due_obj;
-    return (undef) if $due->unix <= 0;
+    my $due = $self->ticket_obj->due;
+    return (undef) if $due->epoch <= 0;
 
     my $diff = $due->diff($cur);
     if ( $diff >= 0 and $diff <= $elapse ) {

Modified: rt/3.999/branches/datetime/lib/RT/Condition/Overdue.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Condition/Overdue.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Condition/Overdue.pm	Fri Mar 13 14:21:34 2009
@@ -68,8 +68,8 @@
 
 sub is_applicable {
     my $self = shift;
-    if (    $self->ticket_obj->due_obj->unix > 0
-        and $self->ticket_obj->due_obj->unix < time() )
+    if (    $self->ticket_obj->due->epoch > 0
+        and $self->ticket_obj->due->epoch < time() )
     {
         return (1);
     } else {

Modified: rt/3.999/branches/datetime/lib/RT/Config.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Config.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Config.pm	Fri Mar 13 14:21:34 2009
@@ -278,16 +278,11 @@
     DateTimeFormat => {
         section         => 'Locale',                 #loc
         overridable     => 1,
-        widget          => '/Widgets/Form/Select',
+        widget          => '/Widgets/Form/String',
         widget_arguments => {
             description => 'Date format',            #loc
-            values       => [qw(default_format RFC2822 ISO W3CDTF)],
-            values_label => {
-                default_format => 'Tue Dec 25 21:59:12 1995',           #loc
-                RFC2822       => 'Tue, 25 Dec 1995 21:59:12 -0300',    #loc
-                ISO           => '1995-11-25 21:59:12',                #loc
-                W3CDTF        => '1995-11-25T21:59:12Z',               #loc
-            },
+            hints =>
+"Use a strftime format string" #loc
         },
     },
     EmailFrequency => {

Modified: rt/3.999/branches/datetime/lib/RT/Crypt/GnuPG.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Crypt/GnuPG.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Crypt/GnuPG.pm	Fri Mar 13 14:21:34 2009
@@ -2224,16 +2224,11 @@
     # never
     return $value unless $value;
 
-    require RT::Date;
-    my $obj = RT::Date->new( current_user => RT->system_user );
-
-    # unix time
-    if ( $value =~ /^\d+$/ ) {
-        $obj->set( value => $value );
-    } else {
-        $obj->set( format => 'unknown', value => $value, timezone => 'utc' );
-    }
-    return $obj;
+    return RT::DateTime->new_from_string(
+        $value,
+        current_user => RT->system_user,
+        time_zone    => 'UTC',
+    );
 }
 
 sub delete_key {

Modified: rt/3.999/branches/datetime/lib/RT/Date.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Date.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Date.pm	Fri Mar 13 14:21:34 2009
@@ -173,7 +173,7 @@
             #now that we've parsed it, deal with the case where everything was 0
             return $self->unix(0) if $mon < 0 || $mon > 11;
 
-            my $tz = lc $args{'format'} eq 'datemanip' ? 'user' : 'utc';
+            my $tz = lc $args{'format'} eq 'datemanip' ? 'user' : 'UTC';
             $self->unix( $self->time_local( $tz, $sec, $min, $hours, $mday, $mon, $year ) );
 
             $self->unix(0) unless $self->unix > 0;
@@ -223,7 +223,7 @@
     return $_[0]->unix(time);
 }
 
-=head2 set_to_midnight [timezone => 'utc']
+=head2 set_to_midnight [timezone => 'UTC']
 
 Sets the date to midnight (at the beginning of the day).
 Returns the unixtime at midnight.
@@ -715,7 +715,7 @@
         date => 1,
         time => 1,
         @_,
-        timezone    => 'utc',
+        timezone    => 'UTC',
         seconds     => 1,
         day_of_week => 1,
     );
@@ -834,9 +834,9 @@
 
 If you pass C<$offset> as ninth argument, it's used instead of
 C<$context>. It's done such way as code 
-C<$self->time_local('utc', $self->localtime('server'))> doesn't
+C<$self->time_local('UTC', $self->localtime('server'))> doesn't
 makes much sense and most probably would produce unexpected
-result, so the method ignore 'utc' context and uses offset
+result, so the method ignore 'UTC' context and uses offset
 returned by L<Localtime> method.
 
 =cut
@@ -869,7 +869,7 @@
 
 Returns the timezone name.
 
-Takes one argument, C<$context> argument which could be C<user>, C<server> or C<utc>.
+Takes one argument, C<$context> argument which could be C<user>, C<server> or C<UTC>.
 
 =over
 
@@ -881,7 +881,7 @@
 
 If context is C<server> it returns value of the C<timezone> RT config option.
 
-=item  utc
+=item UTC
 
 If both server's and user's timezone names are undefined returns 'UTC'.
 
@@ -893,11 +893,11 @@
     my $self    = shift;
     my $context = lc(shift);
 
-    $context = 'utc' unless $context =~ /^(?:utc|server|user)$/i;
+    $context = 'UTC' unless $context =~ /^(?:UTC|server|user)$/i;
 
     my $tz;
     if ( $context eq 'user' ) {
-        $tz = $self->current_user->user_object->timezone;
+        $tz = $self->current_user->user_object->time_zone;
     } elsif ( $context eq 'server' ) {
         $tz = RT->config->get('Timezone');
     } else {

Added: rt/3.999/branches/datetime/lib/RT/DateTime.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/datetime/lib/RT/DateTime.pm	Fri Mar 13 14:21:34 2009
@@ -0,0 +1,121 @@
+use strict;
+use warnings;
+
+package RT::DateTime;
+use base 'Jifty::DateTime';
+
+use RT::DateTime::Duration;
+
+use constant duration_class => 'RT::DateTime::Duration';
+
+sub _stringify { shift->config_format }
+
+sub is_unset { shift->epoch == 0 }
+
+sub age {
+    my $self  = shift;
+    my $until = shift || RT::DateTime->now;
+
+    return $until - $self;
+}
+
+sub _canonicalize_time_zone {
+    my $self    = shift;
+    my $tz      = shift;
+    my $default = shift || 'UTC';
+
+    if (lc($tz) eq 'user') {
+        $tz = $self->current_user->user_object->time_zone;
+    }
+
+    # if the user time zone is requested and the user has none, use the server's
+    # time zone
+    if (!$tz || lc($tz) eq 'server' || lc($tz) eq 'system') {
+        $tz = RT->config->get('TimeZone');
+    }
+
+    return $tz || $default;
+}
+
+sub new {
+    my $self = shift;
+    my %args = @_;
+
+    $args{time_zone} = $self->_canonicalize_time_zone($args{time_zone})
+        if defined $args{time_zone};
+
+    return $self->SUPER::new(%args);
+}
+
+sub set_time_zone {
+    my $self = shift;
+    my $tz   = shift;
+
+    return $self->SUPER::set_time_zone($self->_canonicalize_time_zone($tz));
+}
+
+sub new_from_string {
+    my $class  = shift;
+    my $string = shift;
+    my %args = (
+        time_zone => undef,
+        @_,
+    );
+
+    if ($args{time_zone}) {
+        $args{time_zone} = $class->_canonicalize_time_zone($args{time_zone});
+    }
+
+    my $dt = $class->SUPER::new_from_string($string, %args);
+
+    if (!defined($dt)) {
+        return RT::DateTime->from_epoch(epoch => 0);
+    }
+
+    return $dt;
+}
+
+sub strftime {
+    my $self = shift;
+
+    return 'unset' if $self->is_unset;
+    return $self->SUPER::strftime(@_);
+}
+
+sub _canonicalize_self {
+    my $self = shift;
+    my %args = (
+        time_zone => undef,
+        @_,
+    );
+
+    my $clone;
+    if ($args{time_zone}) {
+        $clone = $self->clone;
+        $clone->set_time_zone($args{time_zone});
+        return $clone;
+    }
+
+    return $self;
+}
+
+sub rfc2822 {
+    my $self = _canonicalize_self(@_);
+
+    return $self->strftime('%a, %d %b %Y %H:%M:%S %z');
+}
+
+sub iso {
+    my $self = _canonicalize_self(@_);
+
+    return $self->strftime('%Y-%m-%d %H:%M:%S');
+}
+
+sub config_format {
+    my $self = _canonicalize_self(@_);
+
+    return $self->strftime(RT->config->get('DateTimeFormat'));
+}
+
+1;
+

Added: rt/3.999/branches/datetime/lib/RT/DateTime/Duration.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/datetime/lib/RT/DateTime/Duration.pm	Fri Mar 13 14:21:34 2009
@@ -0,0 +1,50 @@
+use strict;
+use warnings;
+
+package RT::DateTime::Duration;
+use base 'DateTime::Duration';
+
+use overload (
+    q{""} => '_stringify',
+);
+
+sub _stringify {
+    my $self = shift;
+
+    my %delta = $self->deltas;
+
+    my ($count, $unit);
+
+    if ($delta{months} >= 12) {
+        ($count, $unit) = ($self->in_units('years'), 'years');
+    }
+    elsif ($delta{months}) {
+        ($count, $unit) = ($self->in_units('months'), 'months');
+    }
+    elsif ($delta{days} >= 7) {
+        ($count, $unit) = ($self->in_units('weeks'), 'weeks');
+    }
+    elsif ($delta{days}) {
+        ($count, $unit) = ($self->in_units('days'), 'days');
+    }
+    elsif ($delta{minutes} >= 60) {
+        ($count, $unit) = ($self->in_units('hours'), 'hours');
+    }
+    elsif ($delta{minutes}) {
+        ($count, $unit) = ($self->in_units('minutes'), 'min');
+    }
+    else {
+        ($count, $unit) = ($self->in_units('seconds'), 'sec');
+    }
+
+    if ($self->is_negative) {
+        return _("%1 %2 ago", $count, $unit);
+    }
+    else {
+        return _("%1 %2", $count, $unit);
+    }
+
+}
+
+1;
+

Modified: rt/3.999/branches/datetime/lib/RT/Interface/Email.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Interface/Email.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Interface/Email.pm	Fri Mar 13 14:21:34 2009
@@ -362,7 +362,7 @@
         require RT::Date;
         my $date = RT::Date->new( current_user => RT->system_user );
         $date->set_to_now;
-        $args{'entity'}->head->set( 'date', $date->rfc2822( timezone => 'server' ) );
+        $args{'entity'}->head->set( 'date', $date->rfc2822( time_zone => 'server' ) );
     }
 
     my $mail_command = RT->config->get('MailCommand');

Modified: rt/3.999/branches/datetime/lib/RT/Interface/Web.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Interface/Web.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Interface/Web.pm	Fri Mar 13 14:21:34 2009
@@ -394,13 +394,11 @@
 
     my $due;
     if ( defined $ARGS{'Due'} and $ARGS{'Due'} =~ /\S/ ) {
-        $due = new RT::Date( current_user => Jifty->web->current_user );
-        $due->set( format => 'unknown', value => $ARGS{'Due'} );
+        $due = RT::DateTime->new_from_string($ARGS{'Due'});
     }
     my $starts;
     if ( defined $ARGS{'Starts'} and $ARGS{'Starts'} =~ /\S/ ) {
-        $starts = new RT::Date( current_user => Jifty->web->current_user );
-        $starts->set( format => 'unknown', value => $ARGS{'Starts'} );
+        $starts = RT::DateTime->new_from_string($ARGS{'Starts'});
     }
 
     my $sigless = RT::Interface::Web::strip_content(
@@ -812,12 +810,7 @@
 sub parse_date_to_iso {
     my $date = shift;
 
-    my $date_obj = RT::Date->new();
-    $date_obj->set(
-        format => 'unknown',
-        value  => $date
-    );
-    return ( $date_obj->iso );
+    return RT::DateTime->new_from_string($date)->iso;
 }
 
 
@@ -1342,15 +1335,12 @@
 
         my ( $code, $msg );
 
-        my $DateObj = RT::Date->new();
-        $DateObj->set(
-            format => 'unknown',
-            value  => $args_ref->{ $field . '_date' }
-        );
+        my $date = $args_ref->{ $field . '_date' };
+        my $DateObj = RT::DateTime->new_from_string($date);
 
         my $obj = $field . "_obj";
-        if (    ( defined $DateObj->unix )
-            and ( $DateObj->unix != $Ticket->$obj()->unix() ) )
+        if (    ( defined $DateObj->epoch )
+            and ( $DateObj->epoch != $Ticket->$obj->epoch ) )
         {
             my $method = "set_$field";
             my ( $code, $msg ) = $Ticket->$method( $DateObj->iso );

Modified: rt/3.999/branches/datetime/lib/RT/Model/Attachment.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Model/Attachment.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Model/Attachment.pm	Fri Mar 13 14:21:34 2009
@@ -410,7 +410,7 @@
 
         $body =~ s/^/> /gm;
 
-        $body = '[' . $self->transaction->creator_obj->name() . ' - ' . $self->transaction->created_as_string() . "]:\n\n" . $body . "\n\n";
+        $body = '[' . $self->transaction->creator_obj->name() . ' - ' . $self->transaction->created . "]:\n\n" . $body . "\n\n";
 
     } else {
         $body = "[Non-text message not quoted]\n\n";

Modified: rt/3.999/branches/datetime/lib/RT/Model/Ticket.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Model/Ticket.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Model/Ticket.pm	Fri Mar 13 14:21:34 2009
@@ -123,7 +123,11 @@
         filters are qw( Jifty::Filter::DateTime Jifty::DBI::Filter::DateTime),
         render_as 'DateTime',
         label is _('Due');
-    column resolved         => type is 'timestamp';
+    column resolved         => type is 'timestamp',
+        filters are qw( Jifty::Filter::DateTime Jifty::DBI::Filter::DateTime),
+        render_as 'DateTime',
+        label is _('Closed');
+
     column disabled         => max_length is 6,   type is 'smallint',     default is '0';
 };
 use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata map => {
@@ -956,45 +960,6 @@
 
 
 
-=head2 due_obj
-
-  Returns an RT::Date object containing this ticket's due date
-
-=cut
-
-sub due_obj {
-    my $self = shift;
-
-    my $time = RT::Date->new();
-
-    # -1 is RT::Date slang for never
-    if ( my $due = $self->due ) {
-        $time->set( format => 'sql', value => $due );
-    } else {
-        $time->set( format => 'unix', value => -1 );
-    }
-
-    return $time;
-}
-
-
-
-=head2 resolved_obj
-
-  Returns an RT::Date object of this ticket's 'resolved' time.
-
-=cut
-
-sub resolved_obj {
-    my $self = shift;
-
-    my $time = RT::Date->new();
-    $time->set( format => 'sql', value => $self->resolved );
-    return $time;
-}
-
-
-
 =head2 set_started
 
 Takes a date in ISO format or undef
@@ -1036,78 +1001,6 @@
 
 }
 
-
-
-=head2 started_obj
-
-  Returns an RT::Date object which contains this ticket's 
-'started' time.
-
-=cut
-
-sub started_obj {
-    my $self = shift;
-
-    my $time = RT::Date->new();
-    $time->set( format => 'sql', value => $self->started );
-    return $time;
-}
-
-
-
-=head2 starts_obj
-
-  Returns an RT::Date object which contains this ticket's 
-'starts' time.
-
-=cut
-
-sub starts_obj {
-    my $self = shift;
-
-    my $time = RT::Date->new();
-    $time->set( format => 'sql', value => $self->starts );
-    return $time;
-}
-
-
-
-=head2 told_obj
-
-  Returns an RT::Date object which contains this ticket's 
-'told' time.
-
-=cut
-
-sub told_obj {
-    my $self = shift;
-
-    my $time = RT::Date->new();
-    $time->set( format => 'sql', value => $self->told );
-    return $time;
-}
-
-
-
-=head2 told_as_string
-
-A convenience method that returns told_obj->as_string
-
-TODO: This should be deprecated
-
-=cut
-
-sub told_as_string {
-    my $self = shift;
-    if ( $self->told ) {
-        return $self->told_obj->as_string();
-    } else {
-        return ("Never");
-    }
-}
-
-
-
 =head2 time_worked_as_string
 
 Returns the amount of time worked on this ticket as a Text String
@@ -2288,15 +2181,6 @@
     #Take care of the old value we really don't want to get in an ACL loop.
     # so ask the super::_value
     my $Old = $self->SUPER::_value( $args{'column'} );
-    if ( $args{'column'} =~ /due|starts|started|told/ ) {
-    # we want the real value in db, without filter
-        my $date = RT::Date->new();
-        $date->set(
-            format => 'unknown',
-            value  => $Old,
-        );
-        $Old = $date->iso;
-    }
 
     if ( $Old && $args{'value'} && $Old eq $args{'value'} ) {
 

Modified: rt/3.999/branches/datetime/lib/RT/Model/TicketCollection.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Model/TicketCollection.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Model/TicketCollection.pm	Fri Mar 13 14:21:34 2009
@@ -525,8 +525,7 @@
     die "Incorrect Meta Data for $field"
         unless ( defined $meta->[1] );
 
-    my $date = RT::Date->new();
-    $date->set( format => 'unknown', value => $value );
+    my $date = RT::DateTime->new_from_string($value);
 
     if ( $op eq "=" ) {
 
@@ -534,10 +533,9 @@
         # particular single day.  in the database, we need to check for >
         # and < the edges of that day.
 
-        $date->set_to_midnight( timezone => 'server' );
+        $date->truncate(to => 'day')->set_time_zone('server');
         my $daystart = $date->iso;
-        $date->add_day;
-        my $dayend = $date->iso;
+        my $dayend = $date->add(days => 1)->iso;
 
         $sb->open_paren;
 
@@ -625,8 +623,7 @@
         );
     }
 
-    my $date = RT::Date->new();
-    $date->set( format => 'unknown', value => $value );
+    my $date = RT::DateTime->new_from_string($value);
 
     $sb->open_paren;
     if ( $op eq "=" ) {
@@ -635,10 +632,9 @@
         # particular single day.  in the database, we need to check for >
         # and < the edges of that day.
 
-        $date->set_to_midnight( timezone => 'server' );
+        $date->truncate(to => 'day')->set_time_zone('server');
         my $daystart = $date->iso;
-        $date->add_day;
-        my $dayend = $date->iso;
+        my $dayend = $date->add(days => 1)->iso;
 
         $sb->_sql_limit(
             alias          => $sb->{_sql_transalias},

Modified: rt/3.999/branches/datetime/lib/RT/Model/Transaction.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Model/Transaction.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Model/Transaction.pm	Fri Mar 13 14:21:34 2009
@@ -560,7 +560,7 @@
         }
 
         $content =~ s/^/> /gm;
-        $content = _( "On %1, %2 wrote:", $self->created_as_string, $self->creator_obj->name ) . "\n$content\n\n";
+        $content = _( "On %1, %2 wrote:", $self->created, $self->creator_obj->name ) . "\n$content\n\n";
     }
 
     return ($content);

Modified: rt/3.999/branches/datetime/lib/RT/Model/User.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Model/User.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Model/User.pm	Fri Mar 13 14:21:34 2009
@@ -122,7 +122,7 @@
     column state    => max_length is 100, type is 'varchar(100)', default is '';
     column zip      => max_length is 16,  type is 'varchar(16)',  default is '';
     column country  => max_length is 50,  type is 'varchar(50)',  default is '';
-    column timezone => max_length is 50,  type is 'varchar(50)',  default is '';
+    column time_zone => max_length is 50,  type is 'varchar(50)',  default is '';
     column pgp_key   => type is 'text';
 
 };

Modified: rt/3.999/branches/datetime/lib/RT/Record.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Record.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Record.pm	Fri Mar 13 14:21:34 2009
@@ -345,78 +345,6 @@
 }
 
 
-
-# There is room for optimizations in most of those subs:
-
-
-sub last_updated_obj {
-    my $self = shift;
-    my $obj  = RT::Date->new();
-
-    $obj->set( format => 'sql', value => $self->last_updated );
-    return $obj;
-}
-
-
-
-sub created_obj {
-    my $self = shift;
-    my $obj  = RT::Date->new();
-
-    $obj->set( format => 'sql', value => $self->created );
-
-    return $obj;
-}
-
-
-#
-# TODO: This should be deprecated
-#
-sub age_as_string {
-    my $self = shift;
-    return ( $self->created_obj->age_as_string() );
-}
-
-
-
-# TODO this should be deprecated
-
-sub last_updated_as_string {
-    my $self = shift;
-    if ( $self->last_updated ) {
-        return ( $self->last_updated_obj->as_string() );
-
-    } else {
-        return "never";
-    }
-}
-
-
-#
-# TODO This should be deprecated
-#
-sub created_as_string {
-    my $self = shift;
-    return ( $self->created_obj->as_string() );
-}
-
-
-#
-# TODO This should be deprecated
-#
-sub long_since_update_as_string {
-    my $self = shift;
-    if ( $self->last_updated ) {
-
-        return ( $self->last_updated_obj->age_as_string() );
-
-    } else {
-        return "never";
-    }
-}
-
-
-
 #
 sub _set {
     my $self = shift;

Modified: rt/3.999/branches/datetime/lib/RT/Report/Tickets.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Report/Tickets.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Report/Tickets.pm	Fri Mar 13 14:21:34 2009
@@ -65,7 +65,7 @@
       my $type (qw(owner creator last_updated_by requestor cc admin_cc watcher))
     {
         push @fields, $type . ' ' . $_, $type . '.' . $_ foreach qw(
-          name email real_name nickname organization lang city country timezone
+          name email real_name nickname organization lang city country time_zone
         );
     }
 

Modified: rt/3.999/branches/datetime/lib/RT/ScripAction/CreateTickets.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/ScripAction/CreateTickets.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/ScripAction/CreateTickets.pm	Fri Mar 13 14:21:34 2009
@@ -685,17 +685,9 @@
     }
 
     foreach my $date qw(due starts started resolved) {
-        my $dateobj = RT::Date->new;
         next unless $args{$date};
-        if ( $args{$date} =~ /^\d+$/ ) {
-            $dateobj->set( format => 'unix', value => $args{$date} );
-        } else {
-            eval { $dateobj->set( format => 'iso', value => $args{$date} ); };
-            if ( $@ or $dateobj->unix <= 0 ) {
-                $dateobj->set( format => 'unknown', value => $args{$date} );
-            }
-        }
-        $args{$date} = $dateobj->iso;
+        my $dt = RT::DateTime->new_from_string(delete $args{$date});
+        $args{$date} = $dt->iso if $dt;
     }
 
     $args{'requestor'} ||= $self->ticket_obj->role_group("requestor")->member_emails
@@ -935,10 +927,10 @@
     $string .= "UpdateType: correspond\n";
     $string .= "Content: \n";
     $string .= "ENDOFCONTENT\n";
-    $string .= "Due: " . $t->due_obj->as_string . "\n";
-    $string .= "starts: " . $t->starts_obj->as_string . "\n";
-    $string .= "Started: " . $t->started_obj->as_string . "\n";
-    $string .= "Resolved: " . $t->resolved_obj->as_string . "\n";
+    $string .= "Due: " . $t->due . "\n";
+    $string .= "Starts: " . $t->starts . "\n";
+    $string .= "Started: " . $t->started . "\n";
+    $string .= "Resolved: " . $t->resolved . "\n";
     $string .= "Owner: " . $t->owner->name . "\n";
     $string .= "Requestor: " . $t->role_group("requestor")->member_emails_as_string . "\n";
     $string .= "Cc: " . $t->role_group("cc")->member_emails_as_string . "\n";
@@ -986,10 +978,10 @@
     $string .= "Queue: " . $t->queue . "\n";
     $string .= "Subject: " . $t->subject . "\n";
     $string .= "Status: " . $t->status . "\n";
-    $string .= "Due: " . $t->due_obj->unix . "\n";
-    $string .= "starts: " . $t->starts_obj->unix . "\n";
-    $string .= "Started: " . $t->started_obj->unix . "\n";
-    $string .= "Resolved: " . $t->resolved_obj->unix . "\n";
+    $string .= "Due: " . $t->due->epoch . "\n";
+    $string .= "Starts: " . $t->starts->epoch . "\n";
+    $string .= "Started: " . $t->started->epoch . "\n";
+    $string .= "Resolved: " . $t->resolved->epoch . "\n";
     $string .= "Owner: " . $t->owner . "\n";
     $string .= "Requestor: " . $t->role_group("requestor")->member_emails_as_string . "\n";
     $string .= "Cc: " . $t->role_group("cc")->member_emails_as_string . "\n";

Modified: rt/3.999/branches/datetime/lib/RT/ScripAction/EscalatePriority.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/ScripAction/EscalatePriority.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/ScripAction/EscalatePriority.pm	Fri Mar 13 14:21:34 2009
@@ -95,11 +95,11 @@
     }
 
     #compute the number of days until the ticket is due
-    my $due = $self->ticket_obj->due_obj();
+    my $due = $self->ticket_obj->due;
 
     # If we don't have a due date, adjust the priority by one
     # until we hit the final priority
-    if ( $due->unix() < 1 ) {
+    if ( $due->epoch < 1 ) {
         if ( $self->ticket_obj->priority > $self->ticket_obj->final_priority ) {
             $self->{'prio'} = ( $self->ticket_obj->priority - 1 );
             return 1;

Modified: rt/3.999/branches/datetime/lib/RT/ScripAction/LinearEscalate.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/ScripAction/LinearEscalate.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/ScripAction/LinearEscalate.pm	Fri Mar 13 14:21:34 2009
@@ -157,7 +157,7 @@
 
     my $ticket = $self->ticket_obj;
 
-    my $due = $ticket->due_obj->unix;
+    my $due = $ticket->due->epoch;
     unless ( $due > 0 ) {
         Jifty->log->debug('Due is not set. Not escalating.');
         return 1;
@@ -187,8 +187,8 @@
     # now we know we have a due date. for every day that passes,
     # increment priority according to the formula
 
-    my $starts = $ticket->starts_obj->unix;
-    $starts = $ticket->created_obj->unix unless $starts > 0;
+    my $starts = $ticket->starts->epoch;
+    $starts = $ticket->created->epoch unless $starts > 0;
     my $now = time;
 
     # do nothing if we didn't reach starts or created date

Modified: rt/3.999/branches/datetime/lib/RT/Shredder/Plugin/Users.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/Shredder/Plugin/Users.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/Shredder/Plugin/Users.pm	Fri Mar 13 14:21:34 2009
@@ -132,7 +132,7 @@
 
     # XXX: we want preload only things we need, but later while
     # logging we need all data, TODO envestigate this
-    # $objs->columns(qw(id name email lang timezone
+    # $objs->columns(qw(id name email lang time_zone
     #                   creator Created last_updated last_updated_by));
     if ( my $s = $self->{'opt'}{'status'} ) {
         if ( $s eq 'any' ) {

Modified: rt/3.999/branches/datetime/sbin/rt-email-dashboards
==============================================================================
--- rt/3.999/branches/datetime/sbin/rt-email-dashboards	(original)
+++ rt/3.999/branches/datetime/sbin/rt-email-dashboards	Fri Mar 13 14:21:34 2009
@@ -121,7 +121,7 @@
         next;
     }
 
-    my ($hour, $dow, $dom) = hour_dow_dom_in($user->timezone || RT->config->get('Timezone'));
+    my ($hour, $dow, $dom) = hour_dow_dom_in($user->time_zone || RT->config->get('TimeZone'));
     $hour .= ':00';
     debug "Checking %1's subscriptions: hour %2, dow %3, dom %4",
           $user->name, $hour, $dow, $dom;
@@ -494,7 +494,7 @@
 how often that dashboard is sent and how it's displayed.
 
 Each subscription has an hour, and possibly day of week or day of month. These
-are taken to be in the user's timezone if available, UTC otherwise.
+are taken to be in the user's time zone if available, UTC otherwise.
 
 =head1 SETUP
 

Modified: rt/3.999/branches/datetime/share/html/Approvals/Elements/PendingMyApproval
==============================================================================
--- rt/3.999/branches/datetime/share/html/Approvals/Elements/PendingMyApproval	(original)
+++ rt/3.999/branches/datetime/share/html/Approvals/Elements/PendingMyApproval	Fri Mar 13 14:21:34 2009
@@ -63,9 +63,9 @@
 <input type="checkbox" class="checkbox" value="1" name="show_rejected" <% defined($ARGS{'show_rejected'}) && $ARGS{'show_rejected'} && qq[checked="checked"] |n%> /> <&|/l&>Show denied requests</&><br />
 <input type="checkbox" class="checkbox" value="1" name="show_dependent" <% defined($ARGS{'show_dependent'}) && $ARGS{'show_dependent'} && qq[checked="checked"] |n%> /> <&|/l&>Show requests awaiting other approvals</&><br />
 
-<&|/l,"<input size='15' value='".($Created_before->unix > 0 &&$Created_before->iso)."' name='created_before' id='CreatedBefore' class='datetime' />"&>Only show approvals for requests Created before %1</&><br />
+<&|/l,"<input size='15' value='".($Created_before->epoch > 0 &&$Created_before->iso)."' name='created_before' id='CreatedBefore' class='datetime' />"&>Only show approvals for requests Created before %1</&><br />
 
-<&|/l, "<input size='15' value='".( $Created_after->unix >0 && $Created_after->iso)."' name='created_after' id='CreatedAfter' class='datetime' />"&>Only show approvals for requests Created after %1</&>
+<&|/l, "<input size='15' value='".( $Created_after->epoch >0 && $Created_after->iso)."' name='created_after' id='CreatedAfter' class='datetime' />"&>Only show approvals for requests Created after %1</&>
 </&>
 
 <%init>

Modified: rt/3.999/branches/datetime/share/html/Dashboards/Subscription.html
==============================================================================
--- rt/3.999/branches/datetime/share/html/Dashboards/Subscription.html	(original)
+++ rt/3.999/branches/datetime/share/html/Dashboards/Subscription.html	Fri Mar 13 14:21:34 2009
@@ -146,7 +146,7 @@
     <option value="<% $formatted %>" <%$selected%>><% $formatted %></option>
 % }
 </select>
-(in <%$timezone%>)
+(in <%$time_zone%>)
 </td></tr>
 <tr><td class="label">
 <&|/l&>Rows</&>:
@@ -185,7 +185,7 @@
 my ($title, @results);
 my ($val, $msg);
 my $Loaded = 0;
-my $timezone = Jifty->web->current_user->user_object->timezone || RT->config->get('Timezone');
+my $time_zone = Jifty->web->current_user->user_object->time_zone || RT->config->get('TimeZone');
 
 use RT::Dashboard;
 my $dashboard_obj = RT::Dashboard->new( current_user => Jifty->web->current_user );

Modified: rt/3.999/branches/datetime/share/html/Elements/ColumnMap
==============================================================================
--- rt/3.999/branches/datetime/share/html/Elements/ColumnMap	(original)
+++ rt/3.999/branches/datetime/share/html/Elements/ColumnMap	Fri Mar 13 14:21:34 2009
@@ -65,12 +65,12 @@
     created => {
         attribute => 'Created',
         title     => 'Created', # loc
-        value     => sub  { return $_[0]->created_obj->as_string }
+        value     => sub  { return $_[0]->created }
     },
     created_relative => {
         attribute => 'Created',
         title     => 'Created', # loc
-        value     => sub  { return $_[0]->created_obj->age_as_string }
+        value     => sub  { return $_[0]->created->age }
     },
     created_by => {
         attribute => 'CreatedBy',
@@ -80,12 +80,12 @@
     last_updated => {
         attribute => 'last_updated',
         title     => 'Last Updated', # loc
-        value     => sub  { return $_[0]->last_updated_obj->as_string }
+        value     => sub  { return $_[0]->last_updated }
     },
     last_updated_relative => {
         attribute => 'last_updated',
         title     => 'Last Updated', # loc
-        value     => sub  { return $_[0]->last_updated_obj->age_as_string }
+        value     => sub  { return $_[0]->last_updated->age }
     },
     last_updated_by => {
         attribute => 'last_updated_by',

Modified: rt/3.999/branches/datetime/share/html/Elements/MyReminders
==============================================================================
--- rt/3.999/branches/datetime/share/html/Elements/MyReminders	(original)
+++ rt/3.999/branches/datetime/share/html/Elements/MyReminders	Fri Mar 13 14:21:34 2009
@@ -57,7 +57,7 @@
 <tr class="<%$i%2 ? 'evenline' : 'oddline'%>"><td><a href="<%RT->config->get('WebPath')%>/Ticket/Display.html?id=<%$ticket->id%>"><%$reminder->subject%></a><br />
 <blockquote>
 #<%$ticket->id%>: <%$ticket->subject%><br />
-<%$reminder->owner_obj->name %>  <%$reminder->due_obj->unix >0 ? '&bull; '.$reminder->due_obj->age_as_string : '' |n %>
+<%$reminder->owner_obj->name %>  <%$reminder->due->epoch >0 ? '&bull; '.$reminder->due->age : '' |n %>
 </blockquote>
 </td>
 </tr>

Modified: rt/3.999/branches/datetime/share/html/Elements/RT__Model__Ticket/ColumnMap
==============================================================================
--- rt/3.999/branches/datetime/share/html/Elements/RT__Model__Ticket/ColumnMap	(original)
+++ rt/3.999/branches/datetime/share/html/Elements/RT__Model__Ticket/ColumnMap	Fri Mar 13 14:21:34 2009
@@ -181,60 +181,60 @@
     starts_relative => {
         title     => 'Starts', # loc
         attribute => 'starts',
-        value     => sub  { return $_[0]->starts_obj->age_as_string }
+        value     => sub  { return $_[0]->starts->age }
     },
     started_relative => {
         title     => 'Started', # loc
         attribute => 'Started',
-        value     => sub  { return $_[0]->started_obj->age_as_string }
+        value     => sub  { return $_[0]->started->age }
     },
     told_relative => {
         title     => 'Told', # loc
         attribute => 'Told',
-        value     => sub  { return $_[0]->told_obj->age_as_string }
+        value     => sub  { return $_[0]->told->age }
     },
     due_relative => {
         title     => 'Due', # loc
         attribute => 'Due',
         value     => sub  { 
-            my $date = $_[0]->due_obj;
+            my $date = $_[0]->due;
             # Highlight the date if it was due in the past, and it's still active
-            if ( $date && $date->unix > 0 && $date->diff < 0 && $_[0]->queue->status_schema->is_active($_[0]->status)) {
-                return (\'<span class="overdue">' , $date->age_as_string , \'</span>');
+            if ( $date && $date->epoch > 0 && $date->diff < 0 && $_[0]->queue->status_schema->is_active($_[0]->status)) {
+                return (\'<span class="overdue">' , $date->age , \'</span>');
             } else {
-                return $date->age_as_string;
+                return $date->age;
             }
         }
     },
     resolved_relative => {
         title     => 'Resolved', # loc
         attribute => 'resolved',
-        value     => sub  { return $_[0]->resolved_obj->age_as_string }
+        value     => sub  { return $_[0]->resolved->age }
     },
     starts => {
         title     => 'Starts', # loc
         attribute => 'starts',
-        value     => sub  { return $_[0]->starts_obj->as_string }
+        value     => sub  { return $_[0]->starts }
     },
     started => {
         title     => 'Started', # loc
         attribute => 'Started',
-        value     => sub  { return $_[0]->started_obj->as_string }
+        value     => sub  { return $_[0]->started }
     },
     told => {
         title     => 'Told', # loc
         attribute => 'Told',
-        value     => sub  { return $_[0]->told_obj->as_string }
+        value     => sub  { return $_[0]->told }
     },
     due => {
         title     => 'Due', # loc
         attribute => 'Due',
-        value     => sub  { return $_[0]->due_obj->as_string }
+        value     => sub  { return $_[0]->due }
     },
     resolved => {
         title     => 'Resolved', # loc
         attribute => 'resolved',
-        value     => sub  { return $_[0]->resolved_obj->as_string }
+        value     => sub  { return $_[0]->resolved }
     },
     update_status => {
         title => 'New messages', # loc

Modified: rt/3.999/branches/datetime/share/html/Install/Global.html
==============================================================================
--- rt/3.999/branches/datetime/share/html/Install/Global.html	(original)
+++ rt/3.999/branches/datetime/share/html/Install/Global.html	Fri Mar 13 14:21:34 2009
@@ -51,10 +51,10 @@
 
 <p><&|/l&>When RT sends an email it sets the From: and Reply-To: headers so users can add to the conversation by just hitting Reply in their mail client.  It uses different addresses for Replies and Comments.  These can be changed for each of your queues.  These addresses will need to be configured to use the <tt>rt-mailgate</tt> program.</&></p>
 
-<p><&|/l&>By default, RT will use the timezone of your system.  This lets you set a global default for the display of dates and times in RT.  Your users can choose a different Timezone in their preferences.</&></p>
+<p><&|/l&>By default, RT will use the time zone of your system.  This lets you set a global default for the display of dates and times in RT.  Your users can choose a different time zone in their preferences.</&></p>
 
 
-<& Elements/Form, fields => [qw/comment_address correspond_address timezone/],
+<& Elements/Form, fields => [qw/comment_address correspond_address time_zone/],
     next => $next,
     next_label => _('Next: ') . _($next_label),
     previous => '/Install/Sendmail.html',

Modified: rt/3.999/branches/datetime/share/html/NoAuth/iCal/dhandler
==============================================================================
--- rt/3.999/branches/datetime/share/html/NoAuth/iCal/dhandler	(original)
+++ rt/3.999/branches/datetime/share/html/NoAuth/iCal/dhandler	Fri Mar 13 14:21:34 2009
@@ -86,9 +86,9 @@
 $feed->add_properties('prodid'   => ["-//" . RT->config->get('rtname') ."//"]);
 
 while (my $t = $tickets->next) {
-    next unless $t->due_obj->unix > 0;
+    next unless $t->due->epoch > 0;
 
-    my $starttime = $t->starts_obj->unix > 0 ? $t->starts_obj : $t->created_obj;
+    my $starttime = $t->starts->epoch > 0 ? $t->starts : $t->created;
 
     my $now = RT::Date->new; $now->set_to_now;
     my $start = Data::ICal::Entry::Event->new;
@@ -97,8 +97,8 @@
         url       => RT->config->get('WebURL') . "?q=".$t->id,
         organizer => $t->owner_obj->name,
         dtstamp   => $now->iCal,
-        created   => $t->created_obj->iCal,
-       'last-modified' => $t->last_updated_obj->iCal,
+        created   => $t->created->iCal,
+       'last-modified' => $t->last_updated->iCal,
     ) for $start, $end;
 
     $start->add_properties(
@@ -108,8 +108,8 @@
     );
     $end->add_properties(
         summary   => "Due: ".$t->subject,
-        dtstart   => $t->due_obj->iCalDate,
-        dtend     => $t->due_obj->iCalDate,
+        dtstart   => $t->due->iCalDate,
+        dtend     => $t->due->iCalDate,
     );
 
     $feed->add_entry($start);

Modified: rt/3.999/branches/datetime/share/html/Search/Results.rdf
==============================================================================
--- rt/3.999/branches/datetime/share/html/Search/Results.rdf	(original)
+++ rt/3.999/branches/datetime/share/html/Search/Results.rdf	Fri Mar 13 14:21:34 2009
@@ -90,7 +90,7 @@
           description => $Ticket->transactions->first->content,
           dc => {
             creator  => $creator_str,
-            date => $Ticket->created_obj->rfc2822,
+            date => $Ticket->created->rfc2822,
           },
           guid        => $Ticket->queue . '_' . $Ticket->id,
         );

Modified: rt/3.999/branches/datetime/share/html/Search/Results.tsv
==============================================================================
--- rt/3.999/branches/datetime/share/html/Search/Results.tsv	(original)
+++ rt/3.999/branches/datetime/share/html/Search/Results.tsv	Fri Mar 13 14:21:34 2009
@@ -71,17 +71,17 @@
 
 my @attrs = qw( id queue_obj->name subject status time_estimated time_worked time_left priority final_priority owner_obj->name 
                 requestors->member_emails_as_string cc->member_emails_as_string admin_cc->member_emails_as_string
-                due_obj->iso told_obj->iso created_obj->iso resolved_obj->iso last_updated_obj->iso);
+                due->iso told->iso created->iso resolved->iso last_updated->iso);
 
 $r->content_type('application/vnd.ms-excel');
 while ( my $Ticket = $Tickets->next()) {
     my $row;
     foreach my $attr (@attrs) {
-        if ($attr =~ /(.*)->iso$/ and $Ticket->$1->unix <= 0) {
+        if ($attr =~ /(.*)->iso$/ and $Ticket->$1->epoch <= 0) {
             $row->{$attr} = "";
         } else {
             my $method = '$Ticket->'.$attr.'()';
-            $method =~ s/->iso\(\)$/->iso( Timezone => 'user' )/;
+            $method =~ s/->iso\(\)$/->iso( time_zone => 'user' )/;
             $row->{$attr} = eval $method;
             if ($@) {die "Failed to find $attr - ". $@}; 
         }

Modified: rt/3.999/branches/datetime/share/html/Ticket/Elements/EditDates
==============================================================================
--- rt/3.999/branches/datetime/share/html/Ticket/Elements/EditDates	(original)
+++ rt/3.999/branches/datetime/share/html/Ticket/Elements/EditDates	Fri Mar 13 14:21:34 2009
@@ -49,11 +49,11 @@
   <tr>
     <td class="label"><&|/l&>starts</&>:</td>
     <td class="entry"><& /Elements/SelectDate, menu_prefix => 'starts', current => 0 &> 
-        (<% $ticket_obj->starts_obj->as_string %>)</td>
+        (<% $ticket_obj->starts %>)</td>
   </tr>
   <tr>
     <td class="label"><&|/l&>Started</&>:</td>
-    <td class="entry"><& /Elements/SelectDate, menu_prefix => 'started', current => 0 &> (<%$ticket_obj->started_obj->as_string %>)</td>
+    <td class="entry"><& /Elements/SelectDate, menu_prefix => 'started', current => 0 &> (<%$ticket_obj->started %>)</td>
   </tr>
 
   <tr>
@@ -61,13 +61,13 @@
       <&|/l&>Last Contact</&>:
     </td>
     <td class="entry">
-      <& /Elements/SelectDate, menu_prefix => 'told', current => 0 &> (<% $ticket_obj->told_obj->as_string %>)
+      <& /Elements/SelectDate, menu_prefix => 'told', current => 0 &> (<% $ticket_obj->told %>)
     </td>
   </tr>
   <tr>
     <td class="label"><&|/l&>Due</&>:</td>
     <td class="entry">
-      <& /Elements/SelectDate, menu_prefix => 'due', current => 0 &> (<% $ticket_obj->due_obj->as_string %>)
+      <& /Elements/SelectDate, menu_prefix => 'due', current => 0 &> (<% $ticket_obj->due %>)
     </td>
   </tr>
 </table>

Modified: rt/3.999/branches/datetime/share/html/Ticket/Elements/Reminders
==============================================================================
--- rt/3.999/branches/datetime/share/html/Ticket/Elements/Reminders	(original)
+++ rt/3.999/branches/datetime/share/html/Ticket/Elements/Reminders	Fri Mar 13 14:21:34 2009
@@ -76,26 +76,26 @@
             $reminder->set_owner( $request_args->{ 'Reminder-Owner-' . $reminder->id } , "Force" ) ;
         }
 
-        if ( exists( $request_args->{ 'Reminder-Due-' . $reminder->id } ) && ( $reminder->due_obj->date ne $request_args->{ 'Reminder-Due-' . $reminder->id } )) {
+        if ( exists( $request_args->{ 'Reminder-Due-' . $reminder->id } ) && ( $reminder->due->ymd ne $request_args->{ 'Reminder-Due-' . $reminder->id } )) {
             $reminder->set_due( $request_args->{ 'Reminder-Due-' . $reminder->id } ) ;
         }
     }
 }
 
 if ( $request_args->{'NewReminder-Subject'} ) {
-    my $due_obj = RT::Date->new();
+    my $due     = RT::Date->new();
     my $date    = Time::ParseDate::parsedate(
         $request_args->{'NewReminder-Due'},
         UK            => RT->config->get('DateDayBeforeMonth'),
         PREFER_PAST   => 0,
         PREFER_FUTURE => 1
     );
-    $due_obj->set( value => $date, format => 'unix' );
+    $due->set( value => $date, format => 'unix' );
     my ( $add_id, $msg, $txnid ) = $ticket->reminders->add(
 
         subject => $request_args->{'NewReminder-Subject'},
         owner   => $request_args->{'NewReminder-Owner'},
-        due     => $due_obj->iso
+        due     => $due->iso
     );
 }
 
@@ -157,8 +157,8 @@
 /> 
     <input type="text" size="15" name="Reminder-Subject-<% $reminder->id %>" value="<%$reminder->subject%>" /> &bull; 
     <& /Elements/SelectOwner, name => 'Reminder-Owner-'.$reminder->id, queue => $ticket->queue, default => $reminder->owner, default_value => 0  &>
-    <& /Elements/SelectDate, name => 'Reminder-Due-'.$reminder->id, default => $reminder->due_obj->date &>
-    (<%$reminder->due_obj->unix>0  ? $reminder->due_obj->age_as_string : '' %>)<br />
+    <& /Elements/SelectDate, name => 'Reminder-Due-'.$reminder->id, default => $reminder->due->ymd &>
+    (<%$reminder->due->epoch>0  ? $reminder->due->age : '' %>)<br />
 </%method>
 <%method ShowEntry>
 <%args>
@@ -172,5 +172,5 @@
 /> 
     <%$reminder->subject%> &bull; 
     <%$reminder->owner_obj->name%>
-    <%$reminder->due_obj->unix>0  ? "&bull; ". $reminder->due_obj->age_as_string : '' |n%><br />
+    <%$reminder->due->epoch>0  ? "&bull; ". $reminder->due->age : '' |n%><br />
 </%method>

Modified: rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowAttachments
==============================================================================
--- rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowAttachments	(original)
+++ rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowAttachments	Fri Mar 13 14:21:34 2009
@@ -72,7 +72,7 @@
 
 <li><font size="-2">
 <a href="<%RT->config->get('WebPath')%>/Ticket/Attachment/<%$rev->transaction_id%>/<%$rev->id%>/<%$rev->filename | u%>">
-<&|/l, $rev->created_as_string, $size, $rev->creator_obj->name &>%1 (%2) by %3</&>
+<&|/l, $rev->created, $size, $rev->creator_obj->name &>%1 (%2) by %3</&>
 </a>
 </font></li>
 % }

Modified: rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowDates
==============================================================================
--- rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowDates	(original)
+++ rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowDates	Fri Mar 13 14:21:34 2009
@@ -48,36 +48,36 @@
 <table>
   <tr>
     <td class="label date Created"><&|/l&>Created</&>:</td>
-    <td class="value date Created"><% $ticket->created_obj->as_string %></td>
+    <td class="value date Created"><% $ticket->created %></td>
   </tr>
   <tr>
     <td class="label date starts"><&|/l&>Starts</&>:</td>
-    <td class="value date starts"><% $ticket->starts_obj->as_string %></td>
+    <td class="value date starts"><% $ticket->starts %></td>
   </tr>
   <tr>
     <td class="label date started"><&|/l&>Started</&>:</td>
-    <td class="value date started"><% $ticket->started_obj->as_string %></td>
+    <td class="value date started"><% $ticket->started %></td>
   </tr>
   <tr>
     <td class="label date told"><a href="<% RT->config->get('WebPath') %>/Ticket/Display.html?id=<% $ticket->id %>&Action=SetTold"><&|/l&>Last Contact</&></a>:</td>
-    <td class="value date told"><% $ticket->told_obj->as_string %></td>
+    <td class="value date told"><% $ticket->told %></td>
   </tr>
   <tr>
     <td class="label date due"><&|/l&>Due</&>:</td>
-% my $due = $ticket->due_obj;
-% if ( $due && $due->unix > 0 && $due->diff < 0 ) {
-    <td class="value date due"><span class="overdue"><% $due->as_string  %></span></td>
+% my $due = $ticket->due;
+% if ( $due && $due->epoch > 0 && $due->diff < 0 ) {
+    <td class="value date due"><span class="overdue"><% $due %></span></td>
 % } else {
-    <td class="value date due"><% $due->as_string  %></td>
+    <td class="value date due"><% $due %></td>
 % }
   </tr>
   <tr>
     <td class="label date resolved"><&|/l&>Closed</&>:</td>
-    <td class="value date resolved"><% $ticket->resolved_obj->as_string  %></td>
+    <td class="value date resolved"><% $ticket->resolved  %></td>
   </tr>
   <tr>
     <td class="label date updated"><&|/l&>Updated</&>:</td>
-% my $UpdatedString = $ticket->last_updated ? _("%1 by %2", $ticket->last_updated_as_string, $ticket->last_updated_by_obj->name) : _("Never");
+% my $UpdatedString = $ticket->last_updated ? _("%1 by %2", $ticket->last_updated, $ticket->last_updated_by_obj->name) : _("Never");
 % if ($updated_link) {
     <td class="value date updated"><a href="#lasttrans"><% $UpdatedString | h %></a></td>
 % } else {

Modified: rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowTransaction
==============================================================================
--- rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowTransaction	(original)
+++ rt/3.999/branches/datetime/share/html/Ticket/Elements/ShowTransaction	Fri Mar 13 14:21:34 2009
@@ -121,7 +121,7 @@
 </%ONCE>
 <%INIT>
 
-my $transdate = $transaction->created_as_string();
+my $transdate = $transaction->created;
 $transdate =~ s/\s/&nbsp;/g;
 
 my ($type, $field) = ($transaction->type, $transaction->field || '');

Modified: rt/3.999/branches/datetime/share/html/User/Prefs.html
==============================================================================
--- rt/3.999/branches/datetime/share/html/User/Prefs.html	(original)
+++ rt/3.999/branches/datetime/share/html/User/Prefs.html	Fri Mar 13 14:21:34 2009
@@ -79,8 +79,8 @@
     <td class="value"><& /Elements/SelectLang, name => 'lang', default => $user_object->lang &></td>
   </tr>
   <tr>
-    <td class="label"><&|/l&>timezone</&>:</td>
-    <td class="value"><& /Elements/SelectTimezone, name => 'timezone', default => $user_object->timezone &></td>
+    <td class="label"><&|/l&>Time Zone</&>:</td>
+    <td class="value"><& /Elements/SelectTimezone, name => 'time_zone', default => $user_object->time_zone &></td>
   </tr>
 </table>
 </&>
@@ -217,7 +217,7 @@
 		    organization real_name nickname lang email_encoding web_encoding 
 		    ExternalContactInfoId ContactInfoSystem gecos ExternalAuthId 
 		    auth_system HomePhone WorkPhone MobilePhone PagerPhone Address1
-		Address2 City State Zip Country lang timezone
+		Address2 City State Zip Country lang time_zone
 		   );
 
     $m->callback(

Modified: rt/3.999/branches/datetime/t/api/date.t
==============================================================================
--- rt/3.999/branches/datetime/t/api/date.t	(original)
+++ rt/3.999/branches/datetime/t/api/date.t	Fri Mar 13 14:21:34 2009
@@ -4,24 +4,27 @@
 use Test::MockTime qw(set_fixed_time restore_time);
 use RT::Test;
 
-use Test::More tests => 166;
+use Test::More tests => 93;
 
 use RT::Model::User;
 use Test::Warn;
 
-use_ok('RT::Date');
+use_ok('RT::DateTime');
+
+set_fixed_time("2005-11-28T15:10:00Z");
+
 {
-    my $date = RT::Date->new(current_user => RT->system_user);
-    isa_ok($date, 'RT::Date', "constructor returned RT::Date oject");
-    $date = $date->new(current_user => RT->system_user);
-    isa_ok($date, 'RT::Date', "constructor returned RT::Date oject");
+    my $system = RT->system_user;
+    my $date = RT::DateTime->now(current_user => $system);
+    isa_ok($date, 'RT::DateTime', "constructor returned RT::DateTime oject");
+    is($date->current_user, $system, "correctly set the datetime's current_user");
 }
 
 {
-    # set timezone in all places to UTC
-    RT->system_user->user_object->__set(column => 'timezone', value => 'UTC')
-                                if RT->system_user->user_object->timezone;
-    RT->config->set( Timezone => 'UTC' );
+    # set time zone in all places to UTC
+    RT->system_user->user_object->__set(column => 'time_zone', value => 'UTC')
+                                if RT->system_user->user_object->time_zone;
+    RT->config->set( TimeZone => 'UTC' );
 }
 
 my $current_user;
@@ -34,493 +37,267 @@
     );
     ok($uid, "user was Created") or diag("error: $msg");
     $current_user = RT::CurrentUser->new(id => $user->id);
+    Jifty->web->current_user($current_user);
 }
 
 {
-    my $date = RT::Date->new(current_user => $current_user );
-    is($date->timezone, 'UTC', "dropped all timzones to UTC");
-    is($date->timezone('user'), 'UTC', "dropped all timzones to UTC");
-    is($date->timezone('server'), 'UTC', "dropped all timzones to UTC");
-    is($date->timezone('unknown'), 'UTC', "with wrong context returns UTC");
+    my $date = RT::DateTime->now;
+    is($date->time_zone->name, 'UTC', "dropped all timzones to UTC");
+    is($date->set_time_zone('user')->time_zone->name, 'UTC', "dropped all timzones to UTC");
+    is($date->set_time_zone('server')->time_zone->name, 'UTC', "dropped all timzones to UTC");
 
-    $current_user->user_object->__set( column => 'timezone', value => 'Europe/Moscow');
-    is($current_user->user_object->timezone,
+    $current_user->user_object->__set( column => 'time_zone', value => 'Europe/Moscow');
+    is($current_user->user_object->time_zone,
        'Europe/Moscow',
-       "successfuly changed user's timezone");
-    is($date->timezone('user'),
+       "successfuly changed user's time_zone");
+    is($date->set_time_zone('user')->time_zone->name,
        'Europe/Moscow',
-       "in user context returns user's timezone");
-    is($date->timezone, 'UTC', "the deafult value is always UTC");
-    is($date->timezone('server'), 'UTC', "wasn't changed");
+       "in user context returns user's time_zone");
+    is($date->time_zone->name, 'Europe/Moscow', "we changed the timezone");
+    is($date->set_time_zone('server')->time_zone->name, 'UTC', "wasn't changed");
 
-    RT->config->set( Timezone => 'Africa/Ouagadougou' );
-    is($date->timezone('server'),
+    RT->config->set( TimeZone => 'Africa/Ouagadougou' );
+    is($date->set_time_zone('server')->time_zone->name,
        'Africa/Ouagadougou',
-       "timezone of the RT server was changed");
-    is($date->timezone('user'),
+       "time_zone of the RT server was changed");
+    is($date->set_time_zone('user')->time_zone->name,
        'Europe/Moscow',
-       "in user context still returns user's timezone");
-    is($date->timezone, 'UTC', "the deafult value is always UTC");
+       "in user context still returns user's time_zone");
+    is($date->time_zone->name, 'Europe/Moscow', "we changed the timezone");
 
-    $current_user->user_object->__set( column => 'timezone', value => '');
-    is($current_user->user_object->timezone,
+    $current_user->user_object->__set( column => 'time_zone', value => '');
+    is($current_user->user_object->time_zone,
        '',
-       "successfuly changed user's timezone");
-    is($date->timezone('user'),
+       "successfuly changed user's time_zone");
+    is($date->set_time_zone('user')->time_zone->name,
        'Africa/Ouagadougou',
-       "in user context returns timezone of the server if user's one is not defined");
-    is($date->timezone, 'UTC', "the deafult value is always UTC");
+       "in user context returns time zone of the server if user's one is not defined");
+    is($date->time_zone->name, 'Africa/Ouagadougou', "we changed the timezone");
 
-    RT->config->set( Timezone => 'GMT' );
-    is($date->timezone('server'),
+    RT->config->set( TimeZone => 'GMT' );
+    is($date->set_time_zone('server')->time_zone->name,
        'UTC',
-       "timezone is GMT which one is alias for UTC");
+       "time zone is GMT which one is alias for UTC");
 
-    RT->config->set( Timezone => '' );
-    is($date->timezone, 'UTC', "dropped all timzones to UTC");
-    is($date->timezone('user'),
+    RT->config->set( TimeZone => '' );
+    is($date->time_zone->name, 'UTC', "dropped all timzones to UTC");
+    is($date->set_time_zone('user')->time_zone->name,
        'UTC',
        "user's and server's timzones are not defined, so UTC");
-    is($date->timezone('server'),
+    is($date->set_time_zone('server')->time_zone->name,
        'UTC',
-       "timezone of the server is not defined so UTC");
+       "time zone of the server is not defined so UTC");
 
-    RT->config->set( Timezone => 'UTC' );
+    RT->config->set( TimeZone => 'UTC' );
 }
 
 {
-    my $date = RT::Date->new(current_user => RT->system_user);
-    is($date->unix, 0, "new date returns 0 in Unix format");
-    is($date->get, '1970-01-01 00:00:00', "default is ISO format");
-    is($date->get(format =>'SomeBadFormat'),
-       '1970-01-01 00:00:00',
-       "don't know format, return ISO format");
-    is($date->get(format =>'W3CDTF'),
-       '1970-01-01T00:00:00Z',
-       "W3CDTF format with defaults");
-
-    is($date->get(format =>'RFC2822'),
-       'Thu, 1 Jan 1970 00:00:00 +0000',
+    my $date = RT::DateTime->now(current_user => RT->system_user);
+    is($date, '2005-11-28 15:10:00', "default is ISO format");
+    is($date->iso, '2005-11-28 15:10:00', "default is ISO format");
+    ok(!$date->is_unset, "date is set");
+    is($date->rfc2822,
+       'Mon, 28 Nov 2005 15:10:00 +0000',
        "RFC2822 format with defaults");
+}
 
-    is($date->iso(time => 0),
-       '1970-01-01',
-       "ISO format without time part");
-    is($date->w3cdtf(time => 0),
-       '1970-01-01',
-       "W3CDTF format without time part");
-    is($date->rfc2822(time => 0),
-       'Thu, 1 Jan 1970',
-       "RFC2822 format without time part");
-
-    is($date->iso(date => 0),
-       '00:00:00',
-       "ISO format without date part");
-    is($date->w3cdtf(date => 0),
-       '1970-01-01T00:00:00Z',
-       "W3CDTF format is incorrect without date part");
-    is($date->rfc2822(date => 0),
-       '00:00:00 +0000',
-       "RFC2822 format without date part");
-
-    is($date->iso(date => 0, seconds => 0),
-       '00:00',
-       "ISO format without date part and seconds");
-    is($date->w3cdtf(date => 0, seconds => 0),
-       '1970-01-01T00:00Z',
-       "W3CDTF format without seconds, but we ship date part even if date is false");
-    is($date->rfc2822(date => 0, seconds => 0),
-       '00:00 +0000',
-       "RFC2822 format without date part and seconds");
-
-    is($date->rfc2822(day_of_week => 0),
-       '1 Jan 1970 00:00:00 +0000',
-       "RFC2822 format without 'day of week' part");
-    is($date->rfc2822(day_of_week => 0, date => 0),
-       '00:00:00 +0000',
-       "RFC2822 format without 'day of week' and date parts(corner case test)");
-
-    is($date->date,
-       '1970-01-01',
-       "the default format for the 'date' method is ISO");
-    is($date->date(format => 'W3CDTF'),
-       '1970-01-01',
-       "'date' method, W3CDTF format");
-    is($date->date(format => 'RFC2822'),
-       'Thu, 1 Jan 1970',
-       "'date' method, RFC2822 format");
-    is($date->date(time => 1),
-       '1970-01-01',
-       "'date' method doesn't pass through 'time' argument");
-    is($date->date(date => 0),
-       '1970-01-01',
-       "'date' method overrides 'date' argument");
-
-    is($date->time,
-       '00:00:00',
-       "the default format for the 'time' method is ISO");
-    is($date->time(format => 'W3CDTF'),
-       '1970-01-01T00:00:00Z',
-       "'time' method, W3CDTF format, date part is required by w3c doc");
-    is($date->time(format => 'RFC2822'),
-       '00:00:00 +0000',
-       "'time' method, RFC2822 format");
-    is($date->time(date => 1),
-       '00:00:00',
-       "'time' method doesn't pass through 'date' argument");
-    is($date->time(time => 0),
-       '00:00:00',
-       "'time' method overrides 'time' argument");
-
-    is($date->date_time,
-       '1970-01-01 00:00:00',
-       "the default format for the 'DateTime' method is ISO");
-    is($date->date_time(format =>'W3CDTF'),
-       '1970-01-01T00:00:00Z',
-       "'DateTime' method, W3CDTF format");
-    is($date->date_time(format =>'RFC2822'),
-       'Thu, 1 Jan 1970 00:00:00 +0000',
-       "'DateTime' method, RFC2822 format");
-    is($date->date_time(date => 0, time => 0),
-       '1970-01-01 00:00:00',
-       "the 'DateTime' method overrides both 'date' and 'time' arguments");
-}
-
-
-{ # positive timezone
-    $current_user->user_object->__set( column => 'timezone', value => 'Europe/Moscow');
-    my $date = RT::Date->new( current_user => $current_user );
-    $date->set( format => 'ISO', timezone => 'utc', value => '2005-01-01 15:10:00' );
-    is($date->iso( timezone => 'user' ), '2005-01-01 18:10:00', "ISO");
-    is($date->w3cdtf( timezone => 'user' ), '2005-01-01T18:10:00+03:00', "W3C DTF");
-    is($date->rfc2822( timezone => 'user' ), 'Sat, 1 Jan 2005 18:10:00 +0300', "RFC2822");
+
+{ # positive time zone
+    $current_user->user_object->__set( column => 'time_zone', value => 'Europe/Moscow');
+    my $date = RT::DateTime->new_from_string('2005-01-01 15:10:00');
+    is($date->iso, '2005-01-01 15:10:00', "user timezone");
+    is($date->iso(time_zone => 'system'), '2005-01-01 12:10:00', "system timezone");
+    is($date->rfc2822( time_zone => 'user' ), 'Sat, 01 Jan 2005 15:10:00 +0300', "RFC2822 in user time zone");
+    is($date->rfc2822( time_zone => 'server' ), 'Sat, 01 Jan 2005 12:10:00 +0000', "RFC2822 in server time zone");
 
     # DST
-    $date = RT::Date->new(current_user =>  $current_user );
-    $date->set( format => 'ISO', timezone => 'utc', value => '2005-07-01 15:10:00' );
-    is($date->iso( timezone => 'user' ), '2005-07-01 19:10:00', "ISO");
-    is($date->w3cdtf( timezone => 'user' ), '2005-07-01T19:10:00+04:00', "W3C DTF");
-    is($date->rfc2822( timezone => 'user' ), 'Fri, 1 Jul 2005 19:10:00 +0400', "RFC2822");
+    $date = RT::DateTime->new_from_string('2005-07-01 15:10:00', time_zone => 'UTC');
+    is($date->iso( time_zone => 'user' ), '2005-07-01 19:10:00', "ISO");
+    is($date->rfc2822( time_zone => 'user' ), 'Fri, 01 Jul 2005 19:10:00 +0400', "RFC2822");
+
+    is($date->iso( time_zone => 'server' ), '2005-07-01 15:10:00', "ISO");
+    is($date->rfc2822( time_zone => 'server' ), 'Fri, 01 Jul 2005 15:10:00 +0000', "RFC2822");
 }
 
-{ # negative timezone
-    $current_user->user_object->__set( column => 'timezone', value => 'America/New_York');
-    my $date = RT::Date->new( current_user => $current_user );
-    $date->set( format => 'ISO', timezone => 'utc', value => '2005-01-01 15:10:00' );
-    is($date->iso( timezone => 'user' ), '2005-01-01 10:10:00', "ISO");
-    is($date->w3cdtf( timezone => 'user' ), '2005-01-01T10:10:00-05:00', "W3C DTF");
-    is($date->rfc2822( timezone => 'user' ), 'Sat, 1 Jan 2005 10:10:00 -0500', "RFC2822");
+{ # negative time zone
+    $current_user->user_object->__set( column => 'time_zone', value => 'America/New_York');
+    my $date = RT::DateTime->new_from_string('2005-01-01 15:10:00', time_zone => 'UTC');
+    is($date->iso( time_zone => 'user' ), '2005-01-01 10:10:00', "ISO");
+    is($date->rfc2822( time_zone => 'user' ), 'Sat, 01 Jan 2005 10:10:00 -0500', "RFC2822");
 
     # DST
-    $date = RT::Date->new( current_user =>  $current_user );
-    $date->set( format => 'ISO', timezone => 'utc', value => '2005-07-01 15:10:00' );
-    is($date->iso( timezone => 'user' ), '2005-07-01 11:10:00', "ISO");
-    is($date->w3cdtf( timezone => 'user' ), '2005-07-01T11:10:00-04:00', "W3C DTF");
-    is($date->rfc2822( timezone => 'user' ), 'Fri, 1 Jul 2005 11:10:00 -0400', "RFC2822");
-}
-
- # bad format
-    my $date = RT::Date->new(current_user => RT->system_user);
-    $date->set( format => 'bad' );
-    is($date->unix, undef, "bad format");
-
-
-{ # setting value via Unix method
-    my $date = RT::Date->new(current_user => RT->system_user);
-    $date->unix(1);
-    is($date->iso, '1970-01-01 00:00:01', "correct value");
+    $date = RT::DateTime->new_from_string('2005-07-01 15:10:00', time_zone => 'UTC' );
+    is($date->iso( time_zone => 'user' ), '2005-07-01 11:10:00', "ISO");
+    is($date->rfc2822( time_zone => 'user' ), 'Fri, 01 Jul 2005 11:10:00 -0400', "RFC2822");
+}
 
-    foreach (undef, 0, ''){
-        $date->unix(1);
+{ # setting value via from_epoch method
+    my $date = RT::DateTime->from_epoch(epoch => 1, time_zone => 'UTC');
+    is($date->time_zone->name, 'UTC', "time_zone set correctly");
+    ok(!$date->is_unset, "date is set");
     is($date->iso, '1970-01-01 00:00:01', "correct value");
 
-        $date->set(format => 'unix', value => $_);
-        is($date->iso, '1970-01-01 00:00:00', "Set a date to midnight 1/1/1970 GMT due to wrong call");
-        is($date->unix, 0, "unix is 0 => unset");
-    }
+    $date = RT::DateTime->from_epoch(epoch => 1);
+    is($date->time_zone->name, 'America/New_York', "time_zone defaults to user's");
+    ok(!$date->is_unset, "date is set");
+    is($date->iso, '1969-12-31 19:00:01', "correct value");
 }
 
-my $year = (localtime(time))[5] + 1900;
-
 { # set+ISO format
-    my $date = RT::Date->new(current_user => RT->system_user);
-    my $return =   $date->set(format => 'ISO', value => 'weird date');
-    is ($return, undef, "The set failed. returned undef");
-    is($date->unix, undef, "date was wrong => unix == 0");
-
-    # XXX: ISO format has more feature than we suport
-    # http://www.cl.cam.ac.uk/~mgk25/iso-time.html
+    my $date = RT::DateTime->new_from_string('weird date');
+    isa_ok($date, 'RT::DateTime');
+    is($date, 'unset', "unparseable date returns an 'unset' RT::DateTime");
+    ok($date->is_unset, "unparseable date is_unset");
 
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00');
+    $date = RT::DateTime->new_from_string('2005-11-28 15:10:00');
     is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
 
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00+00');
+    TODO: {
+        local $TODO = "YYYY-DD-MM hh:mm:ss+00 not handled yet";
+        $date = RT::DateTime->new_from_string('2005-11-28 15:10:00+00');
         is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss+00");
+    };
 
-    $date->set(format => 'ISO', value => '11-28 15:10:00');
-    is($date->iso, $year .'-11-28 15:10:00', "DD-MM hh:mm:ss");
+    TODO: {
+        local $TODO = "DD-MM hh:mm:ss not handled yet";
+        $date = RT::DateTime->new_from_string('11-28 15:10:00');
+        is($date->iso, '2005-11-28 15:10:00', "DD-MM hh:mm:ss");
+    };
+
+    TODO: {
+        local $TODO = "DD-MM hh:mm:ss+00 not handled yet";
+        $date = RT::DateTime->new_from_string('11-28 15:10:00+00');
+        is($date->iso, '2005-11-28 15:10:00', "DD-MM hh:mm:ss+00");
+    };
 
-    $date->set(format => 'ISO', value => '11-28 15:10:00+00');
-    is($date->iso, $year .'-11-28 15:10:00', "DD-MM hh:mm:ss+00");
-
-    $date->set(format => 'ISO', value => '20051128151000');
+    $date = RT::DateTime->new_from_string('20051128151000');
     is($date->iso, '2005-11-28 15:10:00', "YYYYDDMMhhmmss");
 
-    $date->set(format => 'ISO', value => '1128151000');
-    is($date->iso, $year .'-11-28 15:10:00', "DDMMhhmmss");
+    TODO: {
+        local $TODO = "DDMMhhmmss not handled yet";
+        $date = RT::DateTime->new_from_string('1128151000');
+        is($date->iso, '2005-11-28 15:10:00', "DDMMhhmmss");
+    };
 
-    $date->set(format => 'ISO', value => '2005112815:10:00');
+    $date = RT::DateTime->new_from_string('2005112815:10:00');
     is($date->iso, '2005-11-28 15:10:00', "YYYYDDMMhh:mm:ss");
 
-    $date->set(format => 'ISO', value => '112815:10:00');
-    is($date->iso, $year .'-11-28 15:10:00', "DDMMhh:mm:ss");
+    TODO: {
+        local $TODO = "DDMMhh:mm:ss not handled yet";
+        $date = RT::DateTime->new_from_string('112815:10:00');
+        is($date->iso, '2005-11-28 15:10:00', "DDMMhh:mm:ss");
+    };
 
-    $date->set(format => 'ISO', value => '2005-13-28 15:10:00');
-    is($date->unix, 0, "wrong month value");
+    $date = RT::DateTime->new_from_string('2005-13-28 15:10:00');
+    ok($date->is_unset, "wrong month value");
 
-    $date->set(format => 'ISO', value => '2005-00-28 15:10:00');
-    is($date->unix, 0, "wrong month value");
+    $date = RT::DateTime->new_from_string('2005-00-28 15:10:00');
+    ok($date->is_unset, "wrong month value");
 
-    $date->set(format => 'ISO', value => '1960-01-28 15:10:00');
-    is($date->unix, 0, "too old, we don't support");
+    $date = RT::DateTime->new_from_string('1960-01-28 15:10:00');
+    is($date->iso, '1960-01-28 15:10:00', "we can support pre-1970s dates now");
 }
 
 { # set+datemanip format(time::ParseDate)
-    my $date = RT::Date->new(current_user => RT->system_user);
-    $date->set(format => 'unknown', value => 'weird date');
-    is($date->unix, 0, "date was wrong");
-
-    RT->config->set( Timezone => 'Europe/Moscow' );
-    $date->set(format => 'datemanip', value => '2005-11-28 15:10:00');
-    is($date->iso, '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
+    RT->config->set( TimeZone => 'Europe/Moscow' );
+    my $date = RT::DateTime->new_from_string('2005-11-28 15:10:00');
+    is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+    is($date->iso(time_zone => 'server'), '2005-11-28 23:10:00', "YYYY-DD-MM hh:mm:ss");
 
-    RT->config->set( Timezone => 'UTC' );
-    $date->set(format => 'datemanip', value => '2005-11-28 15:10:00');
+    RT->config->set( TimeZone => 'UTC' );
+    $date = RT::DateTime->new_from_string('2005-11-28 15:10:00');
     is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+    is($date->iso(time_zone => 'server'), '2005-11-28 20:10:00', "YYYY-DD-MM hh:mm:ss");
 
-    $current_user->user_object->__set( column => 'timezone', value => 'Europe/Moscow');
-    $date = RT::Date->new( current_user => $current_user );
-    $date->set(format => 'datemanip', value => '2005-11-28 15:10:00');
-    is($date->iso, '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
-}
-
-{ # set+unknown format(time::ParseDate)
-    my $date = RT::Date->new(current_user => RT->system_user);
-    $date->set(format => 'unknown', value => 'weird date');
-    is($date->unix, 0, "date was wrong");
-
-    RT->config->set( Timezone => 'Europe/Moscow' );
-    $date->set(format => 'unknown', value => '2005-11-28 15:10:00');
-    is($date->iso, '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
+    $current_user->user_object->__set( column => 'time_zone', value => 'Europe/Moscow');
+    $date = RT::DateTime->new_from_string('2005-11-28 15:10:00');
+    is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+    is($date->iso(time_zone => 'server'), '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
+}
 
-    $date->set(format => 'unknown', value => '2005-11-28 15:10:00', timezone => 'utc' );
+{
+    RT->config->set( TimeZone => 'Europe/Moscow' );
+    my $date = RT::DateTime->new_from_string('2005-11-28 15:10:00');
     is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
 
-    # test relative dates
-    {
-        set_fixed_time("2005-11-28T15:10:00Z");
-        $date->set(format => 'unknown', value => 'now');
-        is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
-
-        $date->set(format => 'unknown', value => '1 day ago');
-        is($date->iso, '2005-11-27 15:10:00', "YYYY-DD-MM hh:mm:ss");
-        restore_time();
-    }
+    $date = RT::DateTime->new_from_string('2005-11-28 15:10:00', time_zone => 'UTC' );
+    is($date->iso, '2005-11-28 18:10:00', "YYYY-DD-MM hh:mm:ss");
 
-    RT->config->set( Timezone => 'UTC' );
-    $date->set(format => 'unknown', value => '2005-11-28 15:10:00');
-    is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+    # relative dates
+    $date = RT::DateTime->new_from_string('now');
+    is($date->iso, '2005-11-28 10:10:00', "YYYY-DD-MM hh:mm:ss");
 
-    $current_user->user_object->__set( column => 'timezone', value => 'Europe/Moscow');
-    $date = RT::Date->new( current_user => $current_user );
-    $date->set(format => 'unknown', value => '2005-11-28 15:10:00');
-    is($date->iso, '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
-    $date->set(format => 'unknown', value => '2005-11-28 15:10:00', timezone => 'server' );
-    is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
-    $date->set(format => 'unknown', value => '2005-11-28 15:10:00', timezone => 'utc' );
+    $date = RT::DateTime->new_from_string('1 day ago');
+    is($date->iso, '2005-11-27 13:10:00', "YYYY-DD-MM hh:mm:ss");
+
+    RT->config->set( TimeZone => 'UTC' );
+    $date = RT::DateTime->new_from_string('2005-11-28 15:10:00');
     is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
-}
 
-{ # SetToMidnight
-    my $date = RT::Date->new(current_user => RT->system_user);
+    $current_user->user_object->__set( column => 'time_zone', value => 'Europe/Moscow');
+    $date = RT::DateTime->new_from_string('2005-11-28 15:10:00');
+    is($date->iso, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+    $date = RT::DateTime->new_from_string('2005-11-28 15:10:00', time_zone => 'server' );
+    is($date->iso, '2005-11-28 18:10:00', "YYYY-DD-MM hh:mm:ss");
+    $date = RT::DateTime->new_from_string('2005-11-28 15:10:00', time_zone => 'UTC' );
+    is($date->iso, '2005-11-28 18:10:00', "YYYY-DD-MM hh:mm:ss");
+}
+
+{ # stringification
+    $current_user->user_object->__set( column => 'time_zone', value => '');
+    my $date = RT::DateTime->from_epoch(epoch => 0);
+    is($date, "unset", "epoch 0 returns 'unset'");
+
+    RT->config->set( DateTimeFormat => '%a %b %d %H:%M:%S %Y');
+    $date = RT::DateTime->from_epoch(epoch => 1);
+    is($date, 'Thu Jan 01 00:00:01 1970', "correct string");
+
+    RT->config->set( DateTimeFormat => '%a, %d %b %Y %H:%M:%S %z' );
+    is($date, 'Thu, 01 Jan 1970 00:00:01 +0000', "correct string");
+
+    RT->config->set( DateTimeFormat => '%a, %d %b %Y %H:%M %z' );
+    is($date, 'Thu, 01 Jan 1970 00:00 +0000', "correct string");
+}
+
+{ # RT::DateTime::Duration
+
+    is(RT::DateTime::Duration->new(seconds => 1), '1 sec', '1 sec');
+    is(RT::DateTime::Duration->new(seconds => 59), '59 sec', '59 sec');
+
+    TODO: {
+        local $TODO = "DateTime::Duration doesn't convert between units that are not constant factors of another";
+        is(RT::DateTime::Duration->new(seconds => 60), '1 min', '1 min');
+        is(RT::DateTime::Duration->new(seconds => 60*119), '119 min', '119 min');
+        is(RT::DateTime::Duration->new(seconds => 60*60*2-1), '120 min', '120 min');
+        is(RT::DateTime::Duration->new(seconds => 60*60*2), '2 hours', '2 hours');
+        is(RT::DateTime::Duration->new(seconds => 60*60*2), '2 hours', '2 hours');
+        is(RT::DateTime::Duration->new(seconds => 60*60*48-1), '48 hours', '48 hours');
+        is(RT::DateTime::Duration->new(seconds => 60*60*48), '2 days', '2 days');
+        is(RT::DateTime::Duration->new(seconds => 60*60*24*14-1), '14 days', '14 days');
+        is(RT::DateTime::Duration->new(seconds => 60*60*24*14), '2 weeks', '2 weeks');
+        is(RT::DateTime::Duration->new(seconds => 60*60*24*7*8-1), '8 weeks', '8 weeks');
+        is(RT::DateTime::Duration->new(seconds => 60*60*24*61), '2 months', '2 months');
+        is(RT::DateTime::Duration->new(seconds => 60*60*24*365-1), '12 months', '12 months');
+        is(RT::DateTime::Duration->new(seconds => 60*60*24*366), '1 years', '1 years');
 
-    RT->config->set( Timezone => 'Europe/Moscow' );
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00');
-    $date->set_to_midnight;
-    is($date->iso, '2005-11-28 00:00:00', "default is utc");
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00');
-    $date->set_to_midnight(timezone => 'utc');
-    is($date->iso, '2005-11-28 00:00:00', "utc context");
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00');
-    $date->set_to_midnight(timezone => 'user');
-    is($date->iso, '2005-11-27 21:00:00', "user context, user has no preference, fallback to server");
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00');
-    $date->set_to_midnight(timezone => 'server');
-    is($date->iso, '2005-11-27 21:00:00', "server context");
-
-    $current_user->user_object->__set( column => 'timezone', value => 'Europe/Moscow');
-    $date = RT::Date->new(current_user =>  $current_user );
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00');
-    $date->set_to_midnight;
-    is($date->iso, '2005-11-28 00:00:00', "default is utc");
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00');
-    $date->set_to_midnight(timezone => 'utc');
-    is($date->iso, '2005-11-28 00:00:00', "utc context");
-    $date->set(format => 'ISO', value => '2005-11-28 15:10:00');
-    $date->set_to_midnight(timezone => 'user');
-    is($date->iso, '2005-11-27 21:00:00', "user context");
-    $date->set_to_midnight(timezone => 'server');
-    is($date->iso, '2005-11-27 21:00:00', "server context");
-
-    RT->config->set( Timezone => 'UTC' );
-}
-
-{ # set_to_now
-    my $date = RT::Date->new(current_user => RT->system_user);
-    my $time = time;
-    $date->set_to_now;
-    ok($date->unix >= $time, 'close enough');
-    ok($date->unix < $time+5, 'difference is less than five seconds');
+        is(RT::DateTime::Duration->new(seconds => -1), '1 sec ago', '1 sec ago');
+    }
 }
 
-{
-    my $date = RT::Date->new(current_user => RT->system_user);
-    
-    $date->unix(0);
-    $date->add_seconds;
-    is($date->iso, '1970-01-01 00:00:00', "nothing changed");
-    $date->add_seconds(0);
-    is($date->iso, '1970-01-01 00:00:00', "nothing changed");
-    
-    $date->unix(0);
-    $date->add_seconds(5);
-    is($date->iso, '1970-01-01 00:00:05', "added five seconds");
-    $date->add_seconds(-2);
-    is($date->iso, '1970-01-01 00:00:03', "substracted two seconds");
-    
-    $date->unix(0);
-    $date->add_seconds(3661);
-    is($date->iso, '1970-01-01 01:01:01', "added one hour, minute and a second");
-
-# XXX: TODO, doesn't work with Test::Warn
-#    TODO: {
-#        local $TODO = "BUG or subject to change Date handling to support unix time <= 0";
-#        $date->unix(0);
-#        $date->add_seconds(-2);
-#        ok($date->unix > 0);
-#    }
-
-    $date->unix(0);
-    $date->add_day;
-    is($date->iso, '1970-01-02 00:00:00', "added one day");
-    $date->add_days(2);
-    is($date->iso, '1970-01-04 00:00:00', "added two days");
-    $date->add_days(-1);
-    is($date->iso, '1970-01-03 00:00:00', "substructed one day");
-    
-    $date->unix(0);
-    $date->add_days(31);
-    is($date->iso, '1970-02-01 00:00:00', "added one month");
+{ # difference
+    my $date = RT::DateTime->now;
+    my $duration = RT::DateTime->now - $date;
+    like($duration, qr/^\d+ sec$/, 'close enough');
 }
 
-{
-    $current_user->user_object->__set( column => 'timezone', value => '');
-    my $date = RT::Date->new(current_user =>  $current_user );
-    is($date->as_string, "Not set", "as_string returns 'Not set'");
-
-    RT->config->set( DateTimeFormat => '');
-    $date->unix(1);
-    is($date->as_string, 'Thu Jan 01 00:00:01 1970', "correct string");
-    is($date->as_string(date => 0), '00:00:01', "correct string");
-    is($date->as_string(time => 0), 'Thu Jan 01 1970', "correct string");
-    is($date->as_string(date => 0, time => 0), 'Thu Jan 01 00:00:01 1970', "invalid input");
-
-    RT->config->set( DateTimeFormat => 'RFC2822' );
-    $date->unix(1);
-    is($date->as_string, 'Thu, 1 Jan 1970 00:00:01 +0000', "correct string");
-
-    RT->config->set( DateTimeFormat => { format => 'RFC2822', seconds => 0 } );
-    $date->unix(1);
-    is($date->as_string, 'Thu, 1 Jan 1970 00:00 +0000', "correct string");
-    is($date->as_string(seconds => 1), 'Thu, 1 Jan 1970 00:00:01 +0000', "correct string");
-}
-
-{ # DurationAsString
-    my $date = RT::Date->new(current_user => RT->system_user);
-
-    is($date->duration_as_string(1), '1 sec', '1 sec');
-    is($date->duration_as_string(59), '59 sec', '59 sec');
-    is($date->duration_as_string(60), '1 min', '1 min');
-    is($date->duration_as_string(60*119), '119 min', '119 min');
-    is($date->duration_as_string(60*60*2-1), '120 min', '120 min');
-    is($date->duration_as_string(60*60*2), '2 hours', '2 hours');
-    is($date->duration_as_string(60*60*48-1), '48 hours', '48 hours');
-    is($date->duration_as_string(60*60*48), '2 days', '2 days');
-    is($date->duration_as_string(60*60*24*14-1), '14 days', '14 days');
-    is($date->duration_as_string(60*60*24*14), '2 weeks', '2 weeks');
-    is($date->duration_as_string(60*60*24*7*8-1), '8 weeks', '8 weeks');
-    is($date->duration_as_string(60*60*24*61), '2 months', '2 months');
-    is($date->duration_as_string(60*60*24*365-1), '12 months', '12 months');
-    is($date->duration_as_string(60*60*24*366), '1 years', '1 years');
-
-    is($date->duration_as_string(-1), '1 sec ago', '1 sec ago');
-}
-
-{ # DiffAsString
-    my $date = RT::Date->new(current_user => RT->system_user);
-    is($date->diff_as_string(1), '', 'no diff, wrong input');
-    is($date->diff_as_string(-1), '', 'no diff, wrong input');
-    is($date->diff_as_string('qwe'), '', 'no diff, wrong input');
-
-    $date->unix(2);
-    is($date->diff_as_string(-1), '', 'no diff, wrong input');
-
-    is($date->diff_as_string(3), '1 sec ago', 'diff: 1 sec ago');
-    is($date->diff_as_string(1), '1 sec', 'diff: 1 sec');
-
-    my $ndate = RT::Date->new(current_user => RT->system_user);
-    is($date->diff_as_string($ndate), '', 'no diff, wrong input');
-    $ndate->unix(3);
-    is($date->diff_as_string($ndate), '1 sec ago', 'diff: 1 sec ago');
-}
-
-{ # Diff
-    my $date = RT::Date->new(current_user => RT->system_user);
-    $date->set_to_now;
-    my $diff = $date->diff;
-    ok($diff <= 0, 'close enought');
-    ok($diff > -5, 'close enought');
-}
-
-{ # AgeAsString
-    my $date = RT::Date->new(current_user => RT->system_user);
-    $date->set_to_now;
-    my $diff = $date->age_as_string;
+{ # age
+    my $date = RT::DateTime->now(current_user => RT->system_user);
+    my $diff = $date->age;
     like($diff, qr/^(0 sec|[1-5] sec ago)$/, 'close enought');
 }
 
-{ # GetWeekday
-    my $date = RT::Date->new(current_user => RT->system_user);
-    is($date->get_weekday(7),  '',    '7 and greater are invalid');
-    is($date->get_weekday(6),  'Sat', '6 is Saturday');
-    is($date->get_weekday(0),  'Sun', '0 is Sunday');
-    is($date->get_weekday(-1), 'Sat', '-1 is Saturday');
-    is($date->get_weekday(-7), 'Sun', '-7 is Sunday');
-    is($date->get_weekday(-8), '',    '-8 and lesser are invalid');
-}
-
-{ # GetMonth
-    my $date = RT::Date->new(current_user => RT->system_user);
-    is($date->get_month(12),  '',     '12 and greater are invalid');
-    is($date->get_month(11),  'Dec', '11 is December');
-    is($date->get_month(0),   'Jan', '0 is January');
-    is($date->get_month(-1),  'Dec', '11 is December');
-    is($date->get_month(-12), 'Jan', '0 is January');
-    is($date->get_month(-13),  '',    '-13 and lesser are invalid');
-}
-
 #TODO: AsString
-#TODO: RFC2822, W3CDTF with timezones
+#TODO: RFC2822 with time zones
 
 exit(0);
 

Modified: rt/3.999/branches/datetime/t/api/ticket.t
==============================================================================
--- rt/3.999/branches/datetime/t/api/ticket.t	(original)
+++ rt/3.999/branches/datetime/t/api/ticket.t	Fri Mar 13 14:21:34 2009
@@ -91,7 +91,7 @@
 ok ( my $id = $t->id, "Got ticket id");
 like ($t->refers_to->first->target , qr/fsck.com/, "Got refers to");
 like ($t->referred_to_by->first->base , qr/cpan.org/, "Got referredtoby");
-is ($t->resolved_obj->unix, 0, "It hasn't been resolved - ". $t->resolved_obj->unix);
+is ($t->resolved->epoch, 0, "It hasn't been resolved - ". $t->resolved->epoch);
 
 
 my $ticket = RT::Model::Ticket->new(current_user => RT->system_user);

Modified: rt/3.999/branches/datetime/t/ticket/search_by_txn.t
==============================================================================
--- rt/3.999/branches/datetime/t/ticket/search_by_txn.t	(original)
+++ rt/3.999/branches/datetime/t/ticket/search_by_txn.t	Fri Mar 13 14:21:34 2009
@@ -26,11 +26,11 @@
 
 isa_ok($txnobj, 'RT::Model::Transaction');
 
-ok($txnobj->created_obj->iso);
+ok($txnobj->created->iso);
 my ( $sid,$smsg) = $txnobj->__set(column => 'created', value => '2005-08-05 20:00:56');
 ok($sid,$smsg);
 is($txnobj->created,'2005-08-05 20:00:56');
-is($txnobj->created_obj->iso,'2005-08-05 20:00:56');
+is($txnobj->created->iso,'2005-08-05 20:00:56');
 
 $tix->from_sql(qq{Updated = "2005-08-05" AND subject = "$SUBJECT"});
 is( $tix->count, 1);


More information about the Rt-commit mailing list