line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Netstack::Utils::Date; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
4
|
|
|
|
|
|
|
# 加载扩展插件 |
5
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
6
|
1
|
|
|
1
|
|
56552
|
use 5.016; |
|
1
|
|
|
|
|
11
|
|
7
|
1
|
|
|
1
|
|
496
|
use Moose; |
|
1
|
|
|
|
|
436356
|
|
|
1
|
|
|
|
|
10
|
|
8
|
1
|
|
|
1
|
|
7168
|
use namespace::autoclean; |
|
1
|
|
|
|
|
7517
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub getLocalDate { |
11
|
2
|
|
|
2
|
0
|
19
|
my ( $self, @param ) = @_; |
12
|
|
|
|
|
|
|
# 初始化变量 |
13
|
2
|
|
|
|
|
3
|
my ( $format, $time ); |
14
|
|
|
|
|
|
|
|
15
|
2
|
100
|
66
|
|
|
12
|
if ( defined $param[0] and $param[0] =~ /^\d+$/ ) { |
16
|
1
|
|
|
|
|
2
|
( $time, $format ) = @param; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
else { |
19
|
1
|
|
|
|
|
3
|
( $format, $time ) = @param; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
# 缺省时间格式 |
22
|
2
|
50
|
|
|
|
21
|
if ( not defined $format ) { |
23
|
2
|
|
|
|
|
3
|
$format = 'yyyy-mm-dd hh:mi:ss'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
# 缺省为本地时间 |
26
|
2
|
100
|
|
|
|
5
|
if ( not defined $time ) { |
27
|
1
|
|
|
|
|
2
|
$time = time(); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
# 时间对象切片 |
30
|
2
|
|
|
|
|
90
|
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
|
|
|
|
|
15
|
my %formatMap = ( |
41
|
|
|
|
|
|
|
yyyy => '%04d', |
42
|
|
|
|
|
|
|
mm => '%02d', |
43
|
|
|
|
|
|
|
dd => '%02d', |
44
|
|
|
|
|
|
|
hh => '%02d', |
45
|
|
|
|
|
|
|
mi => '%02d', |
46
|
|
|
|
|
|
|
ss => '%02d', |
47
|
|
|
|
|
|
|
); |
48
|
2
|
|
|
|
|
11
|
my $regex = '(' . join( '|', keys %timeMap ) . ')'; |
49
|
2
|
|
|
|
|
96
|
my @times = map { $timeMap{$_} } ( $format =~ /$regex/g ); |
|
12
|
|
|
|
|
21
|
|
50
|
2
|
50
|
|
|
|
9
|
if ( scalar(@times) == 0 ) { |
51
|
0
|
|
|
|
|
0
|
confess "ERROR: format string [$format] has none valid characters\n"; |
52
|
|
|
|
|
|
|
} |
53
|
2
|
|
|
|
|
54
|
$format =~ s/$regex/$formatMap{$1}/g; |
54
|
2
|
|
|
|
|
13
|
my $localTime = sprintf( "$format", @times ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# 返回计算结果 |
57
|
2
|
|
|
|
|
46
|
return $localTime; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
61
|
|
|
|
|
|
|
1; |