line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Netstack::Utils::Date; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
4
|
|
|
|
|
|
|
# 加载扩展插件 |
5
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
6
|
1
|
|
|
1
|
|
57579
|
use 5.016; |
|
1
|
|
|
|
|
12
|
|
7
|
1
|
|
|
1
|
|
480
|
use Moose; |
|
1
|
|
|
|
|
403972
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
7059
|
use namespace::autoclean; |
|
1
|
|
|
|
|
7180
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub getLocalDate { |
11
|
2
|
|
|
2
|
0
|
16
|
my ( $self, @param ) = @_; |
12
|
|
|
|
|
|
|
# 初始化变量 |
13
|
2
|
|
|
|
|
5
|
my ( $format, $time ); |
14
|
|
|
|
|
|
|
|
15
|
2
|
100
|
66
|
|
|
11
|
if ( defined $param[0] and $param[0] =~ /^\d+$/ ) { |
16
|
1
|
|
|
|
|
3
|
( $time, $format ) = @param; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
else { |
19
|
1
|
|
|
|
|
2
|
( $format, $time ) = @param; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
# 缺省时间格式 |
22
|
2
|
50
|
|
|
|
13
|
if ( not defined $format ) { |
23
|
2
|
|
|
|
|
4
|
$format = 'yyyy-mm-dd hh:mi:ss'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
# 缺省为本地时间 |
26
|
2
|
100
|
|
|
|
6
|
if ( not defined $time ) { |
27
|
1
|
|
|
|
|
2
|
$time = time(); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
# 时间对象切片 |
30
|
2
|
|
|
|
|
78
|
my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime($time); |
31
|
|
|
|
|
|
|
# 定义本地时间数据字典 |
32
|
2
|
|
|
|
|
17
|
my %timeMap = ( |
33
|
|
|
|
|
|
|
yyyy => $year + 1900, |
34
|
|
|
|
|
|
|
mm => $mon + 1, |
35
|
|
|
|
|
|
|
dd => $mday, |
36
|
|
|
|
|
|
|
hh => $hour, |
37
|
|
|
|
|
|
|
mi => $min, |
38
|
|
|
|
|
|
|
ss => $sec, |
39
|
|
|
|
|
|
|
); |
40
|
2
|
|
|
|
|
14
|
my %formatMap = ( |
41
|
|
|
|
|
|
|
yyyy => '%04d', |
42
|
|
|
|
|
|
|
mm => '%02d', |
43
|
|
|
|
|
|
|
dd => '%02d', |
44
|
|
|
|
|
|
|
hh => '%02d', |
45
|
|
|
|
|
|
|
mi => '%02d', |
46
|
|
|
|
|
|
|
ss => '%02d', |
47
|
|
|
|
|
|
|
); |
48
|
2
|
|
|
|
|
10
|
my $regex = '(' . join( '|', keys %timeMap ) . ')'; |
49
|
2
|
|
|
|
|
79
|
my @times = map { $timeMap{$_} } ( $format =~ /$regex/g ); |
|
12
|
|
|
|
|
22
|
|
50
|
2
|
50
|
|
|
|
8
|
if ( scalar(@times) == 0 ) { |
51
|
0
|
|
|
|
|
0
|
confess "ERROR: format string [$format] has none valid characters\n"; |
52
|
|
|
|
|
|
|
} |
53
|
2
|
|
|
|
|
53
|
$format =~ s/$regex/$formatMap{$1}/g; |
54
|
2
|
|
|
|
|
12
|
my $localTime = sprintf( "$format", @times ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# 返回计算结果 |
57
|
2
|
|
|
|
|
84
|
return $localTime; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
61
|
|
|
|
|
|
|
1; |