diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-12-27 19:01:41 -0800 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-12-27 19:01:41 -0800 |
commit | 8511956c25f92ccd6094dca45824697ad21cfdd4 (patch) | |
tree | 339c6be9e55fc02eae92912dcde3aec10bb2dbe5 /t | |
download | perl-TimeDate-8511956c25f92ccd6094dca45824697ad21cfdd4.tar.gz perl-TimeDate-8511956c25f92ccd6094dca45824697ad21cfdd4.tar.bz2 perl-TimeDate-8511956c25f92ccd6094dca45824697ad21cfdd4.zip |
Imported Upstream version 1.20upstream/1.20
Diffstat (limited to 't')
-rw-r--r-- | t/cpanrt.t | 55 | ||||
-rw-r--r-- | t/date.t | 193 | ||||
-rw-r--r-- | t/format.t | 184 | ||||
-rw-r--r-- | t/getdate.t | 209 | ||||
-rw-r--r-- | t/lang.t | 24 |
5 files changed, 665 insertions, 0 deletions
diff --git a/t/cpanrt.t b/t/cpanrt.t new file mode 100644 index 0000000..32b37e7 --- /dev/null +++ b/t/cpanrt.t @@ -0,0 +1,55 @@ +use Date::Format qw(time2str strftime); +use Date::Parse qw(strptime str2time); + +print "1..8\n"; + +my $i = 1; + +{ # RT#45067 Date::Format with %z gives wrong results for half-hour timezones + + foreach my $zone (qw(-0430 -0445)) { + my $zone_str = time2str("%Z %z", time, $zone); + print "# $zone => $zone_str\n"; + print "not " unless $zone_str eq "$zone $zone"; + print "ok ", $i++, "\n"; + } +} + + +{ # RT#48164: Date::Parse unable to set seconds correctly + + foreach my $str ("2008.11.30 22:35 CET", "2008-11-30 22:35 CET") { + my @t = strptime($str); + my $t = join ":", map { defined($_) ? $_ : "-" } @t; + print "# $str => $t\n"; + print "not " unless $t eq "-:35:22:30:10:108:3600"; + print "ok ", $i++, "\n"; + } +} + +{ # RT#17396: Parse error for french date with 'mars' (march) as month + use Date::Language; + my $dateP = Date::Language->new('French'); + my $timestamp = $dateP->str2time('4 mars 2005'); + my ($ss, $mm, $hh, $day, $month, $year, $zone) = localtime $timestamp; + $month++; + $year += 1900; + my $date = "$day/$month/$year"; + print "# $date\n"; + print "not " unless $date eq "4/3/2005"; + print "ok ", $i++, "\n"; +} + +{ # [rt.cpan.org #52387] seconds since the Epoch, UCT + my $time = time; + my @lt = localtime(time); + print "not " unless strftime("%s", @lt) eq $time; + print "ok ", $i++, "\n"; + print "not " unless time2str("%s",$time) eq $time; + print "ok ", $i++, "\n"; +} + +{ # [rt.cpan.org #51664] Change in str2time behaviour between 1.16 and 1.19 + print "not " if str2time('16 Oct 09') < 0; + print "ok ", $i++, "\n"; +} diff --git a/t/date.t b/t/date.t new file mode 100644 index 0000000..a2649ae --- /dev/null +++ b/t/date.t @@ -0,0 +1,193 @@ +#!/usr/local/bin/perl -w + +use Date::Parse; +use Date::Format qw(time2str); + +$data = qq!1995-01-24 +1995-01-24T09:08:17.1823213 +- 1935-01-24T09:08:17 +- Fri Dec 17 00:00:00 1901 GMT +Tue Jan 16 23:59:59 2038 GMT +2001-02-02 00:00:00 GMT +2035-02-02 00:00:00 GMT +- 16 Jun 33 07:29:35 CST +2002-02-26-10:37:21.141 GMT +Wed, 16 Jun 94 07:29:35 CST +Wed, 16 Nov 94 07:29:35 CST +Mon, 21 Nov 94 07:42:23 CST +Mon, 21 Nov 94 04:28:18 CST +Tue, 15 Nov 94 09:15:10 GMT +Wed, 16 Nov 94 09:39:49 GMT +Wed, 16 Nov 94 09:23:17 GMT +Wed, 16 Nov 94 12:39:49 GMT +Wed, 16 Nov 94 14:03:06 GMT +Wed, 16 Nov 94 05:30:51 CST +Thu, 17 Nov 94 03:19:30 CST +Mon, 21 Nov 94 14:05:32 GMT +Mon, 14 Nov 94 15:08:49 CST +Wed, 16 Nov 94 14:48:06 GMT +Thu, 17 Nov 94 14:22:03 GMT +Wed, 16 Nov 94 14:36:00 GMT +Wed, 16 Nov 94 09:23:17 GMT +Wed, 16 Nov 94 10:01:43 GMT +Wed, 16 Nov 94 15:03:35 GMT +Mon, 21 Nov 94 13:55:19 GMT +Wed, 16 Nov 94 08:46:11 CST +21 dec 17:05 +21-dec 17:05 +21/dec 17:05 +21/dec/93 17:05 +dec/21/93 17:05 +Dec/21/1993 17:05:00 +dec-21-1993 17:05 +Dec-21-93 17:05:00 +dec 21 1994 17:05 +dec 21 94 17:05 +dec 21 94 17:05 GMT +dec 21 94 17:05 BST +dec 21 94 00:05 -1700 +dec 21 94 17:05 -1700 +Wed, 9 Nov 1994 09:50:32 -0500 (EST) +Thu, 13 Oct 94 10:13:13 -0700 +Sat, 19 Nov 1994 16:59:14 +0100 +Thu, 3 Nov 94 14:10:47 EST +Thu, 3 Nov 94 21:51:09 EST +Fri, 4 Nov 94 9:24:52 EST +Wed, 9 Nov 94 09:38:54 EST +Mon, 14 Nov 94 13:20:12 EST +Wed, 16 Nov 94 17:09:13 EST +Tue, 15 Nov 94 12:27:01 PST +Fri, 18 Nov 1994 07:34:05 -0600 +Mon, 21 Nov 94 14:34:28 -0500 +Fri, 18 Nov 1994 12:05:47 -0800 (PST) +Fri, 18 Nov 1994 12:36:26 -0800 (PST) +Wed, 16 Nov 1994 15:58:58 GMT +1999 10:02:18 "GMT" +Sun, 06 Nov 94 14:27:40 -0500 +Mon, 07 Nov 94 08:20:13 -0500 +Mon, 07 Nov 94 16:48:42 -0500 +Wed, 09 Nov 94 15:46:16 -0500 +Fri, 4 Nov 94 16:17:40 "PST +Wed, 16 Nov 94 12:43:37 "PST +Sun, 6 Nov 1994 02:38:17 -0800 +Tue, 1 Nov 1994 13:53:49 -0500 +Tue, 15 Nov 94 08:31:59 +0100 +Sun, 6 Nov 1994 11:09:12 -0500 (IST) +Fri, 4 Nov 94 12:52:10 EST +Mon, 31 Oct 1994 14:17:39 -0500 (EST) +Mon, 14 Nov 94 11:25:00 CST +Mon, 14 Nov 94 13:26:29 CST +Fri, 18 Nov 94 8:42:47 CST +Thu, 17 Nov 94 14:32:01 +0900 +Wed, 2 Nov 94 18:16:31 +0100 +Fri, 18 Nov 94 10:46:26 +0100 +Tue, 8 Nov 1994 22:39:28 +0200 +Wed, 16 Nov 1994 10:01:08 -0500 (EST) +Wed, 2 Nov 1994 16:59:42 -0800 +Wed, 9 Nov 94 10:00:23 PST +Fri, 18 Nov 94 17:01:43 PST +Mon, 14 Nov 1994 14:47:46 -0500 +Mon, 21 Nov 1994 04:56:04 -0500 (EST) +Mon, 21 Nov 1994 11:50:12 -0800 +Sat, 5 Nov 1994 14:04:16 -0600 (CST) +Sat, 05 Nov 94 13:10:13 MST +Wed, 02 Nov 94 10:47:48 -0800 +Wed, 02 Nov 94 13:19:15 -0800 +Thu, 03 Nov 94 15:27:07 -0800 +Fri, 04 Nov 94 09:12:12 -0800 +Wed, 9 Nov 1994 10:13:03 +0000 (GMT) +Wed, 9 Nov 1994 15:28:37 +0000 (GMT) +Wed, 2 Nov 1994 17:37:41 +0100 (MET) +05 Nov 94 14:22:19 PST +16 Nov 94 22:28:20 PST +Tue, 1 Nov 1994 19:51:15 -0800 +Wed, 2 Nov 94 12:21:23 GMT +Fri, 18 Nov 94 18:07:03 GMT +Wed, 16 Nov 1994 11:26:27 -0500 +Sun, 6 Nov 1994 13:48:49 -0500 +Tue, 8 Nov 1994 13:19:37 -0800 +Fri, 18 Nov 1994 11:01:12 -0800 +Mon, 21 Nov 1994 00:47:58 -0500 +Mon, 7 Nov 1994 14:22:48 -0800 (PST) +Wed, 16 Nov 1994 15:56:45 -0800 (PST) +Thu, 3 Nov 1994 13:17:47 +0000 +Wed, 9 Nov 1994 17:32:50 -0500 (EST) +Wed, 9 Nov 94 16:31:52 PST +Wed, 09 Nov 94 10:41:10 -0800 +Wed, 9 Nov 94 08:42:22 MST +Mon, 14 Nov 1994 08:32:13 -0800 +Mon, 14 Nov 1994 11:34:32 -0500 (EST) +Mon, 14 Nov 94 16:48:09 GMT +Tue, 15 Nov 1994 10:27:33 +0000 +Wed, 02 Nov 94 13:56:54 MST +Thu, 03 Nov 94 15:24:45 MST +Thu, 3 Nov 1994 15:13:53 -0700 (MST) +Fri, 04 Nov 94 08:15:13 MST +Thu, 3 Nov 94 18:15:47 EST +Tue, 08 Nov 94 07:02:33 MST +Thu, 3 Nov 94 18:15:47 EST +Tue, 15 Nov 94 07:26:05 MST +Wed, 2 Nov 1994 00:00:55 -0600 (CST) +Sun, 6 Nov 1994 01:19:13 -0600 (CST) +Mon, 7 Nov 1994 23:16:57 -0600 (CST) +Tue, 08 Nov 1994 13:21:21 -0600 +Mon, 07 Nov 94 13:47:37 PST +Tue, 08 Nov 94 11:23:19 PST +Tue, 01 Nov 1994 11:28:25 -0800 +Tue, 15 Nov 1994 13:11:47 -0800 +Tue, 15 Nov 1994 13:18:38 -0800 +Tue, 15 Nov 1994 0:18:38 -0800 +10:00:00Z +10:00:00 +10:00 +10:00 +100 +10:00 +0100 +20020722T100000Z +Jul 22 10:00:00 UTC 2002 +2002-07-22 10:00:00Z +2002-07-22 10:00:00 Z +2002-07-22 10:00 Z +2002-07-22 10:00Z +2002-07-22 10:00 +100 +2002-07-22 10:00 +0100 +!; + +@data = split(/\n/, $data); + +print "1..", 1+@data,"\n"; + +print defined(str2time("")) ? "not ok 1\n" : "ok 1\n"; + +$loop = 2; + +foreach (@data) +{ + my $pre_1970 = s/^-\s*//; + + if ($pre_1970 and $^O eq "MSWin32") { + print "ok ",$loop++," # skip\n"; + next; + } + + $time = str2time($_); + + if(defined $time) + { + $time = int $time; + + $x = time2str("%a %b %e %T %Y %Z",$time,'GMT'); + + printf "%-40s\t%s\n", $_,$x,"\n"; + + $y = str2time($x); + + print "",($y == $time) ? "ok $loop\n" : "not ok $loop # $y != $time\n"; + } + else + { + print "not ok $loop # $_\n"; + } + + $loop++; +} + diff --git a/t/format.t b/t/format.t new file mode 100644 index 0000000..15765c2 --- /dev/null +++ b/t/format.t @@ -0,0 +1,184 @@ + +use Date::Format qw(ctime time2str); +use Date::Language; + +print "1..152\n"; + +my $i = 1; + +$pkg = 'Date::Format::Generic'; + +while(<DATA>) { + chomp; + if (/^(\d+)/) { + $t = $1; + next; + } + elsif (/^(\w+)/) { + $pkg = Date::Language->new($1); + next; + } + + my($fmt,$res) = split(/\t+/,$_); + my $str = $pkg->time2str($fmt,$t,'GMT'); + print "# '$fmt'$res'$str'\nnot " unless $str eq $res; + print "ok ",$i++,"\n"; +} + +__DATA__ +936709362 # Tue Sep 7 11:22:42 1999 GMT +%y 99 +%Y 1999 +%% % +%a Tue +%A Tuesday +%b Sep +%B September +%c 09/07/99 13:02:42 +%C Tue Sep 7 13:02:42 GMT 1999 +%d 07 +%e 7 +%D 09/07/99 +%G 1026 +%h Sep +%H 13 +%I 01 +%j 250 +%k 13 +%l 1 +%L 9 +%m 09 +%M 02 +%o 7th +%p PM +%q 3 +%r 01:02:42 PM +%R 13:02 +%s 936709362 +%S 42 +%T 13:02:42 +%U 36 +%w 2 +%W 36 +%x 09/07/99 +%X 13:02:42 +%y 99 +%Y 1999 +%Z GMT +%z +0000 +%Od VII +%Oe VII +%OH XIII +%OI I +%Oj CCL +%Ok XIII +%Ol I +%Om IX +%OM II +%Oq III +%OY MCMXCIX +%Oy XCIX +German +%y 99 +%Y 1999 +%% % +%a Die +%A Dienstag +%b Sep +%B September +%c 09/07/99 13:02:42 +%C Die Sep 7 13:02:42 GMT 1999 +%d 07 +%e 7 +%D 09/07/99 +%h Sep +%H 13 +%I 01 +%j 250 +%k 13 +%l 1 +%L 9 +%m 09 +%M 02 +%o 7. +%p PM +%q 3 +%r 01:02:42 PM +%R 13:02 +%s 936709362 +%S 42 +%T 13:02:42 +%U 36 +%w 2 +%W 36 +%x 09/07/99 +%X 13:02:42 +%y 99 +%Y 1999 +%Z GMT +%z +0000 +%Od VII +%Oe VII +%OH XIII +%OI I +%Oj CCL +%Ok XIII +%Ol I +%Om IX +%OM II +%Oq III +%OY MCMXCIX +%Oy XCIX +Italian +%y 99 +%Y 1999 +%% % +%a Mar +%A Martedi +%b Set +%B Settembre +%c 09/07/99 13:02:42 +%C Mar Set 7 13:02:42 GMT 1999 +%d 07 +%e 7 +%D 09/07/99 +%h Set +%H 13 +%I 01 +%j 250 +%k 13 +%l 1 +%L 9 +%m 09 +%M 02 +%o 7th +%p PM +%q 3 +%r 01:02:42 PM +%R 13:02 +%s 936709362 +%S 42 +%T 13:02:42 +%U 36 +%w 2 +%W 36 +%x 09/07/99 +%X 13:02:42 +%y 99 +%Y 1999 +%Z GMT +%z +0000 +%Od VII +%Oe VII +%OH XIII +%OI I +%Oj CCL +%Ok XIII +%Ol I +%Om IX +%OM II +%Oq III +%OY MCMXCIX +%Oy XCIX +316051200 # Mon Jan 7 00:00:00 1980 GMT +%G 0 diff --git a/t/getdate.t b/t/getdate.t new file mode 100644 index 0000000..31b577b --- /dev/null +++ b/t/getdate.t @@ -0,0 +1,209 @@ +#!/usr/local/bin/perl -w + +#Thanks to Andreas Koenig for converting all those dates to numbers +#and adding the folloing acknowledgement into Date/t/getdate.t +#Thanks to Graham Barr for writing these tests. Slightly adjusted for +#the C version by Andreas Koenig, 96-06-08. + +use Date::Parse; + +$data = qq!1995-01-24 ;790905600 +1995-06-24 ;803952000 +92/01/02 12:01 ;694353660 +92/01/02 12:01 AM ;694310460 +92/01/02 12:01 PM ;694353660 +2002-11-02 11pm GMT ;1036278000 +2002-11-02 11 pm GMT ;1036278000 +1995-01-24 GMT ;790905600 +1995-01-24 BST ;790902000 +1995-06-24 GMT ;803952000 +1995-06-24 BST ;803948400 +1992-1-2 12:01 GMT ;694353660 +1992-1-2-12:01:00 GMT ;694353660 +Wed, 16 Jun 94 07:29:35 CST ;771773375 +Wed,16 Jun 94 07:29:35 CST ;771773375 +Wed, 16 Nov 94 07:29:35 CST ;784992575 +Mon, 21 Nov 94 07:42:23 CST ;785425343 +Mon, 21 Nov 94 04:28:18 CST ;785413698 +Tue, 15 Nov 94 09:15:10 GMT ;784890910 +Wed, 16 Nov 94 09:39:49 GMT ;784978789 +Wed, 16 Nov 94 09:23:17 GMT ;784977797 +Wed, 16 Nov 94 12:39:49 GMT ;784989589 +Wed, 16 Nov 94 14:03:06 GMT ;784994586 +Wed, 16 Nov 94 05:30:51 CST ;784985451 +Thu, 17 Nov 94 03:19:30 CST ;785063970 +1994:11:21T14:05:32+0000 ;785426732 +Mon, 21 Nov 94 14:05:32 GMT ;785426732 +Mon, 14 Nov 94 15:08:49 CST ;784847329 +Wed, 16 Nov 94 14:48:06 GMT ;784997286 +Thu, 17 Nov 94 14:22:03 GMT ;785082123 +Wed, 16 Nov 94 14:36:00 GMT ;784996560 +Wed, 16 Nov 94 09:23:17 GMT ;784977797 +Wed, 16 Nov 94 10:01:43 GMT ;784980103 +Wed, 16 Nov 94 15:03:35 GMT ;784998215 +Mon, 21 Nov 94 13:55:19 GMT ;785426119 +Wed, 16 Nov 94 08:46:11 CST ;784997171 +Wed, 9 Nov 1994 09:50:32 -0500 (EST) ;784392632 +Thu, 13 Oct 94 10:13:13 -0700 ;782068393 +Sat, 19 Nov 1994 16:59:14 +0100 ;785260754 +Thu, 3 Nov 94 14:10:47 EST ;783889847 +Thu, 3 Nov 94 21:51:09 EST ;783917469 +Fri, 4 Nov 94 9:24:52 EST ;783959092 +Wed, 9 Nov 94 09:38:54 EST ;784391934 +Mon, 14 Nov 94 13:20:12 EST ;784837212 +Wed, 16 Nov 94 17:09:13 EST ;785023753 +Tue, 15 Nov 94 12:27:01 PST ;784931221 +Fri, 18 Nov 1994 07:34:05 -0600 ;785165645 +Mon, 21 Nov 94 14:34:28 -0500 ;785446468 +Fri, 18 Nov 1994 12:05:47 -0800 (PST);785189147 +Fri, 18 Nov 1994 12:36:26 -0800 (PST);785190986 +Wed, 16 Nov 1994 15:58:58 GMT ;785001538 +Sun, 06 Nov 94 14:27:40 -0500 ;784150060 +Mon, 07 Nov 94 08:20:13 -0500 ;784214413 +Mon, 07 Nov 94 16:48:42 -0500 ;784244922 +Wed, 09 Nov 94 15:46:16 -0500 ;784413976 +Sun, 6 Nov 1994 02:38:17 -0800 ;784118297 +Tue, 1 Nov 1994 13:53:49 -0500 ;783716029 +Tue, 15 Nov 94 08:31:59 +0100 ;784884719 +Sun, 6 Nov 1994 11:09:12 -0500 (IST) ;784138152 +Fri, 4 Nov 94 12:52:10 EST ;783971530 +Mon, 31 Oct 1994 14:17:39 -0500 (EST);783631059 +Mon, 14 Nov 94 11:25:00 CST ;784833900 +Mon, 14 Nov 94 13:26:29 CST ;784841189 +Fri, 18 Nov 94 8:42:47 CST ;785169767 +Thu, 17 Nov 94 14:32:01 +0900 ;785050321 +Wed, 2 Nov 94 18:16:31 +0100 ;783796591 +Fri, 18 Nov 94 10:46:26 +0100 ;785151986 +Tue, 8 Nov 1994 22:39:28 +0200 ;784327168 +Wed, 16 Nov 1994 10:01:08 -0500 (EST);784998068 +Wed, 2 Nov 1994 16:59:42 -0800 ;783824382 +Wed, 9 Nov 94 10:00:23 PST ;784404023 +Fri, 18 Nov 94 17:01:43 PST ;785206903 +Mon, 14 Nov 1994 14:47:46 -0500 ;784842466 +Mon, 21 Nov 1994 04:56:04 -0500 (EST);785411764 +Mon, 21 Nov 1994 11:50:12 -0800 ;785447412 +Sat, 5 Nov 1994 14:04:16 -0600 (CST) ;784065856 +Sat, 05 Nov 94 13:10:13 MST ;784066213 +Wed, 02 Nov 94 10:47:48 -0800 ;783802068 +Wed, 02 Nov 94 13:19:15 -0800 ;783811155 +Thu, 03 Nov 94 15:27:07 -0800 ;783905227 +Fri, 04 Nov 94 09:12:12 -0800 ;783969132 +Wed, 9 Nov 1994 10:13:03 +0000 (GMT) ;784375983 +Wed, 9 Nov 1994 15:28:37 +0000 (GMT) ;784394917 +Wed, 2 Nov 1994 17:37:41 +0100 (MET) ;783794261 +05 Nov 94 14:22:19 PST ;784074139 +16 Nov 94 22:28:20 PST ;785053700 +Tue, 1 Nov 1994 19:51:15 -0800 ;783748275 +Wed, 2 Nov 94 12:21:23 GMT ;783778883 +Fri, 18 Nov 94 18:07:03 GMT ;785182023 +Wed, 16 Nov 1994 11:26:27 -0500 ;785003187 +Sun, 6 Nov 1994 13:48:49 -0500 ;784147729 +Tue, 8 Nov 1994 13:19:37 -0800 ;784329577 +Fri, 18 Nov 1994 11:01:12 -0800 ;785185272 +Mon, 21 Nov 1994 00:47:58 -0500 ;785396878 +Mon, 7 Nov 1994 14:22:48 -0800 (PST) ;784246968 +Wed, 16 Nov 1994 15:56:45 -0800 (PST);785030205 +Thu, 3 Nov 1994 13:17:47 +0000 ;783868667 +Wed, 9 Nov 1994 17:32:50 -0500 (EST) ;784420370 +Wed, 9 Nov 94 16:31:52 PST ;784427512 +Wed, 09 Nov 94 10:41:10 -0800 ;784406470 +Wed, 9 Nov 94 08:42:22 MST ;784395742 +Mon, 14 Nov 1994 08:32:13 -0800 ;784830733 +Mon, 14 Nov 1994 11:34:32 -0500 (EST);784830872 +Mon, 14 Nov 94 16:48:09 GMT ;784831689 +Tue, 15 Nov 1994 10:27:33 +0000 ;784895253 +Wed, 02 Nov 94 13:56:54 MST ;783809814 +Thu, 03 Nov 94 15:24:45 MST ;783901485 +Thu, 3 Nov 1994 15:13:53 -0700 (MST) ;783900833 +Fri, 04 Nov 94 08:15:13 MST ;783962113 +Thu, 3 Nov 94 18:15:47 EST ;783904547 +Tue, 08 Nov 94 07:02:33 MST ;784303353 +Thu, 3 Nov 94 18:15:47 EST ;783904547 +Tue, 15 Nov 94 07:26:05 MST ;784909565 +Wed, 2 Nov 1994 00:00:55 -0600 (CST) ;783756055 +Sun, 6 Nov 1994 01:19:13 -0600 (CST) ;784106353 +Mon, 7 Nov 1994 23:16:57 -0600 (CST) ;784271817 +Tue, 08 Nov 1994 13:21:21 -0600 ;784322481 +Mon, 07 Nov 94 13:47:37 PST ;784244857 +Tue, 08 Nov 94 11:23:19 PST ;784322599 +Tue, 01 Nov 1994 11:28:25 -0800 ;783718105 +Tue, 15 Nov 1994 13:11:47 -0800 ;784933907 +Tue, 15 Nov 1994 13:18:38 -0800 ;784934318 +Tue, 15 Nov 1994 0:18:38 -0800 ;784887518 +Jul 13 1999 1:23P GMT ;931872180 +Jul 13 1999 1:23P.M GMT ;931872180 +Jul 13 1999 1:23P.M. GMT ;931872180 +Jul-13-1999 1:23P.M GMT ;931872180 +Jul/13/1999 1:23P.M. GMT ;931872180 +2001-02-26T13:44:12-0700 ;983220252 +2001-02-26T13:44-0700 ;983220240 +2001-02-26T13-0700 ;983217600 +2001-02-26T13-44-12-0700 ;983220252 +2001-02-26T13-44-0700 ;983220240 +2001-02-26T13-0700 ;983217600 +07/Nov/2000:16:45:56 +0100 ;973611956 +2002-11-07T23:31:49-05:00 ;1036729909 +2003-02-17T07:45:56Z ;1045467956 +2003-02-17T08:14:07.198189+0000 ;1045469647.198189 +20020722T100000Z ;1027332000 +Jul 22 10:00:00 UTC 2002 ;1027332000 +2002-07-22 10:00:00Z ;1027332000 +2002-07-22 10:00:00 Z ;1027332000 +2002-07-22 10:00 Z ;1027332000 +2002-07-22 10:00Z ;1027332000 +2002-07-22 10:00 +100 ;1027328400 +2002-07-22 10:00 +0100 ;1027328400 +!; + +require Time::Local; +my $offset = Time::Local::timegm(0,0,0,1,0,70); + +@data = split(/\n/, $data); + +print "1..", scalar(@data),"\n"; +$loop = 1; + +printf "# offset = %d\n", $offset; + +foreach (@data){ + my($str,$time_expect) = split ';', $_; + my $time = Date::Parse::str2time($str); + + if($loop < 6) { + + # The first five tests are parsed in the current time zone + # But the check number is in GMT + + my @lt = localtime($time_expect); + my @gt = gmtime($time_expect); + + $tzsec = ($gt[1] - $lt[1]) * 60 + ($gt[2] - $lt[2]) * 3600; + + my($lday,$gday) = ($lt[7],$gt[7]); + if($lt[5] > $gt[5]) { + $tzsec -= 24 * 3600; + } + elsif($gt[5] > $lt[5]) { + $tzsec += 24 * 3600; + } + else { + $tzsec += ($gt[7] - $lt[7]) * (24 * 3600); + } + $time -= $tzsec; + } + + $time_expect += $offset; + + if(defined($time) and $time==$time_expect) { + print "ok $loop\n"; + } + else { + require Date::Format; + print "-"x50,"\nFAIL $loop\n"; + printf "%s\nDiff: %d\n", $str, $time - $time_expect; + printf "Expect: %10f %s",$time_expect,Date::Format::ctime($time_expect); + printf "Got: %10f %s",$time, Date::Format::ctime($time); + } + $loop++; +} + diff --git a/t/lang.t b/t/lang.t new file mode 100644 index 0000000..02c96f4 --- /dev/null +++ b/t/lang.t @@ -0,0 +1,24 @@ +#!/usr/local/bin/perl -w + +use Date::Language; + + +my $time = time; +my $v; + +my @lang = qw(English German Italian); + +print "1..", scalar(@lang),"\n"; + +my $loop = 1; +my $lang; + +foreach $lang (@lang) +{ + my $l = Date::Language->new($lang); + $v = $l->str2time($l->ctime($time)); + + print $v == $time ? "ok $loop\n" : "FAIL $loop\n"; + $loop++; +} + |