Skip to content

Commit

Permalink
added unformatDate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barbie committed Jan 4, 2015
1 parent 81bc6ac commit 042dd60
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Changes for the Labyrinth Core
==============================

- fixed date test script.
- fixed and extended date test script.
- switched to using DateTime (DTUtils).

5.29 2014-12-05
Expand Down
61 changes: 35 additions & 26 deletions t/27-labyrinth-dtutils.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;

use Test::More tests => 39;
use Test::More tests => 63;
use Labyrinth::DTUtils;
use Labyrinth::Variables;
use Data::Dumper;
Expand Down Expand Up @@ -55,43 +55,52 @@ is(PeriodSelect(5,1),$select{period3},'PeriodSelect with options and blank');

like(formatDate(),qr/\d+/);
like(formatDate(0),qr/\d+/);
like(unformatDate(),qr/\d+/);
like(unformatDate(0),qr/\d+/);

# 1442110800 translates to Sun 13 Sep 2015 03:20:00 BST / Sun, 13 Sep 2015 02:20:00 GMT
my $TIME0 = 1442110800;

$settings{timezone} = 'UTC';
$settings{timezone} = '+0000'; # UTC
$settings{timezone} = '+0100'; # BST

my %formats = (
1 => '2015',
2 => 'September 2015',
3 => '13/09/2015',
4 => 'Sun Sep 13 3:20:00 2015',
5 => 'Sunday, 13 September 2015',
6 => 'Sunday, 13th September 2015',
7 => 'Sunday, 13 September 2015 (3:20am)',
8 => 'Sunday, 13th September 2015 (3:20am)',
9 => '2015/09/13',
10 => '13th September 2015',
11 => '20150913T032000', # iCal date string
12 => '2015-09-13T03:20:00Z', # RSS date string
13 => '20150913', # backwards date
14 => 'Sun, 13th September 2015',
15 => '13 Sep 2015',
16 => 'Sun, 13 Sep 2015 03:20:00 UT', # RFC-822 date string
17 => 'Sunday, 13 September 2015 03:20:00',
18 => '13/09/2015 03:20:00',
19 => '13th September 2015',
20 => 'Sun, 13 Sep 2015 03:20:00',
21 => '2015-09-13 03:20:00',
22 => '201509130320',
1 => [ '2015', 1420066800 ],
2 => [ 'September 2015', 1441062000 ],
3 => [ '13/09/2015', 1442098800 ],
4 => [ 'Sun Sep 13 3:20:00 2015', $TIME0 ],
5 => [ 'Sunday, 13 September 2015', 1442098800 ],
6 => [ 'Sunday, 13th September 2015', 1442098800 ],
7 => [ 'Sunday, 13 September 2015 (3:20am)', $TIME0 ],
8 => [ 'Sunday, 13th September 2015 (3:20am)', $TIME0 ],
9 => [ '2015/09/13', 1442098800 ],
10 => [ '13th September 2015', 1442098800 ],
11 => [ '20150913T032000', $TIME0 ],
12 => [ '2015-09-13T03:20:00Z', $TIME0 ],
13 => [ '20150913', 1442098800 ],
14 => [ 'Sun, 13th September 2015', 1442098800 ],
15 => [ '13 Sep 2015', 1442098800 ],
16 => [ 'Sun, 13 Sep 2015 03:20:00 +0100', $TIME0 ],
17 => [ 'Sunday, 13 September 2015 03:20:00', $TIME0 ],
18 => [ '13/09/2015 03:20:00', $TIME0 ],
19 => [ '13th September 2015', 1442098800 ],
20 => [ 'Sun, 13 Sep 2015 03:20:00', $TIME0 ],
21 => [ '2015-09-13 03:20:00', $TIME0 ],
22 => [ '201509130320', $TIME0 ],
);

for my $format (keys %formats) {
is(formatDate($format,$TIME0),$formats{$format},".. format $format => $formats{$format}");
is(formatDate($format,$TIME0),$formats{$format}[0],".. format $format => $formats{$format}[0]");
}

$settings{timezone} = '+0100'; # BST

for my $format (keys %formats) {
#diag("format=$format");
is(unformatDate($format,$formats{$format}[0]),$formats{$format}[1],".. unformat $format => $formats{$format}[0]");
}

# TODO:
# * OptSelect
# * unformatDate
# * isMonth
# * _ext

0 comments on commit 042dd60

Please sign in to comment.