summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/format.t46
-rw-r--r--t/precision.t18
-rw-r--r--t/precision2.t22
3 files changed, 83 insertions, 3 deletions
diff --git a/t/format.t b/t/format.t
index b94c327..c1ad071 100644
--- a/t/format.t
+++ b/t/format.t
@@ -1,8 +1,48 @@
#!perl
-use Test::More;
+use Test::More tests=>17;
use DateTime;
use DateTime::Format::GeekTime;
+{
my $dt=DateTime->new(year=>2010,month=>3,day=>8,
- hour=>16,minute=>56,seconds=>23);
-diag DateTime::Format::GeekTime->format_datetime($dt);
+ hour=>17,minute=>56,second=>23,
+ time_zone=>'Europe/Rome',
+ );
+is(DateTime::Format::GeekTime->format_datetime($dt),
+ "0xB4B1 on day 0x042 \x{b4b1}");
+}
+
+{
+my $dt=DateTime::Format::GeekTime->parse_datetime("0xB4B1 0x0042 \x{b4b0}");
+is($dt->month,3);
+is($dt->day,8);
+is($dt->hour,16);
+is($dt->minute,56);
+is($dt->second,23);
+is($dt->time_zone->name,'UTC');
+
+my $other=DateTime::Format::GeekTime->parse_datetime("0xB4B1 0x0042");
+cmp_ok($dt,'==',$other);
+$other=DateTime::Format::GeekTime->parse_datetime("0xB4B1 on day 0x0042");
+cmp_ok($dt,'==',$other);
+$other=DateTime::Format::GeekTime->parse_datetime("B4B1 0042");
+cmp_ok($dt,'==',$other);
+$other=DateTime::Format::GeekTime->parse_datetime("B4B10042");
+cmp_ok($dt,'==',$other);
+$other=DateTime::Format::GeekTime->parse_datetime("b4b10042");
+cmp_ok($dt,'==',$other);
+$other=DateTime::Format::GeekTime->parse_datetime("0xB4B1 0x042");
+cmp_ok($dt,'==',$other);
+$other=DateTime::Format::GeekTime->parse_datetime("B4B1 042");
+cmp_ok($dt,'==',$other);
+$other=DateTime::Format::GeekTime->parse_datetime("B4B1042");
+cmp_ok($dt,'==',$other);
+$other=DateTime::Format::GeekTime->parse_datetime("b4b1042");
+cmp_ok($dt,'==',$other);
+}
+
+{ # bad codepoint
+my $dt=DateTime::Format::GeekTime->parse_datetime('0xdc01 0x000');
+is(DateTime::Format::GeekTime->format_datetime($dt),
+ '0xDC01 on day 0x000');
+}
diff --git a/t/precision.t b/t/precision.t
new file mode 100644
index 0000000..751e1d6
--- /dev/null
+++ b/t/precision.t
@@ -0,0 +1,18 @@
+#!perl
+use Test::More;
+use DateTime;
+use DateTime::Format::GeekTime;
+
+if ($ENV{SLOW_TESTS}) {
+ plan tests=>65536;
+}
+else {
+ plan skip_all => 'Slow test, set $ENV{SLOW_TESTS} to run it';
+}
+
+for my $i (0..65535) {
+ my $gkt=sprintf '0x%04X on day 0x000',$i;
+ my $dt=DateTime::Format::GeekTime->parse_datetime($gkt);
+ my $round_trip=DateTime::Format::GeekTime->format_datetime($dt);
+ is(substr($round_trip,0,19),$gkt);
+}
diff --git a/t/precision2.t b/t/precision2.t
new file mode 100644
index 0000000..ef38f2a
--- /dev/null
+++ b/t/precision2.t
@@ -0,0 +1,22 @@
+#!perl
+use Test::More;
+use DateTime;
+use DateTime::Format::GeekTime;
+
+if ($ENV{SLOW_TESTS}) {
+ plan tests=>86400;
+}
+else {
+ plan skip_all => 'Slow test, set $ENV{SLOW_TESTS} to run it';
+}
+
+my $dt=DateTime->new(day=>1,month=>1,year=>2010,
+ hour=>0,minute=>0,second=>0,
+ time_zone=>'UTC');
+for my $i (0..86399) {
+ my $gkt=DateTime::Format::GeekTime->format_datetime($dt);
+ my $round_trip=DateTime::Format::GeekTime->parse_datetime($gkt);
+ my $diff=$round_trip->subtract_datetime_absolute($dt)->in_units('seconds');
+ cmp_ok($diff,'<=',1);
+ $dt->add(seconds=>1);
+}