[Rt-commit] r18618 - in rt/3.999/trunk: .
sartak at bestpractical.com
sartak at bestpractical.com
Mon Mar 2 20:30:57 EST 2009
Author: sartak
Date: Mon Mar 2 20:30:57 2009
New Revision: 18618
Modified:
rt/3.999/trunk/ (props changed)
rt/3.999/trunk/t/api/date.t
Log:
r80782 at onn: sartak | 2009-03-02 20:30:22 -0500
Begin fixing t/api/date
Modified: rt/3.999/trunk/t/api/date.t
==============================================================================
--- rt/3.999/trunk/t/api/date.t (original)
+++ rt/3.999/trunk/t/api/date.t Mon Mar 2 20:30:57 2009
@@ -4,17 +4,17 @@
use Test::MockTime qw(set_fixed_time restore_time);
use RT::Test;
-use Test::More tests => 166;
+use Test::More tests => 165;
use RT::Model::User;
use Test::Warn;
-use_ok('RT::Date');
+use_ok('RT::DateTime');
+
{
- 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 $date = RT::DateTime->now(current_user => RT->system_user);
+ isa_ok($date, 'RT::DateTime', "constructor returned RT::DateTime oject");
+ is($date->current_user, RT->system_user, "correctly set the datetime's current_user");
}
{
@@ -37,7 +37,7 @@
}
{
- my $date = RT::Date->new(current_user => $current_user );
+ my $date = RT::DateTime->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");
@@ -89,7 +89,7 @@
}
{
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
is($date->epoch, 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'),
@@ -189,14 +189,14 @@
{ # positive timezone
$current_user->user_object->__set( column => 'timezone', value => 'Europe/Moscow');
- my $date = RT::Date->new( current_user => $current_user );
+ my $date = RT::DateTime->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");
# DST
- $date = RT::Date->new(current_user => $current_user );
+ $date = RT::DateTime->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");
@@ -205,14 +205,14 @@
{ # negative timezone
$current_user->user_object->__set( column => 'timezone', value => 'America/New_York');
- my $date = RT::Date->new( current_user => $current_user );
+ my $date = RT::DateTime->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");
# DST
- $date = RT::Date->new( current_user => $current_user );
+ $date = RT::DateTime->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");
@@ -220,13 +220,13 @@
}
# bad format
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
$date->set( format => 'bad' );
is($date->epoch, undef, "bad format");
{ # setting value via Unix method
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
$date->epoch(1);
is($date->iso, '1970-01-01 00:00:01', "correct value");
@@ -243,7 +243,7 @@
my $year = (localtime(time))[5] + 1900;
{ # set+ISO format
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->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->epoch, undef, "date was wrong => unix == 0");
@@ -286,7 +286,7 @@
}
{ # set+datemanip format(time::ParseDate)
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
$date->set(format => 'unknown', value => 'weird date');
is($date->epoch, 0, "date was wrong");
@@ -299,13 +299,13 @@
is($date->iso, '2005-11-28 15: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 = RT::DateTime->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);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
$date->set(format => 'unknown', value => 'weird date');
is($date->epoch, 0, "date was wrong");
@@ -332,7 +332,7 @@
is($date->iso, '2005-11-28 15: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 = RT::DateTime->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' );
@@ -342,7 +342,7 @@
}
{ # SetToMidnight
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
RT->config->set( Timezone => 'Europe/Moscow' );
$date->set(format => 'ISO', value => '2005-11-28 15:10:00');
@@ -359,7 +359,7 @@
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 = RT::DateTime->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");
@@ -376,7 +376,7 @@
}
{ # set_to_now
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
my $time = time;
$date->set_to_now;
ok($date->epoch >= $time, 'close enough');
@@ -384,7 +384,7 @@
}
{
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
$date->epoch(0);
$date->add_seconds;
@@ -425,7 +425,7 @@
{
$current_user->user_object->__set( column => 'timezone', value => '');
- my $date = RT::Date->new(current_user => $current_user );
+ my $date = RT::DateTime->new(current_user => $current_user );
is($date->as_string, "Not set", "as_string returns 'Not set'");
RT->config->set( DateTimeFormat => '');
@@ -446,7 +446,7 @@
}
{ # DurationAsString
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->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');
@@ -467,7 +467,7 @@
}
{ # DiffAsString
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->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');
@@ -478,14 +478,14 @@
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);
+ my $ndate = RT::DateTime->new(current_user => RT->system_user);
is($date->diff_as_string($ndate), '', 'no diff, wrong input');
$ndate->epoch(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);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
$date->set_to_now;
my $diff = $date->diff;
ok($diff <= 0, 'close enought');
@@ -493,14 +493,14 @@
}
{ # AgeAsString
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->new(current_user => RT->system_user);
$date->set_to_now;
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);
+ my $date = RT::DateTime->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');
@@ -510,7 +510,7 @@
}
{ # GetMonth
- my $date = RT::Date->new(current_user => RT->system_user);
+ my $date = RT::DateTime->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');
More information about the Rt-commit
mailing list