| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright 2009, 2010, 2011 Kevin Ryde |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Test-MockTime-DateCalc. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# Test-MockTime-DateCalc is free software; you can redistribute it and/or |
|
6
|
|
|
|
|
|
|
# modify it under the terms of the GNU General Public License as published |
|
7
|
|
|
|
|
|
|
# by the Free Software Foundation; either version 3, or (at your option) any |
|
8
|
|
|
|
|
|
|
# later version. |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# Test-MockTime-DateCalc is distributed in the hope that it will be useful, |
|
11
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
13
|
|
|
|
|
|
|
# Public License for more details. |
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
|
16
|
|
|
|
|
|
|
# with Test-MockTime-DateCalc. If not, see . |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Test::MockTime::DateCalc; |
|
20
|
4
|
|
|
4
|
|
37148
|
use strict; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
146
|
|
|
21
|
4
|
|
|
4
|
|
21
|
use vars qw($VERSION); |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
295
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$VERSION = 6; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
BEGIN { |
|
26
|
|
|
|
|
|
|
# Check that Date::Calc isn't already loaded. |
|
27
|
|
|
|
|
|
|
# |
|
28
|
|
|
|
|
|
|
# Week_of_Year() here is a representative func, present in Date::Calc 4.0 |
|
29
|
|
|
|
|
|
|
# and up, and not one that's mangled here (so as not to risk hitting that |
|
30
|
|
|
|
|
|
|
# if something goes badly wrong). Maybe looking at %INC would be better. |
|
31
|
|
|
|
|
|
|
# |
|
32
|
4
|
100
|
|
4
|
|
110
|
if (Date::Calc->can('Week_of_Year')) { |
|
33
|
1
|
|
|
|
|
36
|
die "Date::Calc already loaded, cannot fake after imports may have grabbed its functions"; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Date::Calc had a big rewrite in 4.0 of May 1998, no attempt to fake |
|
38
|
|
|
|
|
|
|
# anything earlier than that |
|
39
|
|
|
|
|
|
|
# |
|
40
|
3
|
|
|
3
|
|
3804
|
use Date::Calc 4.0; |
|
|
3
|
|
|
|
|
115973
|
|
|
|
3
|
|
|
|
|
139
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
package Date::Calc; |
|
43
|
3
|
|
|
3
|
|
33
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
292
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Calc.xs in Date::Calc calls to the C time() func from its internal C |
|
46
|
|
|
|
|
|
|
# function DateCalc_system_clock(), and also directly in its Gmtime(), |
|
47
|
|
|
|
|
|
|
# Localtime(), Timezone() and Time_to_Date(). In each case that of course |
|
48
|
|
|
|
|
|
|
# misses any fakery on the perl level time(). The replacements here go to |
|
49
|
|
|
|
|
|
|
# perl time() for the current time, and stay with Date::Calc for conversions |
|
50
|
|
|
|
|
|
|
# to d/m/y etc. |
|
51
|
|
|
|
|
|
|
# |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
{ |
|
54
|
|
|
|
|
|
|
local $^W = 0; # no warnings |
|
55
|
2
|
50
|
|
2
|
|
452
|
eval <<'HERE' or die; |
|
|
10
|
|
|
10
|
|
2009320
|
|
|
|
10
|
|
|
2
|
|
286
|
|
|
|
2
|
|
|
2
|
|
483
|
|
|
|
2
|
|
|
2
|
|
1007
|
|
|
|
2
|
|
|
|
|
441
|
|
|
56
|
|
|
|
|
|
|
sub System_Clock { |
|
57
|
|
|
|
|
|
|
my ($gmt) = @_; |
|
58
|
|
|
|
|
|
|
return ($gmt ? Gmtime() : Localtime()); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
sub Today { |
|
61
|
|
|
|
|
|
|
return (System_Clock(@_))[0,1,2]; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
sub Now { |
|
64
|
|
|
|
|
|
|
return (System_Clock(@_))[3,4,5]; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
sub Today_and_Now { |
|
67
|
|
|
|
|
|
|
return (System_Clock(@_))[0,1,2, 3,4,5]; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
sub This_Year { |
|
70
|
|
|
|
|
|
|
return (System_Clock(@_))[0]; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
1 |
|
73
|
|
|
|
|
|
|
HERE |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
{ |
|
77
|
|
|
|
|
|
|
local $^W = 0; # no warnings |
|
78
|
3
|
|
|
3
|
|
161
|
eval <<'HERE' or die; |
|
|
3
|
|
|
3
|
|
155
|
|
|
|
3
|
|
|
3
|
|
162
|
|
|
|
3
|
|
|
3
|
|
131
|
|
|
|
12
|
|
|
12
|
|
412
|
|
|
|
1
|
|
|
1
|
|
145
|
|
|
|
2
|
|
|
2
|
|
445
|
|
|
|
1
|
|
|
1
|
|
98
|
|
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# anonymous sub to avoid adding anything to the Date::Calc namespace |
|
81
|
|
|
|
|
|
|
my $default_to_time_func = sub { |
|
82
|
|
|
|
|
|
|
my ($func, $time) = @_; |
|
83
|
|
|
|
|
|
|
if (! defined $time) { $time = time(); } |
|
84
|
|
|
|
|
|
|
return &$func($time); |
|
85
|
|
|
|
|
|
|
}; |
|
86
|
|
|
|
|
|
|
{ my $orig; |
|
87
|
|
|
|
|
|
|
BEGIN { $orig = \&Gmtime; } |
|
88
|
|
|
|
|
|
|
sub Gmtime { return &$default_to_time_func ($orig, @_) } |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
{ my $orig; |
|
91
|
|
|
|
|
|
|
BEGIN { $orig = \&Localtime; } |
|
92
|
|
|
|
|
|
|
sub Localtime { return &$default_to_time_func ($orig, @_) } |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
{ my $orig; |
|
95
|
|
|
|
|
|
|
BEGIN { $orig = \&Timezone; } |
|
96
|
|
|
|
|
|
|
sub Timezone { return &$default_to_time_func ($orig, @_) } |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
{ my $orig; |
|
99
|
|
|
|
|
|
|
BEGIN { $orig = \&Time_to_Date; } |
|
100
|
|
|
|
|
|
|
sub Time_to_Date { return &$default_to_time_func ($orig, @_) } |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
1 |
|
103
|
|
|
|
|
|
|
HERE |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
|
107
|
|
|
|
|
|
|
__END__ |