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