2 use Test::MockTime qw(set_fixed_time restore_time);
7 use RT::Test tests => undef;
13 my $date = RT::Date->new(RT->SystemUser);
14 isa_ok($date, 'RT::Date', "constructor returned RT::Date oject");
15 $date = $date->new(RT->SystemUser);
16 isa_ok($date, 'RT::Date', "constructor returned RT::Date oject");
20 # set timezone in all places to UTC
21 RT->SystemUser->UserObj->__Set(Field => 'Timezone', Value => 'UTC')
22 if RT->SystemUser->UserObj->Timezone;
23 RT->Config->Set( Timezone => 'UTC' );
28 my $user = RT::User->new(RT->SystemUser);
29 my($uid, $msg) = $user->Create(
30 Name => "date_api". rand(200),
34 ok($uid, "user was created") or diag("error: $msg");
35 $current_user = RT::CurrentUser->new($user);
39 my $date = RT::Date->new( $current_user );
40 is($date->Timezone('user'), 'UTC', "dropped all timzones to UTC");
41 is($date->Timezone('server'), 'UTC', "dropped all timzones to UTC");
42 is($date->Timezone('unknown'), 'UTC', "with wrong context returns UTC");
44 $current_user->UserObj->__Set( Field => 'Timezone', Value => 'Europe/Moscow');
45 is($current_user->UserObj->Timezone,
47 "successfuly changed user's timezone");
48 is($date->Timezone('user'),
50 "in user context returns user's timezone");
51 is($date->Timezone('server'), 'UTC', "wasn't changed");
53 RT->Config->Set( Timezone => 'Africa/Ouagadougou' );
54 is($date->Timezone('server'),
56 "timezone of the RT server was changed");
57 is($date->Timezone('user'),
59 "in user context still returns user's timezone");
61 $current_user->UserObj->__Set( Field => 'Timezone', Value => '');
62 is_empty($current_user->UserObj->Timezone,
63 "successfuly changed user's timezone");
64 is($date->Timezone('user'),
66 "in user context returns timezone of the server if user's one is not defined");
68 RT->Config->Set( Timezone => 'GMT' );
69 is($date->Timezone('server'),
71 "timezone is GMT which one is alias for UTC");
73 RT->Config->Set( Timezone => '' );
74 is($date->Timezone('user'),
76 "user's and server's timzones are not defined, so UTC");
77 is($date->Timezone('server'),
79 "timezone of the server is not defined so UTC");
81 RT->Config->Set( Timezone => 'UTC' );
85 my $date = RT::Date->new(RT->SystemUser);
86 is($date->IsSet,0, "new date isn't set");
87 is($date->Unix, 0, "new date returns 0 in Unix format");
88 is($date->Get, '1970-01-01 00:00:00', "default is ISO format");
90 is($date->Get(Format =>'SomeBadFormat'),
91 '1970-01-01 00:00:00',
92 "don't know format, return ISO format");
93 } qr/Invalid date formatter/;
94 is($date->Get(Format =>'W3CDTF'),
95 '1970-01-01T00:00:00Z',
96 "W3CDTF format with defaults");
97 is($date->Get(Format =>'RFC2822'),
98 'Thu, 01 Jan 1970 00:00:00 +0000',
99 "RFC2822 format with defaults");
100 is($date->Get(Format =>'LocalizedDateTime'),
101 'Thu, Jan 1, 1970 12:00:00 AM',
102 "LocalizedDateTime format with defaults");
104 is($date->ISO(Time => 0),
106 "ISO format without time part");
107 is($date->W3CDTF(Time => 0),
109 "W3CDTF format without time part");
110 is($date->RFC2822(Time => 0),
112 "RFC2822 format without time part");
113 is($date->LocalizedDateTime(Time => 0),
115 "LocalizedDateTime format without time part");
117 is($date->ISO(Date => 0),
119 "ISO format without date part");
120 is($date->W3CDTF(Date => 0),
121 '1970-01-01T00:00:00Z',
122 "W3CDTF format is incorrect without date part");
123 is($date->RFC2822(Date => 0),
125 "RFC2822 format without date part");
126 is($date->LocalizedDateTime(Date => 0),
128 "LocalizedDateTime format without date part");
130 is($date->ISO(Date => 0, Seconds => 0),
132 "ISO format without date part and seconds");
133 is($date->W3CDTF(Date => 0, Seconds => 0),
135 "W3CDTF format without seconds, but we ship date part even if Date is false");
136 is($date->RFC2822(Date => 0, Seconds => 0),
138 "RFC2822 format without date part and seconds");
140 is($date->RFC2822(DayOfWeek => 0),
141 '01 Jan 1970 00:00:00 +0000',
142 "RFC2822 format without 'day of week' part");
143 is($date->RFC2822(DayOfWeek => 0, Date => 0),
145 "RFC2822 format without 'day of week' and date parts(corner case test)");
147 is($date->LocalizedDateTime(AbbrDay => 0),
148 'Thursday, Jan 1, 1970 12:00:00 AM',
149 "LocalizedDateTime format without abbreviation of day");
150 is($date->LocalizedDateTime(AbbrMonth => 0),
151 'Thu, January 1, 1970 12:00:00 AM',
152 "LocalizedDateTime format without abbreviation of month");
153 is($date->LocalizedDateTime(DateFormat => 'date_format_short'),
154 '1/1/70 12:00:00 AM',
155 "LocalizedDateTime format with non default DateFormat");
156 is($date->LocalizedDateTime(TimeFormat => 'time_format_short'),
157 'Thu, Jan 1, 1970 12:00 AM',
158 "LocalizedDateTime format with non default TimeFormat");
162 "the default format for the 'Date' method is ISO");
163 is($date->Date(Format => 'W3CDTF'),
165 "'Date' method, W3CDTF format");
166 is($date->Date(Format => 'RFC2822'),
168 "'Date' method, RFC2822 format");
169 is($date->Date(Time => 1),
171 "'Date' method doesn't pass through 'Time' argument");
172 is($date->Date(Date => 0),
174 "'Date' method overrides 'Date' argument");
178 "the default format for the 'Time' method is ISO");
179 is($date->Time(Format => 'W3CDTF'),
180 '1970-01-01T00:00:00Z',
181 "'Time' method, W3CDTF format, date part is required by w3c doc");
182 is($date->Time(Format => 'RFC2822'),
184 "'Time' method, RFC2822 format");
185 is($date->Time(Date => 1),
187 "'Time' method doesn't pass through 'Date' argument");
188 is($date->Time(Time => 0),
190 "'Time' method overrides 'Time' argument");
193 '1970-01-01 00:00:00',
194 "the default format for the 'DateTime' method is ISO");
195 is($date->DateTime(Format =>'W3CDTF'),
196 '1970-01-01T00:00:00Z',
197 "'DateTime' method, W3CDTF format");
198 is($date->DateTime(Format =>'RFC2822'),
199 'Thu, 01 Jan 1970 00:00:00 +0000',
200 "'DateTime' method, RFC2822 format");
201 is($date->DateTime(Date => 0, Time => 0),
202 '1970-01-01 00:00:00',
203 "the 'DateTime' method overrides both 'Date' and 'Time' arguments");
207 { # positive timezone
208 $current_user->UserObj->__Set( Field => 'Timezone', Value => 'Europe/Moscow');
209 my $date = RT::Date->new( $current_user );
210 $date->Set( Format => 'ISO', Timezone => 'utc', Value => '2005-01-01 15:10:00' );
211 is($date->IsSet,1,"Date has been set");
212 is($date->ISO( Timezone => 'user' ), '2005-01-01 18:10:00', "ISO");
213 is($date->W3CDTF( Timezone => 'user' ), '2005-01-01T18:10:00+03:00', "W3C DTF");
214 is($date->RFC2822( Timezone => 'user' ), 'Sat, 01 Jan 2005 18:10:00 +0300', "RFC2822");
217 $date = RT::Date->new( $current_user );
218 $date->Set( Format => 'ISO', Timezone => 'utc', Value => '2005-07-01 15:10:00' );
219 is($date->ISO( Timezone => 'user' ), '2005-07-01 19:10:00', "ISO");
220 is($date->W3CDTF( Timezone => 'user' ), '2005-07-01T19:10:00+04:00', "W3C DTF");
221 is($date->RFC2822( Timezone => 'user' ), 'Fri, 01 Jul 2005 19:10:00 +0400', "RFC2822");
224 { # negative timezone
225 $current_user->UserObj->__Set( Field => 'Timezone', Value => 'America/New_York');
226 my $date = RT::Date->new( $current_user );
227 $date->Set( Format => 'ISO', Timezone => 'utc', Value => '2005-01-01 15:10:00' );
228 is($date->ISO( Timezone => 'user' ), '2005-01-01 10:10:00', "ISO");
229 is($date->W3CDTF( Timezone => 'user' ), '2005-01-01T10:10:00-05:00', "W3C DTF");
230 is($date->RFC2822( Timezone => 'user' ), 'Sat, 01 Jan 2005 10:10:00 -0500', "RFC2822");
233 $date = RT::Date->new( $current_user );
234 $date->Set( Format => 'ISO', Timezone => 'utc', Value => '2005-07-01 15:10:00' );
235 is($date->ISO( Timezone => 'user' ), '2005-07-01 11:10:00', "ISO");
236 is($date->W3CDTF( Timezone => 'user' ), '2005-07-01T11:10:00-04:00', "W3C DTF");
237 is($date->RFC2822( Timezone => 'user' ), 'Fri, 01 Jul 2005 11:10:00 -0400', "RFC2822");
242 my $date = RT::Date->new(RT->SystemUser);
243 $date->Set( Format => 'bad' );
244 ok(!$date->IsSet, "bad format");
245 } qr{Unknown Date format: bad};
248 { # setting value via Unix method
249 my $date = RT::Date->new(RT->SystemUser);
251 is($date->ISO, '1970-01-01 00:00:01', "correct value");
253 foreach (undef, 0, '', -5){
255 is($date->ISO, '1970-01-01 00:00:01', "correct value");
256 is($date->IsSet,1,"Date has been set to a value");
258 $date->Set(Format => 'unix', Value => $_);
259 is($date->ISO, '1970-01-01 00:00:00', "Set a date to midnight 1/1/1970 GMT due to wrong call");
260 is($date->Unix, 0, "unix is 0 => unset");
261 is($date->IsSet,0,"Date has been unset");
264 foreach (undef, 0, '', -5){
266 is($date->ISO, '1970-01-01 00:00:01', "correct value");
267 is($date->IsSet,1,"Date has been set to a value");
270 is($date->ISO, '1970-01-01 00:00:00', "Set a date to midnight 1/1/1970 GMT due to wrong call");
271 is($date->Unix, 0, "unix is 0 => unset");
272 is($date->IsSet,0,"Date has been unset");
276 my $year = (localtime(time))[5] + 1900;
279 my $date = RT::Date->new(RT->SystemUser);
281 $date->Set(Format => 'ISO', Value => 'weird date');
282 } qr/Couldn't parse date 'weird date' as a ISO format/;
283 ok(!$date->IsSet, "date was wrong => unix == 0");
285 # XXX: ISO format has more feature than we suport
286 # http://www.cl.cam.ac.uk/~mgk25/iso-time.html
288 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
289 is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
291 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00+00');
292 is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss+00");
294 $date->Set(Format => 'ISO', Value => '11-28 15:10:00');
295 is($date->ISO, $year .'-11-28 15:10:00', "DD-MM hh:mm:ss");
297 $date->Set(Format => 'ISO', Value => '11-28 15:10:00+00');
298 is($date->ISO, $year .'-11-28 15:10:00', "DD-MM hh:mm:ss+00");
300 $date->Set(Format => 'ISO', Value => '20051128151000');
301 is($date->ISO, '2005-11-28 15:10:00', "YYYYDDMMhhmmss");
303 $date->Set(Format => 'ISO', Value => '1128151000');
304 is($date->ISO, $year .'-11-28 15:10:00', "DDMMhhmmss");
306 $date->Set(Format => 'ISO', Value => '2005112815:10:00');
307 is($date->ISO, '2005-11-28 15:10:00', "YYYYDDMMhh:mm:ss");
309 $date->Set(Format => 'ISO', Value => '112815:10:00');
310 is($date->ISO, $year .'-11-28 15:10:00', "DDMMhh:mm:ss");
313 $date->Set(Format => 'ISO', Value => '2005-13-28 15:10:00');
315 ok(!$date->IsSet, "wrong month value");
318 $date->Set(Format => 'ISO', Value => '2005-00-28 15:10:00');
320 ok(!$date->IsSet, "wrong month value");
322 $date->Set(Format => 'ISO', Value => '1960-01-28 15:10:00');
323 ok(!$date->IsSet, "too old, we don't support");
326 { # set+datemanip format(Time::ParseDate)
327 my $date = RT::Date->new(RT->SystemUser);
329 RT->Config->Set( Timezone => 'Europe/Moscow' );
330 $date->Set(Format => 'datemanip', Value => '2005-11-28 15:10:00');
331 is($date->ISO, '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
333 RT->Config->Set( Timezone => 'UTC' );
334 $date->Set(Format => 'datemanip', Value => '2005-11-28 15:10:00');
335 is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
337 $current_user->UserObj->__Set( Field => 'Timezone', Value => 'Europe/Moscow');
338 $date = RT::Date->new( $current_user );
339 $date->Set(Format => 'datemanip', Value => '2005-11-28 15:10:00');
340 is($date->ISO, '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
343 { # set+unknown format(Time::ParseDate)
344 my $date = RT::Date->new(RT->SystemUser);
346 $date->Set(Format => 'unknown', Value => 'weird date');
347 } qr{Couldn't parse date 'weird date' by Time::ParseDate};
348 ok(!$date->IsSet, "date was wrong");
350 RT->Config->Set( Timezone => 'Europe/Moscow' );
351 $date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00');
352 is($date->ISO, '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
354 $date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00', Timezone => 'utc' );
355 is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
357 # test relative dates
359 set_fixed_time("2005-11-28T15:10:00Z");
360 $date->Set(Format => 'unknown', Value => 'now');
361 is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
363 $date->Set(Format => 'unknown', Value => '1 day ago');
364 is($date->ISO, '2005-11-27 15:10:00', "YYYY-DD-MM hh:mm:ss");
368 RT->Config->Set( Timezone => 'UTC' );
369 $date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00');
370 is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
372 $current_user->UserObj->__Set( Field => 'Timezone', Value => 'Europe/Moscow');
373 $date = RT::Date->new( $current_user );
374 $date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00');
375 is($date->ISO, '2005-11-28 12:10:00', "YYYY-DD-MM hh:mm:ss");
376 $date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00', Timezone => 'server' );
377 is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
378 $date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00', Timezone => 'utc' );
379 is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
382 { # 'tomorrow 10am' with TZ
383 $current_user->UserObj->__Set( Field => 'Timezone', Value => 'Europe/Moscow');
385 set_fixed_time("2012-06-14T15:10:00Z"); # 14th in UTC and Moscow
386 my $date = RT::Date->new( $current_user );
387 $date->Set(Format => 'unknown', Value => 'tomorrow 10am');
388 is($date->ISO, '2012-06-15 06:00:00', "YYYY-DD-MM hh:mm:ss");
390 set_fixed_time("2012-06-13T23:10:00Z"); # 13th in UTC and 14th in Moscow
391 $date = RT::Date->new( $current_user );
392 $date->Set(Format => 'unknown', Value => 'tomorrow 10am');
393 is($date->ISO, '2012-06-15 06:00:00', "YYYY-DD-MM hh:mm:ss");
395 $current_user->UserObj->__Set( Field => 'Timezone', Value => 'US/Hawaii');
397 set_fixed_time("2012-06-14T20:10:00Z"); # 14th in UTC and Hawaii
398 $date = RT::Date->new( $current_user );
399 $date->Set(Format => 'unknown', Value => 'tomorrow 10am');
400 is($date->ISO, '2012-06-15 20:00:00', "YYYY-DD-MM hh:mm:ss");
402 set_fixed_time("2012-06-15T05:10:00Z"); # 15th in UTC and 14th in Hawaii
403 $date = RT::Date->new( $current_user );
404 $date->Set(Format => 'unknown', Value => 'tomorrow 10am');
405 is($date->ISO, '2012-06-15 20:00:00', "YYYY-DD-MM hh:mm:ss");
411 my $date = RT::Date->new(RT->SystemUser);
413 RT->Config->Set( Timezone => 'Europe/Moscow' );
414 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
415 $date->SetToMidnight;
416 is($date->ISO, '2005-11-28 00:00:00', "default is utc");
417 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
418 $date->SetToMidnight(Timezone => 'utc');
419 is($date->ISO, '2005-11-28 00:00:00', "utc context");
420 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
421 $date->SetToMidnight(Timezone => 'user');
422 is($date->ISO, '2005-11-27 21:00:00', "user context, user has no preference, fallback to server");
423 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
424 $date->SetToMidnight(Timezone => 'server');
425 is($date->ISO, '2005-11-27 21:00:00', "server context");
427 $current_user->UserObj->__Set( Field => 'Timezone', Value => 'Europe/Moscow');
428 $date = RT::Date->new( $current_user );
429 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
430 $date->SetToMidnight;
431 is($date->ISO, '2005-11-28 00:00:00', "default is utc");
432 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
433 $date->SetToMidnight(Timezone => 'utc');
434 is($date->ISO, '2005-11-28 00:00:00', "utc context");
435 $date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
436 $date->SetToMidnight(Timezone => 'user');
437 is($date->ISO, '2005-11-27 21:00:00', "user context");
438 $date->SetToMidnight(Timezone => 'server');
439 is($date->ISO, '2005-11-27 21:00:00', "server context");
441 RT->Config->Set( Timezone => 'UTC' );
445 my $date = RT::Date->new(RT->SystemUser);
448 ok($date->Unix >= $time, 'close enough');
449 ok($date->Unix < $time+5, 'difference is less than five seconds');
453 my $date = RT::Date->new(RT->SystemUser);
457 is($date->ISO, '1970-01-01 00:00:00', "nothing changed");
458 $date->AddSeconds(0);
459 is($date->ISO, '1970-01-01 00:00:00', "nothing changed");
462 $date->AddSeconds(5);
463 is($date->ISO, '1970-01-01 00:00:05', "added five seconds");
464 $date->AddSeconds(-2);
465 is($date->ISO, '1970-01-01 00:00:03', "substracted two seconds");
468 $date->AddSeconds(3661);
469 is($date->ISO, '1970-01-01 01:01:01', "added one hour, minute and a second");
471 # XXX: TODO, doesn't work with Test::Warn
473 # local $TODO = "BUG or subject to change Date handling to support unix time <= 0";
475 # $date->AddSeconds(-2);
476 # ok($date->Unix > 0);
481 is($date->ISO, '1970-01-02 00:00:00', "added one day");
483 is($date->ISO, '1970-01-04 00:00:00', "added two days");
485 is($date->ISO, '1970-01-03 00:00:00', "substructed one day");
489 is($date->ISO, '1970-02-01 00:00:00', "added one month");
493 is($date->ISO, '1970-01-01 00:00:00', "added no days");
497 is($date->ISO, '1970-01-02 00:00:00', "added one day with no argument");
501 $current_user->UserObj->__Set( Field => 'Timezone', Value => '');
502 my $date = RT::Date->new( $current_user );
503 is($date->AsString, "Not set", "AsString returns 'Not set'");
505 RT->Config->Set( DateTimeFormat => '');
507 is($date->AsString, 'Thu Jan 01 00:00:01 1970', "correct string");
508 is($date->AsString(Date => 0), '00:00:01', "correct string");
509 is($date->AsString(Time => 0), 'Thu Jan 01 1970', "correct string");
510 is($date->AsString(Date => 0, Time => 0), 'Thu Jan 01 00:00:01 1970', "invalid input");
512 RT->Config->Set( DateTimeFormat => 'RFC2822' );
514 is($date->AsString, 'Thu, 01 Jan 1970 00:00:01 +0000', "correct string");
516 RT->Config->Set( DateTimeFormat => { Format => 'RFC2822', Seconds => 0 } );
518 is($date->AsString, 'Thu, 01 Jan 1970 00:00 +0000', "correct string");
519 is($date->AsString(Seconds => 1), 'Thu, 01 Jan 1970 00:00:01 +0000', "correct string");
523 my $date = RT::Date->new(RT->SystemUser);
525 is($date->DurationAsString(1), '1 second', '1 sec');
526 is($date->DurationAsString(59), '59 seconds', '59 sec');
527 is($date->DurationAsString(60), '1 minute', '1 min');
528 is($date->DurationAsString(60*119), '119 minutes', '119 min');
529 is($date->DurationAsString(60*60*2-1), '120 minutes', '120 min');
530 is($date->DurationAsString(60*60*2), '2 hours', '2 hours');
531 is($date->DurationAsString(60*60*48-1), '48 hours', '48 hours');
532 is($date->DurationAsString(60*60*48), '2 days', '2 days');
533 is($date->DurationAsString(60*60*24*14-1), '14 days', '14 days');
534 is($date->DurationAsString(60*60*24*14), '2 weeks', '2 weeks');
535 is($date->DurationAsString(60*60*24*7*8-1), '8 weeks', '8 weeks');
536 is($date->DurationAsString(60*60*24*61), '2 months', '2 months');
537 is($date->DurationAsString(60*60*24*365-1), '12 months', '12 months');
538 is($date->DurationAsString(60*60*24*366), '1 year', '1 year');
540 is($date->DurationAsString(-1), '1 second ago', '1 sec ago');
544 my $date = RT::Date->new(RT->SystemUser);
545 is($date->DiffAsString(1), '', 'no diff, wrong input');
546 is($date->DiffAsString(-1), '', 'no diff, wrong input');
547 is($date->DiffAsString('qwe'), '', 'no diff, wrong input');
550 is($date->DiffAsString(-1), '', 'no diff, wrong input');
552 is($date->DiffAsString(3), '1 second ago', 'diff: 1 sec ago');
553 is($date->DiffAsString(1), '1 second', 'diff: 1 sec');
555 my $ndate = RT::Date->new(RT->SystemUser);
556 is($date->DiffAsString($ndate), '', 'no diff, wrong input');
558 is($date->DiffAsString($ndate), '1 second ago', 'diff: 1 sec ago');
562 my $date = RT::Date->new(RT->SystemUser);
564 my $diff = $date->Diff;
565 ok($diff <= 0, 'close enought');
566 ok($diff > -5, 'close enought');
570 my $date = RT::Date->new(RT->SystemUser);
572 my $diff = $date->AgeAsString;
573 like($diff, qr/^(0 seconds|(1 second|[2-5] seconds) ago)$/, 'close enought');
577 my $date = RT::Date->new(RT->SystemUser);
578 is($date->GetWeekday(7), '', '7 and greater are invalid');
579 is($date->GetWeekday(6), 'Sat', '6 is Saturday');
580 is($date->GetWeekday(0), 'Sun', '0 is Sunday');
581 is($date->GetWeekday(-1), 'Sat', '-1 is Saturday');
582 is($date->GetWeekday(-7), 'Sun', '-7 is Sunday');
583 is($date->GetWeekday(-8), '', '-8 and lesser are invalid');
587 my $date = RT::Date->new(RT->SystemUser);
588 is($date->GetMonth(12), '', '12 and greater are invalid');
589 is($date->GetMonth(11), 'Dec', '11 is December');
590 is($date->GetMonth(0), 'Jan', '0 is January');
591 is($date->GetMonth(-1), 'Dec', '11 is December');
592 is($date->GetMonth(-12), 'Jan', '0 is January');
593 is($date->GetMonth(-13), '', '-13 and lesser are invalid');
597 # set unknown format: edge cases
598 my $date = RT::Date->new(RT->SystemUser);
599 $date->Set( Value => 0, Format => 'unknown' );
600 ok( !$date->IsSet, "unix is 0 with Value => 0, Format => 'unknown'" );
602 $date->Set( Value => '', Format => 'unknown' );
603 ok( !$date->IsSet, "unix is 0 with Value => '', Format => 'unknown'" );
605 $date->Set( Value => ' ', Format => 'unknown' );
606 ok( !$date->IsSet, "unix is 0 with Value => ' ', Format => 'unknown'" );
610 #TODO: RFC2822, W3CDTF with Timezones