File: parse.t

package info (click to toggle)
libtime-clock-perl 1.03-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 108 kB
  • sloc: perl: 680; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 2,376 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl -w

use strict;

use Test::More tests => 33;

use Time::Clock;

eval { require Time::HiRes };
our $Have_HiRes_Time = $@ ? 0 : 1;

my $t = Time::Clock->new;

ok($t->parse('12:34:56.123456789'), 'parse 12:34:56.123456789');
is($t->as_string, '12:34:56.123456789', 'check 12:34:56.123456789');

ok($t->parse('12:34:56.123456789 pm'), 'parse 12:34:56.123456789 pm');
is($t->as_string, '12:34:56.123456789', 'check 12:34:56.123456789 pm');

ok($t->parse('12:34:56. A.m.'), 'parse 12:34:56. A.m.');
is($t->as_string, '00:34:56', 'check 12:34:56 am');

ok($t->parse('12:34:56 pm'), 'parse 12:34:56 pm');
is($t->as_string, '12:34:56', 'check 12:34:56 pm');

ok($t->parse('2:34:56 pm'), 'parse 2:34:56 pm');
is($t->as_string, '14:34:56', 'check 14:34:56 pm');

ok($t->parse('2:34 pm'), 'parse 2:34 pm');
is($t->as_string, '14:34:00', 'check 2:34 pm');

ok($t->parse('2 pm'), 'parse 2 pm');
is($t->as_string, '14:00:00', 'check 2 pm');

ok($t->parse('3pm'), 'parse 3pm');
is($t->as_string, '15:00:00', 'check 3pm');

ok($t->parse('4 p.M.'), 'parse 4 p.M.');
is($t->as_string, '16:00:00', 'check 4 p.M.');

ok($t->parse('24:00:00'), 'parse 24:00:00');
is($t->as_string, '24:00:00', 'check 24:00:00');

ok($t->parse('24:00:00 PM'), 'parse 24:00:00 PM');
is($t->as_string, '24:00:00', 'check 24:00:00 PM');

ok($t->parse('24:00'), 'parse 24:00');
is($t->as_string, '24:00:00', 'check 24:00');

eval { $t->parse('24:00:00.000000001') };
ok($@ =~ /only allowed if/,  'parse fail 24:00:00.000000001');

eval { $t->parse('24:00:01') };
ok($@ =~ /only allowed if/,  'parse fail 24:00:01');

eval { $t->parse('24:01') };
ok($@ =~ /only allowed if/,  'parse fail 24:01');

ok(eval { $t->parse('7:41:50.1272602510') }, 'extended fractional seconds');

if($Have_HiRes_Time)
{
  ok($t->parse('now'), 'parse now hires');
  ok($t->as_string =~ /^\d\d:\d\d:\d\d\.\d+$/, 'now hires');

  local $Time::Clock::Have_HiRes_Time = 0;
  ok($t->parse('now'), 'parse now lowres');
  ok($t->as_string =~ /^\d\d:\d\d:\d\d$/, 'check now lowres');
}
else
{
  ok($t->parse('now'), 'parse now hires (skipped) 1');
  ok($t->as_string =~ /^\d\d:\d\d:\d\d$/, 'now hires (skipped) 2');
  SKIP: { skip('parse now lowres', 2) }
}

$t = Time::Clock->new->parse('12:34:56.123456789');

is($t->format('%H %k %I %i %M %S %N %n %p %P %T'), '12 12 12 12 34 56 123456789 .123456789 PM pm 12:34:56', 'new->parse');