File: date_offset.t

package info (click to toggle)
libtemplate-perl 3.102-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,680 kB
  • sloc: perl: 14,945; makefile: 11; sh: 5
file content (107 lines) | stat: -rw-r--r-- 2,222 bytes parent folder | download
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#============================================================= -*-perl-*-
#
# t/date_offset.t
#
# Tests the 'Date' plugin.
#
# Written by Andy Wardley <abw@wardley.org>
#
# Copyright (C) 2000 Andy Wardley. All Rights Reserved.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id$
#
#========================================================================

use strict;
use lib qw( ./lib ../lib );
use Template;
use Template::Test;
use Template::Plugin::Date;
use POSIX;
use Config;
$^W = 1;

eval "use Date::Calc";

my $got_date_calc = 0;
$got_date_calc++ unless $@;

local $ENV{TZ} = 'GMT';
#local $ENV{TZ} = 'Europe/London';

skip_all('TZ GMT not showing as +0000') unless check_tz();

sub check_tz {
  # '2001/09/30T12:59:00' used in DATA
  my $date = [
    '00',
    '59',
    '12',
    '30',
    8,
    101
  ];

  my $time = POSIX::mktime(@$date);
  push @$date, (localtime($time))[6..8];
  my $tz = POSIX::strftime("%z", @$date);

  return $tz eq '+0000';
}

$Template::Test::DEBUG = 0;

my $format = {
    'default' => $Template::Plugin::Date::FORMAT,
    'time'    => '%H:%M:%S',
    'date'    => '%d-%b-%Y',
    'timeday' => 'the time is %H:%M:%S on %A',
};

my $time = time;
my @ltime = localtime($time);

my $params = {
    time    => $time,
    format  => $format,
    now     => sub {
        &POSIX::strftime(shift || $format->{ default }, localtime(time));
    },
    date_calc   => $got_date_calc,
};

# force second to rollover so that we reliably see any tests failing.
# lesson learnt from 2.07b where I broke the Date plugin's handling of a
# 'time' parameter, but which didn't immediately come to light because the
# script could run before the second rolled over and not expose the bug

sleep 1;

test_expect(\*DATA, { POST_CHOMP => 1 }, $params);



__DATA__
-- test --
[% USE date( use_offset = 1 );
   date.format( '2001/09/30T12:59:00', '%H:%M %z' )
-%]
-- expect --
12:59 +0000

-- test --
[% USE date( use_offset = 1 );
   date.format( '2001/09/30T12:59:00', '%H:%M' )
-%]
-- expect --
12:59

-- test --
[% USE date;
   date.format( time = '2001/09/30T12:59:00', format = '%H:%M %z', use_offset = 1 )
-%]
-- expect --
12:59 +0000