line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::GeniusTrader::DateTime::Day; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Copyright 2000-2002 Raphaël Hertzog, Fabien Fulhaber |
4
|
|
|
|
|
|
|
# This file is distributed under the terms of the General Public License |
5
|
|
|
|
|
|
|
# version 2 or (at your option) any later version. |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
8
|
1
|
|
|
1
|
|
11
|
use vars qw(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use Finance::GeniusTrader::DateTime; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
173
|
|
11
|
|
|
|
|
|
|
#ALL# use Log::Log4perl qw(:easy); |
12
|
1
|
|
|
1
|
|
5
|
use Time::Local; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
305
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 Finance::GeniusTrader::DateTime::Day |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module treat dates describing a day. They have the following format : |
17
|
|
|
|
|
|
|
YYYY-MM-DD |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
sub map_date_to_time { |
21
|
0
|
|
|
0
|
0
|
|
my ($date) = @_; |
22
|
0
|
|
|
|
|
|
my ($y, $m, $d) = split /-/, $date; |
23
|
0
|
|
|
|
|
|
($d) = split / /, $d; |
24
|
0
|
|
|
|
|
|
return timelocal(0, 0, 0, $d, $m - 1, $y - 1900); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub map_time_to_date { |
28
|
0
|
|
|
0
|
0
|
|
my ($time) = @_; |
29
|
0
|
|
|
|
|
|
my ($sec, $min, $hour, $d, $m, $y, $wd, $yd) = localtime($time); |
30
|
0
|
|
|
|
|
|
return sprintf("%04d-%02d-%02d", $y + 1900, $m + 1, $d); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub timeframe_ratio { |
34
|
0
|
|
|
0
|
0
|
|
my ($tf) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#WAR# WARN "timeframe must be smaller than a day" unless ($tf < $DAY); |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
$tf == $PERIOD_1MIN && return 8 * 60; # 8 hours approximatively |
39
|
0
|
0
|
|
|
|
|
$tf == $PERIOD_5MIN && return 8 * 12; |
40
|
0
|
0
|
|
|
|
|
$tf == $PERIOD_10MIN && return 8 * 6; |
41
|
0
|
0
|
|
|
|
|
$tf == $PERIOD_30MIN && return 8 * 2; |
42
|
0
|
0
|
|
|
|
|
$tf == $HOUR && return 8; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |