File: 06next.t

package info (click to toggle)
libdatetime-incomplete-perl 0.08-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 188 kB
  • sloc: perl: 1,470; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download | duplicates (4)
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
# bug #67064

use strict;
use warnings;

use DateTime;
use DateTime::Incomplete;
use Test::More;

# 7am in America/Sao_Paulo (UTC-03)
# Note we need to specify up to nanosecond - otherwise previous() will return an hour like 07:59:59.999999
my $dti = DateTime::Incomplete->new(
    hour       => 7,
    minute     => 0,
    second     => 0,
    nanosecond => 0,
    time_zone  => 'America/Sao_Paulo'
);

# 2011-03-29T00:00:00 UTC
my $dt =
  DateTime->new( year => 2011, month => 03, day => 29, time_zone => 'UTC' );

{

    # when is it next 7am in Brazil?  ... should be 10am UTC.
    my $next   = $dti->next($dt);
    my $dt_str = $next->datetime . " " . $next->time_zone->name;
    print "# $dt_str\n";
    is( $dt_str, "2011-03-29T10:00:00 UTC", 'result timezone is UTC' );

    $dt_str = $dt->datetime . " " . $dt->time_zone->name;
    print "# $dt_str\n";
    is( $dt_str, "2011-03-29T00:00:00 UTC", '$dt is the same' );
}

{

    # when is it previous 7am in Brazil?  ... should be 10am UTC.
    my $previous = $dti->previous($dt);
    my $dt_str   = $previous->datetime . " " . $previous->time_zone->name;
    print "# $dt_str\n";
    is( $dt_str, "2011-03-28T10:00:00 UTC", 'result timezone is UTC' );

    $dt_str = $dt->datetime . " " . $dt->time_zone->name;
    print "# $dt_str\n";
    is( $dt_str, "2011-03-29T00:00:00 UTC", '$dt is the same' );
}

done_testing;