File: 05datetime.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 (71 lines) | stat: -rw-r--r-- 1,698 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -w

use strict;

use Test::More tests => 9;
use DateTime;
use DateTime::Incomplete;

my $UNDEF_CHAR = 'x';
my $UNDEF4 = $UNDEF_CHAR x 4;
my $UNDEF2 = $UNDEF_CHAR x 2;

{
    my $dti;
    my $dt = DateTime->new( year => 2003 );
    my $error;

    $dti = DateTime::Incomplete->new( 
        year =>   $dt->year,
        month =>  $dt->month,
        day =>    $dt->day,
        hour =>   $dt->hour,
        minute => $dt->minute,
        second => $dt->second,
        nanosecond => $dt->nanosecond,
    );

    is( $dti->day_name , $dt->day_name, 
        'DTI->day_name matches DT->day_name' );

    $dti->set( year => undef );
    ok( ! defined $dti->day_name ,
        'day_name checks for valid parameter' );

    is( $dti->offset , $dt->offset,
        'DTI->offset matches DT->offset' );

    $dt->set_time_zone( 'America/Chicago' );
    $dti->set_time_zone( 'America/Chicago' );
    is( $dti->offset , $dt->offset,
        'DTI->offset matches DT->offset' );

    $dti->set( year => undef );
    ok( ! defined $dti->is_leap_year ,
        'is_leap_year checks for valid parameter' );
}

{
    my $dti;

    $dti = DateTime::Incomplete->now;
    ok( defined $dti ,
        "now() doesn't die: ".$dti->datetime );

    $dti = DateTime::Incomplete->today;
    my $str_today = $dti->datetime;
    ok( defined $dti ,
        "today() doesn't die: ".$str_today );

    $str_today =~ s/$UNDEF2:$UNDEF2$/00:00/;
    $dti->truncate( to => 'hour' );
    is( $dti->datetime , $str_today ,
        "truncate() defines min:sec ".$str_today );

    $dti = DateTime::Incomplete->from_epoch( epoch => 0 );
    ok( defined $dti ,
        "from_epoch() doesn't die: ".$dti->datetime );
}

1;