line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
### Change History |
2
|
|
|
|
|
|
|
# 2001-05-03 Added 'mm/dd/yy' -Ed |
3
|
|
|
|
|
|
|
# 2001-03-06 Added even more readable formats. -Piglet |
4
|
|
|
|
|
|
|
# 2000-12-16 Added more readable formats. -Simon |
5
|
|
|
|
|
|
|
# 2000-12-01 Added 1900 to year in readable. -Piglet |
6
|
|
|
|
|
|
|
# 1999-02-21 Created. -Simon |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Data::Quantity::Time::Timestamp; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require 5; |
11
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
12
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
728
|
|
13
|
1
|
|
|
1
|
|
40
|
use Time::ParseDate; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
74
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
6
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
75
|
|
16
|
|
|
|
|
|
|
$VERSION = 0.001; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
7
|
use Data::Quantity::Number::Integer '-isasubclass'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# undef = Data::Quantity::Time::Time->scale(); |
21
|
|
|
|
|
|
|
sub scale { |
22
|
0
|
|
|
0
|
0
|
0
|
return 'Second'; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# $date = Data::Quantity::Time::Time->current(); |
26
|
|
|
|
|
|
|
sub current { |
27
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
28
|
0
|
|
|
|
|
0
|
my $date = $class->new_instance; |
29
|
0
|
|
|
|
|
0
|
$date->set_udt( time() ); |
30
|
0
|
|
|
|
|
0
|
return $date; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub type { |
34
|
0
|
|
|
0
|
0
|
0
|
return 'temporal', 'absolute'; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# $seconds_since_1970 = $moment_q->get_udt; |
38
|
|
|
|
|
|
|
sub get_udt { |
39
|
0
|
|
|
0
|
0
|
0
|
my $moment_q = shift; |
40
|
0
|
0
|
|
|
|
0
|
my $udt = $moment_q->value or return; |
41
|
0
|
|
|
|
|
0
|
return $udt; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# $moment_q->set_udt( $seconds_since_1970 ); |
45
|
|
|
|
|
|
|
sub set_udt { |
46
|
0
|
|
|
0
|
0
|
0
|
my $moment_q = shift; |
47
|
0
|
|
|
|
|
0
|
my $udt = shift; |
48
|
0
|
|
|
|
|
0
|
$moment_q->value( $udt ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
5
|
use vars qw( $default_readable_format ); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
1007
|
|
52
|
|
|
|
|
|
|
$default_readable_format ||= 'year/mon/mday hh:mm:ss'; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub readable { |
55
|
0
|
|
|
0
|
0
|
0
|
my $moment_q = shift; |
56
|
0
|
0
|
|
|
|
0
|
my $udt = $moment_q->value or return; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( $udt ); |
59
|
0
|
|
|
|
|
0
|
$mon += 1; |
60
|
0
|
|
|
|
|
0
|
$year += 1900; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
my $style = shift; |
63
|
0
|
|
0
|
|
|
0
|
$style ||= $default_readable_format; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# zero-padding |
66
|
0
|
|
|
|
|
0
|
my ( $ss, $mm, $hh ) = ( $sec, $min, $hour ); |
67
|
0
|
|
|
|
|
0
|
my ( $monmon, $dayday ) = ( $mon, $mday ); |
68
|
0
|
|
|
|
|
0
|
foreach ( $ss, $mm, $hh, $monmon, $dayday ) { |
69
|
0
|
|
|
|
|
0
|
$_ = ( '0' x ( 2 - length($_) ) ) . $_; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
0
|
my($yy) = ( $year =~ /(\d\d)$/ ); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
0
|
my $ampm = ( $hour > 11 ) ? 'pm' : 'am'; |
74
|
0
|
|
|
|
|
0
|
my $AMPM = uc($ampm); |
75
|
0
|
|
0
|
|
|
0
|
my $h = ( $hour % 12 ) || 12; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
0
|
if ( $style eq 'year/mon/mday hh:mm:ss' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
return "$year/$mon/$mday $hh:$mm:$ss"; |
79
|
|
|
|
|
|
|
} elsif ( $style eq 'year/mon/mday hh:mm' ) { |
80
|
0
|
|
|
|
|
0
|
return "$year/$mon/$mday $hh:$mm"; |
81
|
|
|
|
|
|
|
} elsif ( $style eq 'year/mon/mday' ) { |
82
|
0
|
|
|
|
|
0
|
return "$year/$mon/$mday"; |
83
|
|
|
|
|
|
|
} elsif ( $style eq 'yy/mm/dd hh:mm' ) { |
84
|
0
|
|
|
|
|
0
|
return "$yy/$monmon/$dayday $hh:$mm"; |
85
|
|
|
|
|
|
|
} elsif ( $style eq 'yy/mm/dd' ) { |
86
|
0
|
|
|
|
|
0
|
return "$yy/$monmon/$dayday"; |
87
|
|
|
|
|
|
|
} elsif ( $style eq 'mm/dd/yy' ) { |
88
|
0
|
|
|
|
|
0
|
return "$monmon/$dayday/$yy"; |
89
|
|
|
|
|
|
|
} elsif ( $style eq 'yyyy-mm-dd' ) { |
90
|
0
|
|
|
|
|
0
|
return "$year-$monmon-$dayday"; |
91
|
|
|
|
|
|
|
} elsif ( $style eq 'yyyy-mm-dd:hh:mm' ) { |
92
|
0
|
|
|
|
|
0
|
return "$year-$monmon-$dayday:$hh:$mm"; |
93
|
|
|
|
|
|
|
} elsif ( $style =~ /^DATE: ?(.*?) TIME: ?(.*)$/ ) { |
94
|
0
|
|
|
|
|
0
|
my ($d_fmt, $t_fmt) = ($1, $2); |
95
|
0
|
|
|
|
|
0
|
my $date = Data::Quantity::Time::Date->new("$year-$mon-$mday"); |
96
|
0
|
|
|
|
|
0
|
return $date->readable( $d_fmt ) . " $h:$mm$AMPM"; |
97
|
|
|
|
|
|
|
} elsif ( $style eq 'h:mmPM' ) { |
98
|
0
|
|
|
|
|
0
|
return "$h:$mm$AMPM"; |
99
|
|
|
|
|
|
|
} else { |
100
|
0
|
|
|
|
|
0
|
croak "Unknown timestamp readable format."; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub date { |
105
|
0
|
|
|
0
|
0
|
0
|
my $moment_q = shift; |
106
|
0
|
0
|
|
|
|
0
|
my $udt = $moment_q->value or return; |
107
|
0
|
|
|
|
|
0
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( $udt ); |
108
|
0
|
|
|
|
|
0
|
$mon += 1; |
109
|
0
|
|
|
|
|
0
|
$year += 1900; |
110
|
0
|
|
|
|
|
0
|
require Data::Quantity::Time::Date; |
111
|
0
|
|
|
|
|
0
|
Data::Quantity::Time::Date->new("$year-$mon-$mday"); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub time { |
115
|
0
|
|
|
0
|
0
|
0
|
my $moment_q = shift; |
116
|
0
|
0
|
|
|
|
0
|
my $udt = $moment_q->value or return; |
117
|
0
|
|
|
|
|
0
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( $udt ); |
118
|
0
|
|
|
|
|
0
|
require Data::Quantity::Time::Time; |
119
|
0
|
|
|
|
|
0
|
Data::Quantity::Time::Time->new($hour, $min, $sec); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# $value = Data::Quantity::Time::Date->readable_value($number) |
123
|
|
|
|
|
|
|
# $value = Data::Quantity::Time::Date->readable_value($number, $style) |
124
|
|
|
|
|
|
|
sub readable_value { |
125
|
0
|
|
|
0
|
0
|
0
|
my $class_or_item = shift; |
126
|
0
|
|
|
|
|
0
|
my $value = shift; |
127
|
0
|
|
|
|
|
0
|
$class_or_item->new($value)->readable(@_); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# $quantity->init( $n_val ); |
131
|
|
|
|
|
|
|
sub init { |
132
|
2
|
|
|
2
|
0
|
4
|
my $num_q = shift; |
133
|
|
|
|
|
|
|
|
134
|
2
|
|
|
|
|
2
|
my $n_val = shift; |
135
|
2
|
|
|
|
|
15
|
my $numerals = $num_q->numeric_value( $n_val ); |
136
|
2
|
50
|
|
|
|
6
|
if ( defined $numerals ) { |
137
|
2
|
|
|
|
|
15
|
$num_q->value( $numerals ); |
138
|
|
|
|
|
|
|
} else { |
139
|
0
|
|
|
|
|
|
$num_q->set_from_string( $n_val ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# $date->set_from_string( $value ); |
144
|
|
|
|
|
|
|
sub set_from_string { |
145
|
0
|
|
|
0
|
0
|
|
my ($date, $value) = @_; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
my $udt = Time::ParseDate::parsedate($value, 'DATE_REQUIRED' => 1); |
148
|
0
|
0
|
|
|
|
|
if ($udt) { |
149
|
0
|
|
|
|
|
|
$date->set_udt($udt); |
150
|
|
|
|
|
|
|
} else { |
151
|
0
|
|
|
|
|
|
$date->value( 0 ); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |