GeniusTrader/DateTime/Month.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran n/a Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 38 CC 1 SCAR 6.9
CC
1
Cov
0%
map_date_to_time
2.0
map_time_to_date
2.0
timeframe_ratio
2.0
CRAP 2.0
1 package Finance::GeniusTrader::DateTime::Month;
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 use strict;
8 use vars qw();
9  
10 use Finance::GeniusTrader::DateTime;
11 #ALL# use Log::Log4perl qw(:easy);
12 use Time::Local;
13  
14 =head1 Finance::GeniusTrader::DateTime::Month
15  
16 This module treat dates describing a month. They have the following format :
17 YYYY-MM
18  
19 =cut
20 sub map_date_to_time {
21 my ($date) = @_;
22 my ($y, $m) = split /\//, $date;
23 return timelocal(0, 0, 0, 1, $m - 1, $y - 1900);
24 }
25  
26 sub map_time_to_date {
27 my ($time) = @_;
28 my ($sec, $min, $hour, $d, $m, $y, $wd, $yd) = localtime($time);
29 return sprintf("%04d/%02d", $y + 1900, $m + 1);
30 }
31  
32 sub timeframe_ratio {
33 my ($tf) = @_;
34  
35 #WAR# WARN "timeframe must be smaller than a month" unless ($tf < $MONTH);
36  
37 $tf == $DAY && return 30 * 5 / 7;
38 $tf == $WEEK && return 30 / 7;
39 return Finance::GeniusTrader::DateTime::timeframe_ratio($DAY, $tf) * 30 * 5 / 7;
40 }
41  
42 1;