File: datetime.t

package info (click to toggle)
libanyevent-xmpp-perl 0.55-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 784 kB
  • ctags: 553
  • sloc: perl: 8,004; makefile: 13
file content (44 lines) | stat: -rw-r--r-- 1,818 bytes parent folder | download | duplicates (6)
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
#!perl
use strict;
use Test::More tests => 22;
use AnyEvent::XMPP::Util qw/from_xmpp_datetime to_xmpp_datetime to_xmpp_time
                           xmpp_datetime_as_timestamp/;

# to conversion
is (to_xmpp_time (1, 2, 3)          , '03:02:01'      , "basic to_xmpp_time");
is (to_xmpp_time (1, 2, 3, "Z")     , '03:02:01Z'     , "utc to_xmpp_time");
is (to_xmpp_time (1, 2, 3, "+01:10"), '03:02:01+01:10', "+01:10 to_xmpp_time");
is (to_xmpp_time (1, 2, 3, "+01:10", 0.123),
    '03:02:01.123+01:10'                              , "+01:10 with frac to_xmpp_time");

is (to_xmpp_datetime (23, 3, 4, 13, 5, 108, 'Z', 0.32),
    '2008-06-13T04:03:23.320Z',                         "to_xmpp_datetime");

# old format
my ($sec, $min, $hour, $mday, $mon, $year, $tz, $secfrac)
   = from_xmpp_datetime ("20070730T17:06:25");

is (1*$sec ,   25, "old format seconds");
is (1*$min ,    6, "old format minutes");
is (1*$hour,   17, "old format hours");
is (1*$mday,   30, "old format month day");
is (1*$mon ,    6, "old format month");
is (1*$year,  107, "old format year");
ok ((not defined $tz)     , "no tz defined");
ok ((not defined $secfrac), "no secfrac defined");

my $ts = xmpp_datetime_as_timestamp ("20070730T18:51:40-02:10");
is ($ts, '1185813700', "timestamp is UTC located");

# new format
($sec, $min, $hour, $mday, $mon, $year, $tz, $secfrac)
   = from_xmpp_datetime ("03:02:01.123+01:10");

is (1*$sec ,    1,       "new format seconds");
is (1*$min ,    2,       "new format minutes");
is (1*$hour,    3,       "new format hours");
is (1*$secfrac, '0.123', "new format secfrac");
ok ((not defined $mday),     "new format no mday defined");
ok ((not defined $mon) ,     "new format no mon defined");
ok ((not defined $year),     "new format no year defined");
is ($tz,        '+01:10',    "new format tz");