Dates.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 74 CC 7 SCAR 27.1
CC
7
Cov
0%
getTimestampFromISO8601
42.0
getTimestamp
6.0
getLocalNanoTime
2.0
CRAP 15.1
1 use strict;
2 use warnings;
3  
4 package SVN::Friendly::Dates;
5 my $CLASS = __PACKAGE__;
6  
7 #--------------------------------------------------------------------
8  
9 use Exporter;
10 our @ISA = qw(Exporter);
11 our @EXPORT_OK=qw(getTimestampFromISO8601
12 getTimestamp
13 getLocalNanoTime
14 getLocalPerlTime
15 getLocalUsecTime
16 getUtcNanoTime
17 getUtcPerlTime
18 );
19  
20 #--------------------------------------------------------------------
21  
22 use SVN::Core;
23 use Time::Local qw(timelocal_nocheck);
24  
25 use constant {
26 DAY => 1
27 , MINUTE => 2
28 , SECOND => 3
29 , USEC => 4
30 };
31  
32 #==================================================================
33 # FUNCTIONS
34 #==================================================================
35  
36 #--------------------------------------------------------------------
37  
38 sub getTimestampFromISO8601($;$) {
39 my ($sISO, $iPrecision) = @_;
40 if (defined($iPrecision)) {
41 if ($iPrecision == DAY) {
42 $sISO =~ s/^([^T]+)T.*$/$1/;
43 } elsif ($iPrecision == MINUTE) {
44 $sISO =~ s/^([^T]+)T(\d\d:\d\d).*$/$1 $2 UTC/;
45 } elsif ($iPrecision == SECOND) {
46 $sISO =~ s/^([^T]+)T([^.]+)\.\d{6}.*$/$1 $2 UTC/;
47 } elsif ($iPrecision == USEC) {
48 $sISO =~ s/^([^T]+)T([^.]+\.\d{6}).*$/$1 $2 UTC/;
49 }
50 }
51 return $sISO;
52 }
53 #--------------------------------------------------------------------
54  
55 sub getTimestamp($;$) {
56 my ($iAprTime, $iPrecision) = @_;
57 $iPrecision = USEC unless defined($iPrecision);
58  
59 return getTimestampFromISO8601
60 (SVN::Core::time_to_cstring($iAprTime), $iPrecision);
61 }
62  
63 #--------------------------------------------------------------------
64  
65 sub getLocalNanoTime($) {
66 my $iAprTime = $_[0];
67 return getLocalUsecTime($iAprTime)*1000;
68 }
69  
70 #--------------------------------------------------------------------
71  
72 sub getLocalPerlTime($) {
73 my $iAprTime = $_[0];
74 return int(getLocalUsecTime($iAprTime)/1000000);
75 }
76  
77 #--------------------------------------------------------------------
78  
79 sub getLocalUsecTime($) {
80 my $iAprTime = $_[0];
81 return ($iAprTime + 1000000* timelocal_nocheck(0,0,0,1,0,1970));
82 }
83  
84 #--------------------------------------------------------------------
85  
86 sub getUtcNanoTime($) {
87 my $iAprTime = $_[0];
88 return return $iAprTime*1000;
89 }
90  
91 #--------------------------------------------------------------------
92  
93 sub getUtcPerlTime($) {
94 my $iAprTime = $_[0];
95 return int($iAprTime/1000000);
96 }
97  
98 #==================================================================
99 # PRIVATE
100 #==================================================================
101  
102  
103 #==================================================================
104 # MODULE INITIALIZATION
105 #==================================================================
106  
107 1;