File: 410_with_offset.t

package info (click to toggle)
libtime-moment-perl 0.41-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,024 kB
  • ctags: 1,354
  • sloc: perl: 6,312; ansic: 2,936; makefile: 3
file content (51 lines) | stat: -rwxr-xr-x 1,787 bytes parent folder | download | duplicates (3)
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
#!perl
use strict;
use warnings;

use Test::More;

BEGIN {
    use_ok('Time::Moment');
}

{
    my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z");
    for my $offset (-1080, -600, -120, -60, -30, -1, 0, 1, 30, 60, 120, 600, 1080) {
        my $got = $tm->with_offset_same_instant($offset);
        
        my $prefix = "$tm->with_offset_same_instant($offset)";
        is($got->epoch,       $tm->epoch, "$prefix->epoch");
        is($got->millisecond,        123, "$prefix->millisecond");
        is($got->microsecond,     123456, "$prefix->microsecond");
        is($got->nanosecond,   123456789, "$prefix->nanosecond");
        
        is($got->utc_rd_as_seconds,
           $tm->utc_rd_as_seconds,
           "$prefix->utc_rd_as_seconds");
    }
}

{
    my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z");
    for my $offset (-1080, -600, -120, -60, -30, -1, 0, 1, 30, 60, 120, 600, 1080) {
        my $got = $tm->with_offset_same_local($offset);
        
        my $prefix = "$tm->with_offset_same_local($offset)";
        is($got->year,              2012, "$prefix->year");
        is($got->month,               12, "$prefix->month");
        is($got->day_of_month,        24, "$prefix->day_of_month");
        is($got->hour,                12, "$prefix->hour");
        is($got->minute,              30, "$prefix->minute");
        is($got->second,              45, "$prefix->second");
        is($got->millisecond,        123, "$prefix->millisecond");
        is($got->microsecond,     123456, "$prefix->microsecond");
        is($got->nanosecond,   123456789, "$prefix->nanosecond");
        
        is($got->local_rd_as_seconds,
           $tm->local_rd_as_seconds,
           "$prefix->local_rd_as_seconds");
    }
}

done_testing();