line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
XAO::DO::Web::Date - XAO::Web date dysplayable object |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
<%Date%> |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
<%Date gmtime="123456789" style="short"%> |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
<%Date format="%H:%M"%> |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
<%Date gmtime="123456789" timezone="US/Eastern"%> |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
############################################################################### |
18
|
|
|
|
|
|
|
package XAO::DO::Web::Date; |
19
|
1
|
|
|
1
|
|
975
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
20
|
1
|
|
|
1
|
|
5
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
21
|
1
|
|
|
1
|
|
92
|
use XAO::Utils; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
22
|
1
|
|
|
1
|
|
6
|
use XAO::Objects; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
23
|
1
|
|
|
1
|
|
6
|
use base XAO::Objects->load(objname => 'Web::Page'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION='2.001'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
############################################################################### |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Displays current or given date. Arguments are: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item gmtime |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Number of seconds since the Epoch (unix standard time). Optional, |
38
|
|
|
|
|
|
|
default is to display the current time. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item style |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Display according to one of internal styles: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
dateonly => %m/%d/%Y => 3/27/2002 |
45
|
|
|
|
|
|
|
short => %H:%M:%S %m/%d/%Y => 12:23:34 3/27/2002 |
46
|
|
|
|
|
|
|
timeonly => %H:%M:%S => 12:23:34 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item format |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Set custom format according to strftime C function API. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item timezone |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
May contain a name of a time zone, which must be known to the |
55
|
|
|
|
|
|
|
system. Default is the default system timezone. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub display ($;%) { |
62
|
600
|
|
|
600
|
1
|
855
|
my $self=shift; |
63
|
600
|
|
|
|
|
1148
|
my $args=get_args(\@_); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
## |
66
|
|
|
|
|
|
|
# Setting timezone |
67
|
|
|
|
|
|
|
# |
68
|
600
|
|
|
|
|
4832
|
my $tz; |
69
|
600
|
50
|
|
|
|
1136
|
if($args->{timezone}) { |
70
|
0
|
|
|
|
|
0
|
$tz=$ENV{TZ}; |
71
|
0
|
|
|
|
|
0
|
$ENV{TZ}=$args->{timezone}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
## |
75
|
|
|
|
|
|
|
# It can be current time or given time |
76
|
|
|
|
|
|
|
# |
77
|
600
|
|
33
|
|
|
1149
|
my $time=$args->{gmtime} || time; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
## |
80
|
|
|
|
|
|
|
# Checking output style |
81
|
|
|
|
|
|
|
# |
82
|
600
|
|
50
|
|
|
4494
|
my $style=$args->{style} || ''; |
83
|
600
|
|
|
|
|
749
|
my $format=''; |
84
|
600
|
50
|
|
|
|
1002
|
if(!$style) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
85
|
600
|
|
|
|
|
868
|
$format=$args->{format}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif($style eq 'dateonly') { |
88
|
0
|
|
|
|
|
0
|
$format='%m/%d/%Y'; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif($style eq 'short') { |
91
|
0
|
|
|
|
|
0
|
$format='%H:%M:%S %m/%d/%Y'; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif($style eq 'timeonly') { |
94
|
0
|
|
|
|
|
0
|
$format='%H:%M:%S'; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
0
|
|
|
|
|
0
|
eprint "Unknown date style '$style'"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
## |
101
|
|
|
|
|
|
|
# Displaying according to format. |
102
|
|
|
|
|
|
|
# |
103
|
600
|
50
|
|
|
|
1058
|
if($format) { |
104
|
600
|
|
|
|
|
25329
|
$time=strftime($format,localtime($time)); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
0
|
|
|
|
|
0
|
$time=scalar(localtime($time)); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
600
|
|
|
|
|
3035
|
$self->textout($time); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
## |
113
|
|
|
|
|
|
|
# Restoring timezone |
114
|
|
|
|
|
|
|
# |
115
|
600
|
50
|
|
|
|
1826
|
if($args->{timezone}) { |
116
|
0
|
0
|
|
|
|
|
if(defined $tz) { |
117
|
0
|
|
|
|
|
|
$ENV{TZ}=$tz; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else { |
120
|
0
|
|
|
|
|
|
delete $ENV{TZ}; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
############################################################################### |
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
__END__ |