line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BlankOnDev::DateTime; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Import Module : |
7
|
1
|
|
|
1
|
|
718
|
use DateTime; |
|
1
|
|
|
|
|
430240
|
|
|
1
|
|
|
|
|
53
|
|
8
|
|
|
|
|
|
|
#use NKTIweb::DateTime::lang; |
9
|
1
|
|
|
1
|
|
8
|
use base 'BlankOnDev::DateTime::lang'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
527
|
|
10
|
|
|
|
|
|
|
#use vars qw($language $date_lang); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Version : |
13
|
|
|
|
|
|
|
our $VERSION = '0.1005';; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# scalar global : |
16
|
|
|
|
|
|
|
our ($language, $date_lang); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Subroutine for set languages : |
19
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
20
|
|
|
|
|
|
|
sub set_lang { |
21
|
|
|
|
|
|
|
# Define parameter subroutine : |
22
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
my $key_param = scalar keys(@_); |
24
|
0
|
|
|
|
|
|
my $lang = 'id_ID'; |
25
|
0
|
|
|
|
|
|
my $hashdate = undef; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# IF one parameter input : |
28
|
0
|
0
|
|
|
|
|
if ($key_param eq 1) { |
29
|
0
|
0
|
0
|
|
|
|
if ($_[0] =~ m/^[A-Za-z_]+/ and ref($_[0]) ne 'HASH') { |
|
|
0
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$lang = $_[0]; |
31
|
0
|
|
|
|
|
|
$language = $_[0]; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif (ref($_[0]) eq 'HASH') { |
34
|
0
|
|
|
|
|
|
$hashdate = $_[0]; |
35
|
0
|
|
|
|
|
|
$date_lang = $_[0]; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# IF two parameters input : |
40
|
0
|
0
|
|
|
|
|
if ($key_param eq 2) { |
41
|
0
|
0
|
0
|
|
|
|
if ($_[0] =~ m/^[A-Za-z_]+/ and ref($_[0]) ne 'HASH') { |
|
|
0
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$lang = $_[0]; |
43
|
0
|
|
|
|
|
|
$language = $_[0]; |
44
|
|
|
|
|
|
|
} elsif (ref($_[0]) eq 'HASH') { |
45
|
0
|
|
|
|
|
|
$lang = $_[0]; |
46
|
0
|
|
|
|
|
|
$language = $_[0]; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
0
|
|
|
|
if (ref($_[1]) eq 'HASH') { |
|
|
0
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$hashdate = $_[1]; |
50
|
0
|
|
|
|
|
|
$date_lang = $_[1]; |
51
|
|
|
|
|
|
|
} elsif ($_[1] =~ m/^[A-Za-z_]+/ and ref($_[1]) ne 'HASH') { |
52
|
0
|
|
|
|
|
|
$lang = $_[1]; |
53
|
0
|
|
|
|
|
|
$language = $_[1]; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Subroutine for get languages : |
59
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
60
|
|
|
|
|
|
|
sub get_lang { |
61
|
|
|
|
|
|
|
# Define parameter subroutine : |
62
|
0
|
|
|
0
|
0
|
|
my ($self, $lang) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Define scalar for place result : |
65
|
0
|
|
|
|
|
|
my $data = undef; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Get language : |
68
|
0
|
|
|
|
|
|
my $get_lang = $self->$lang(); |
69
|
0
|
|
|
|
|
|
$date_lang = $get_lang; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $get_lang; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
# End of Subroutine for get languages |
74
|
|
|
|
|
|
|
# =========================================================================================================== |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Subroutine for Add or Subtract Duration : |
77
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
78
|
|
|
|
|
|
|
sub add_or_subtract { |
79
|
|
|
|
|
|
|
# Define parameter subroutine : |
80
|
0
|
|
|
0
|
0
|
|
my ($self, $dt, $minplus) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Define scalar for use in this function : |
83
|
0
|
|
|
|
|
|
my $action = undef; |
84
|
0
|
|
|
|
|
|
my $number = undef; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Check IF $minplus == "HASH" : |
87
|
0
|
0
|
|
|
|
|
if ($minplus ne '') { |
88
|
|
|
|
|
|
|
# print "HASH type \n"; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Parse Action : |
91
|
0
|
0
|
|
|
|
|
$action = $minplus =~ m/\+/ ? 'add' : 'subtract'; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Parse Time for add or subtract : |
94
|
0
|
0
|
|
|
|
|
if ($minplus =~ m/[D]/) { |
95
|
0
|
|
|
|
|
|
$minplus =~ s/\D//g; |
96
|
0
|
|
|
|
|
|
$number = $minplus; |
97
|
0
|
0
|
|
|
|
|
$number = $number eq '' ? 1 : $number; |
98
|
0
|
0
|
|
|
|
|
if ($action eq 'add') { |
99
|
0
|
|
|
|
|
|
$dt->add(days => $number); |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
|
$dt->subtract(days => $number); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
0
|
0
|
|
|
|
|
if ($minplus =~ m/W/) { |
105
|
0
|
|
|
|
|
|
$minplus =~ s/\D//g; |
106
|
0
|
|
|
|
|
|
$number = $minplus; |
107
|
0
|
0
|
|
|
|
|
$number = $number eq '' ? 1 : $number; |
108
|
0
|
0
|
|
|
|
|
if ($action eq 'add') { |
109
|
0
|
|
|
|
|
|
$dt->add(weeks => $number); |
110
|
|
|
|
|
|
|
} else { |
111
|
0
|
|
|
|
|
|
$dt->subtract(weeks => $number); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
0
|
0
|
|
|
|
|
if ($minplus =~ m/M/) { |
115
|
0
|
|
|
|
|
|
$minplus =~ s/\D//g; |
116
|
0
|
|
|
|
|
|
$number = $minplus; |
117
|
0
|
0
|
|
|
|
|
$number = $number eq '' ? 1 : $number; |
118
|
0
|
0
|
|
|
|
|
if ($action eq 'add') { |
119
|
0
|
|
|
|
|
|
$dt->add(months => $number); |
120
|
|
|
|
|
|
|
} else { |
121
|
0
|
|
|
|
|
|
$dt->subtract(months => $number); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
0
|
0
|
|
|
|
|
if ($minplus =~ m/Y/) { |
125
|
0
|
|
|
|
|
|
$minplus =~ s/\D//g; |
126
|
0
|
|
|
|
|
|
$number = $minplus; |
127
|
0
|
0
|
|
|
|
|
$number = $number eq '' ? 1 : $number; |
128
|
0
|
0
|
|
|
|
|
if ($action eq 'add') { |
129
|
0
|
|
|
|
|
|
$dt->add(years => $number); |
130
|
|
|
|
|
|
|
} else { |
131
|
0
|
|
|
|
|
|
$dt->subtract(years => $number); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
0
|
0
|
|
|
|
|
if ($minplus =~ m/h/) { |
135
|
0
|
|
|
|
|
|
$minplus =~ s/\D//g; |
136
|
0
|
|
|
|
|
|
$number = $minplus; |
137
|
0
|
0
|
|
|
|
|
$number = $number eq '' ? 1 : $number; |
138
|
0
|
0
|
|
|
|
|
if ($action eq 'add') { |
139
|
0
|
|
|
|
|
|
$dt->add(hours => $number); |
140
|
|
|
|
|
|
|
} else { |
141
|
0
|
|
|
|
|
|
$dt->subtract(hours => $number); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
0
|
0
|
|
|
|
|
if ($minplus =~ m/m/) { |
145
|
0
|
|
|
|
|
|
$minplus =~ s/\D//g; |
146
|
0
|
|
|
|
|
|
$number = $minplus; |
147
|
0
|
0
|
|
|
|
|
$number = $number eq '' ? 1 : $number; |
148
|
0
|
0
|
|
|
|
|
if ($action eq 'add') { |
149
|
0
|
|
|
|
|
|
$dt->add(minutes => $number); |
150
|
|
|
|
|
|
|
} else { |
151
|
0
|
|
|
|
|
|
$dt->subtract(minutes => $number); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
0
|
0
|
|
|
|
|
if ($minplus =~ m/s/) { |
155
|
0
|
|
|
|
|
|
$minplus =~ s/\D//g; |
156
|
0
|
|
|
|
|
|
$number = $minplus; |
157
|
0
|
0
|
|
|
|
|
$number = $number eq '' ? 1 : $number; |
158
|
0
|
0
|
|
|
|
|
if ($action eq 'add') { |
159
|
0
|
|
|
|
|
|
$dt->add(seconds => $number); |
160
|
|
|
|
|
|
|
} else { |
161
|
0
|
|
|
|
|
|
$dt->subtract(seconds => $number); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
0
|
|
|
|
|
|
return(0); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
# End of Subroutine for Add or Subtract Duration |
168
|
|
|
|
|
|
|
# =========================================================================================================== |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Subroutine for Get Date Time : |
172
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
173
|
|
|
|
|
|
|
sub get { |
174
|
|
|
|
|
|
|
# Define parameter subroutine : |
175
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
176
|
0
|
|
|
|
|
|
my $timestamp = undef; |
177
|
0
|
|
|
|
|
|
my $timezone = undef; |
178
|
0
|
|
|
|
|
|
my $attribute = undef; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Define hash for place result : |
181
|
0
|
|
|
|
|
|
my %data = (); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# IF no input parameter : |
184
|
0
|
|
|
|
|
|
my $keys_param = scalar keys(@_); |
185
|
0
|
0
|
|
|
|
|
if ($keys_param eq 0) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
$timestamp = time(); |
187
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
# IF just one of input parameter : |
190
|
|
|
|
|
|
|
elsif ($keys_param eq 1) { |
191
|
0
|
0
|
|
|
|
|
if ($_[0] =~ m/^[0-9,.E]+$/) { |
192
|
0
|
|
|
|
|
|
$timestamp = $_[0]; |
193
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
194
|
0
|
|
|
|
|
|
$attribute = undef; |
195
|
|
|
|
|
|
|
} |
196
|
0
|
0
|
0
|
|
|
|
if ($_[0] =~ m/^[A-Za-z\/]+/ and ref($_[0]) ne 'HASH') { |
197
|
0
|
|
|
|
|
|
$timestamp = time(); |
198
|
0
|
|
|
|
|
|
$timezone = $_[0]; |
199
|
0
|
|
|
|
|
|
$attribute = undef; |
200
|
|
|
|
|
|
|
} |
201
|
0
|
0
|
|
|
|
|
if (ref($_[0]) eq "HASH") { |
202
|
0
|
|
|
|
|
|
$timestamp = time(); |
203
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
204
|
0
|
|
|
|
|
|
$attribute = $_[0]; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
# IF just two of input parameter : |
208
|
|
|
|
|
|
|
elsif ($keys_param == 2) { |
209
|
|
|
|
|
|
|
# For $_[0] : |
210
|
0
|
0
|
0
|
|
|
|
if ($_[0] =~ m/^[0-9,.E]+$/) { |
|
|
0
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
$timestamp = $_[0]; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
elsif ($_[0] =~ m/^[A-Za-z\/\w]+/ and ref($_[0]) ne 'HASH') { |
214
|
0
|
|
|
|
|
|
$timestamp = time(); |
215
|
0
|
|
|
|
|
|
$timezone = $_[0]; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
# For $_[1] : |
218
|
0
|
0
|
0
|
|
|
|
if ($_[1] =~ m/^[A-Za-z\/]+/ and ref($_[1]) ne 'HASH') { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
$timezone = $_[1]; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
elsif ($_[1] =~ m/^[0-9,.E]+$/ and ref($_[1]) ne 'HASH') { |
222
|
0
|
|
|
|
|
|
$timestamp = $_[1]; |
223
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
elsif (ref($_[1]) eq "HASH") { |
226
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
227
|
0
|
|
|
|
|
|
$attribute = $_[1]; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
# IF three of input parameter : |
232
|
|
|
|
|
|
|
elsif ($keys_param eq 3) { |
233
|
|
|
|
|
|
|
# For $_[0] : |
234
|
0
|
0
|
0
|
|
|
|
if (exists $_[0] and $_[0] =~ m/^[0-9,.E]+$/) { |
235
|
0
|
|
|
|
|
|
$timestamp = $_[0]; |
236
|
|
|
|
|
|
|
} else { |
237
|
0
|
|
|
|
|
|
$timestamp = time(); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
# For $_[1] : |
240
|
0
|
0
|
0
|
|
|
|
if (exists $_[1] and $_[1] =~ m/^[A-Za-z\/]+/ and ref($_[1]) ne 'HASH') { |
|
|
|
0
|
|
|
|
|
241
|
0
|
|
|
|
|
|
$timezone = $_[1]; |
242
|
|
|
|
|
|
|
} else { |
243
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
244
|
0
|
|
|
|
|
|
$attribute = undef; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
# For $_[2] : |
247
|
0
|
0
|
0
|
|
|
|
if (exists $_[2] and ref($_[2]) eq "HASH") { |
248
|
0
|
|
|
|
|
|
$attribute = $_[2]; |
249
|
|
|
|
|
|
|
} else { |
250
|
0
|
|
|
|
|
|
$attribute = undef; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} else { |
253
|
0
|
|
|
|
|
|
$timestamp = time(); |
254
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# Get Language : |
258
|
0
|
0
|
|
|
|
|
if ($language) { |
259
|
0
|
|
|
|
|
|
$self->set_lang($language); |
260
|
|
|
|
|
|
|
} else { |
261
|
0
|
|
|
|
|
|
$self->set_lang('id_ID'); |
262
|
|
|
|
|
|
|
} |
263
|
0
|
|
|
|
|
|
my $lang_date = $self->get_lang($language); |
264
|
0
|
|
|
|
|
|
my @Mname = @{$lang_date->{'month'}}; |
|
0
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
my @Mname_short = @{$lang_date->{'month_short'}}; |
|
0
|
|
|
|
|
|
|
266
|
0
|
|
|
|
|
|
my @Dname = @{$lang_date->{'day'}}; |
|
0
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
my @Dname_short = @{$lang_date->{'day_short'}}; |
|
0
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# Get date time ; |
270
|
0
|
|
|
|
|
|
my $dt = DateTime->from_epoch(epoch => $timestamp); |
271
|
0
|
|
|
|
|
|
$dt->set_time_zone( $timezone ); |
272
|
0
|
|
|
|
|
|
my $dayNum = $dt->day_of_week(); |
273
|
0
|
|
|
|
|
|
my $dayName = $Dname[$dayNum]; |
274
|
0
|
|
|
|
|
|
my $dayName_short = $Dname_short[$dayNum]; |
275
|
0
|
|
|
|
|
|
my $date_num = $dt->day(); |
276
|
0
|
|
|
|
|
|
my $monthNum = $dt->month(); |
277
|
0
|
|
|
|
|
|
my $monthName = $Mname[$monthNum]; |
278
|
0
|
|
|
|
|
|
my $years = $dt->year(); |
279
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
|
my $hours = $dt->hour(); |
281
|
0
|
|
|
|
|
|
my $minutes = $dt->minute(); |
282
|
0
|
|
|
|
|
|
my $second = $dt->second(); |
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
|
my $ymd = undef; |
285
|
0
|
|
|
|
|
|
my $dmy = undef; |
286
|
0
|
|
|
|
|
|
my $hms = undef; |
287
|
0
|
|
|
|
|
|
my $DateNow = undef; |
288
|
0
|
|
|
|
|
|
my $DateNow_custom = undef; |
289
|
0
|
|
|
|
|
|
my $DateNow_custom_instring = undef; |
290
|
0
|
|
|
|
|
|
my $add_or_subtract = undef; |
291
|
0
|
|
|
|
|
|
my $epoch_time = undef; |
292
|
|
|
|
|
|
|
# my $epoch_time = $dt->epoch(); |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
# Check $attribute ; |
295
|
0
|
0
|
|
|
|
|
if (ref($attribute) eq 'HASH') { |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
# For Config : |
298
|
0
|
0
|
|
|
|
|
my $delim_date = $attribute->{'date'} ? $attribute->{'date'} : '-'; |
299
|
0
|
0
|
|
|
|
|
my $delim_time = $attribute->{'time'} ? $attribute->{'time'} : ':'; |
300
|
0
|
0
|
|
|
|
|
my $delim_datetime = $attribute->{'datetime'} ? $attribute->{'datetime'} : ' '; |
301
|
0
|
0
|
|
|
|
|
my $minplus_datetime = $attribute->{'minplus'} ? $attribute->{'minplus'} : ''; |
302
|
0
|
|
|
|
|
|
$add_or_subtract = $self->add_or_subtract($dt, $minplus_datetime); |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
# get Date Format : |
305
|
0
|
|
|
|
|
|
$dayNum = $dt->day_of_week(); |
306
|
0
|
|
|
|
|
|
$dayName = $Dname[$dayNum]; |
307
|
0
|
|
|
|
|
|
$dayName_short = $Dname_short[$dayNum]; |
308
|
0
|
|
|
|
|
|
$date_num = $dt->day(); |
309
|
0
|
|
|
|
|
|
$monthNum = $dt->month(); |
310
|
0
|
|
|
|
|
|
$monthName = $Mname[$monthNum]; |
311
|
0
|
|
|
|
|
|
$years = $dt->year(); |
312
|
0
|
|
|
|
|
|
$epoch_time = $dt->epoch(); |
313
|
|
|
|
|
|
|
|
314
|
0
|
|
|
|
|
|
$hours = $dt->hour(); |
315
|
0
|
|
|
|
|
|
$minutes = $dt->minute(); |
316
|
0
|
|
|
|
|
|
$second = $dt->second(); |
317
|
|
|
|
|
|
|
|
318
|
0
|
|
|
|
|
|
$ymd = $dt->ymd($delim_date); |
319
|
0
|
|
|
|
|
|
$dmy = $dt->dmy($delim_date); |
320
|
0
|
|
|
|
|
|
$hms = $dt->hms($delim_time); |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
# For Action Custom : |
323
|
0
|
0
|
|
|
|
|
my $format_datetime = $attribute->{'format'} ? $attribute->{'format'} : ''; |
324
|
0
|
|
|
|
|
|
$format_datetime =~ s/DD/$date_num/g; |
325
|
0
|
|
|
|
|
|
$format_datetime =~ s/Dn/$dayName_short/g; |
326
|
0
|
|
|
|
|
|
$format_datetime =~ s/Di/$dayNum/g; |
327
|
0
|
|
|
|
|
|
$format_datetime =~ s/MM/$monthNum/g; |
328
|
0
|
|
|
|
|
|
$format_datetime =~ s/YYYY/$years/g; |
329
|
0
|
|
|
|
|
|
$format_datetime =~ s/h/$hours/g; |
330
|
0
|
|
|
|
|
|
$format_datetime =~ s/m/$minutes/g; |
331
|
0
|
|
|
|
|
|
$format_datetime =~ s/s/$second/g; |
332
|
0
|
|
|
|
|
|
$DateNow_custom_instring = $format_datetime; |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
# For Action |
335
|
0
|
|
|
|
|
|
$DateNow = $ymd.' '.$hms; |
336
|
0
|
|
|
|
|
|
$DateNow_custom = $ymd.$delim_datetime.$hms; |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
} else { |
339
|
|
|
|
|
|
|
# get Date Format : |
340
|
0
|
|
|
|
|
|
$ymd = $dt->ymd(); |
341
|
0
|
|
|
|
|
|
$dmy = $dt->dmy(); |
342
|
0
|
|
|
|
|
|
$hms = $dt->hms(); |
343
|
0
|
|
|
|
|
|
$DateNow = $ymd.' '.$hms; |
344
|
0
|
|
|
|
|
|
$DateNow_custom = $ymd.' '.$hms; |
345
|
0
|
|
|
|
|
|
$epoch_time = $dt->epoch(); |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
# Place result : |
349
|
0
|
|
|
|
|
|
$data{'custom_in_string'} = $DateNow_custom_instring; |
350
|
0
|
|
|
|
|
|
$data{'custom'} = $DateNow_custom; |
351
|
0
|
|
|
|
|
|
$data{'datetime'} = $DateNow; |
352
|
0
|
|
|
|
|
|
$data{'timestamp'} = $epoch_time; |
353
|
0
|
|
|
|
|
|
$data{'calender'} = { |
354
|
|
|
|
|
|
|
'day_num' => $dayNum, |
355
|
|
|
|
|
|
|
'day_name' => $dayName, |
356
|
|
|
|
|
|
|
'day_short' => $dayName_short, |
357
|
|
|
|
|
|
|
'date' => $date_num, |
358
|
|
|
|
|
|
|
'month' => $monthNum, |
359
|
|
|
|
|
|
|
'month_name' => $monthName, |
360
|
|
|
|
|
|
|
'year' => $years, |
361
|
|
|
|
|
|
|
'ymd' => $ymd, |
362
|
|
|
|
|
|
|
'dmy' => $dmy, |
363
|
|
|
|
|
|
|
}; |
364
|
0
|
|
|
|
|
|
$data{'time'} = { |
365
|
|
|
|
|
|
|
'hour' => $hours, |
366
|
|
|
|
|
|
|
'minute' => $minutes, |
367
|
|
|
|
|
|
|
'second' => $second, |
368
|
|
|
|
|
|
|
'hms' => $hms |
369
|
|
|
|
|
|
|
}; |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
# $data{'timestamp'} = $timestamp; |
372
|
|
|
|
|
|
|
# $data{'timezone'} = $timezone; |
373
|
|
|
|
|
|
|
# $data{'test'} = 'data-test'; |
374
|
|
|
|
|
|
|
# $data{'param'} = \@_; |
375
|
|
|
|
|
|
|
# $data{'param1'} = $_[0]; |
376
|
|
|
|
|
|
|
# $data{'param2'} = $_[1]; |
377
|
|
|
|
|
|
|
# $data{'param1_ref'} = ref($_[0]); |
378
|
|
|
|
|
|
|
# $data{'config'} = $attribute; |
379
|
|
|
|
|
|
|
# $data{'keys_param'} = $keys_param; |
380
|
|
|
|
|
|
|
# $data{'self'} = $self; |
381
|
|
|
|
|
|
|
# $data{'attribute'} = ref($attribute); |
382
|
|
|
|
|
|
|
# $data{'add-substr'} = $add_or_subtract; |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
# Return result : |
385
|
0
|
|
|
|
|
|
return \%data; |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
# End of Subroutine for Get Date Time |
388
|
|
|
|
|
|
|
# =========================================================================================================== |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
# Subroutine for Indonesia Timezone : |
391
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
392
|
|
|
|
|
|
|
sub id_timezone { |
393
|
0
|
|
|
0
|
0
|
|
my %data = (); |
394
|
|
|
|
|
|
|
|
395
|
0
|
|
|
|
|
|
$data{'wib'} = 'Asia/Jakarta'; |
396
|
0
|
|
|
|
|
|
$data{'wita'} = 'Asia/Makassar'; |
397
|
0
|
|
|
|
|
|
$data{'wit'} = 'Asia/Jayapura'; |
398
|
0
|
|
|
|
|
|
$data{'short-long'} = { |
399
|
|
|
|
|
|
|
'wib' => 'Asia/Jakarta', |
400
|
|
|
|
|
|
|
'wita' => 'Asia/Makassar', |
401
|
|
|
|
|
|
|
'wit' => 'Asia/Jayapura' |
402
|
|
|
|
|
|
|
}; |
403
|
0
|
|
|
|
|
|
$data{'long-short'} = { |
404
|
|
|
|
|
|
|
'Asia/Jakarta' => 'wib', |
405
|
|
|
|
|
|
|
'Asia/Makassar' => 'wita', |
406
|
|
|
|
|
|
|
'Asia/Jayapura' => 'wit' |
407
|
|
|
|
|
|
|
}; |
408
|
0
|
|
|
|
|
|
$data{'shor-num'} = { |
409
|
|
|
|
|
|
|
'wib' => 1, |
410
|
|
|
|
|
|
|
'wita' => 2, |
411
|
|
|
|
|
|
|
'wit' => 3 |
412
|
|
|
|
|
|
|
}; |
413
|
0
|
|
|
|
|
|
$data{'long-num'} = { |
414
|
|
|
|
|
|
|
'Asia/Jakarta' => 1, |
415
|
|
|
|
|
|
|
'Asia/Makassar' => 2, |
416
|
|
|
|
|
|
|
'Asia/Jayapura' => 3 |
417
|
|
|
|
|
|
|
}; |
418
|
0
|
|
|
|
|
|
$data{'num-short'} = { |
419
|
|
|
|
|
|
|
'1' => 'wib', |
420
|
|
|
|
|
|
|
'2' => 'wita', |
421
|
|
|
|
|
|
|
'3' => 'wit', |
422
|
|
|
|
|
|
|
}; |
423
|
0
|
|
|
|
|
|
$data{'num-long'} = { |
424
|
|
|
|
|
|
|
'1' => 'Asia/Jakarta', |
425
|
|
|
|
|
|
|
'2' => 'Asia/Makassar', |
426
|
|
|
|
|
|
|
'3' => 'Asia/Jayapura' |
427
|
|
|
|
|
|
|
}; |
428
|
0
|
|
|
|
|
|
return \%data; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
# Subroutine for Test Module NKTIweb::DateTime : |
431
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
432
|
|
|
|
|
|
|
sub test { |
433
|
|
|
|
|
|
|
# Define parameter subroutine : |
434
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
435
|
0
|
|
|
|
|
|
my $timestamp = undef; |
436
|
0
|
|
|
|
|
|
my $timezone = undef; |
437
|
0
|
|
|
|
|
|
my $attribute = undef; |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
# Define hash for place result : |
440
|
0
|
|
|
|
|
|
my %data = (); |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
# IF no input parameter : |
443
|
0
|
|
|
|
|
|
my $keys_param = scalar keys(@_); |
444
|
0
|
0
|
|
|
|
|
if ($keys_param eq 0) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
445
|
0
|
|
|
|
|
|
$timestamp = time(); |
446
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
# IF just one of input parameter : |
449
|
|
|
|
|
|
|
elsif ($keys_param eq 1) { |
450
|
0
|
0
|
|
|
|
|
if ($_[0] =~ m/^[0-9,.E]+$/) { |
451
|
0
|
|
|
|
|
|
$timestamp = $_[0]; |
452
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
453
|
0
|
|
|
|
|
|
$attribute = undef; |
454
|
|
|
|
|
|
|
} |
455
|
0
|
0
|
0
|
|
|
|
if ($_[0] =~ m/^[A-Za-z\/]+/ and ref($_[0]) ne 'HASH') { |
456
|
0
|
|
|
|
|
|
$timestamp = time(); |
457
|
0
|
|
|
|
|
|
$timezone = $_[0]; |
458
|
0
|
|
|
|
|
|
$attribute = undef; |
459
|
|
|
|
|
|
|
} |
460
|
0
|
0
|
|
|
|
|
if (ref($_[0]) eq "HASH") { |
461
|
0
|
|
|
|
|
|
$timestamp = time(); |
462
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
463
|
0
|
|
|
|
|
|
$attribute = $_[0]; |
464
|
|
|
|
|
|
|
} |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
# IF just two of input parameter : |
467
|
|
|
|
|
|
|
elsif ($keys_param == 2) { |
468
|
|
|
|
|
|
|
# For $_[0] : |
469
|
0
|
0
|
0
|
|
|
|
if ($_[0] =~ m/^[0-9,.E]+$/) { |
|
|
0
|
|
|
|
|
|
470
|
0
|
|
|
|
|
|
$timestamp = $_[0]; |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
elsif ($_[0] =~ m/^[A-Za-z\/\w]+/ and ref($_[0]) ne 'HASH') { |
473
|
0
|
|
|
|
|
|
$timestamp = time(); |
474
|
0
|
|
|
|
|
|
$timezone = $_[0]; |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
# For $_[1] : |
477
|
0
|
0
|
0
|
|
|
|
if ($_[1] =~ m/^[A-Za-z\/]+/ and ref($_[1]) ne 'HASH') { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
478
|
0
|
|
|
|
|
|
$timezone = $_[1]; |
479
|
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
elsif ($_[1] =~ m/^[0-9,.E]+$/ and ref($_[1]) ne 'HASH') { |
481
|
0
|
|
|
|
|
|
$timestamp = $_[1]; |
482
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
483
|
|
|
|
|
|
|
} |
484
|
|
|
|
|
|
|
elsif (ref($_[1]) eq "HASH") { |
485
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
486
|
0
|
|
|
|
|
|
$attribute = $_[1]; |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
# IF three of input parameter : |
490
|
|
|
|
|
|
|
elsif ($keys_param eq 3) { |
491
|
|
|
|
|
|
|
# For $_[0] : |
492
|
0
|
0
|
|
|
|
|
if ($_[0] =~ m/^[0-9,.E]+$/) { |
493
|
0
|
|
|
|
|
|
$timestamp = $_[0]; |
494
|
|
|
|
|
|
|
} else { |
495
|
0
|
|
|
|
|
|
$timestamp = time(); |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
# For $_[1] : |
498
|
0
|
0
|
0
|
|
|
|
if ($_[1] =~ m/^[A-Za-z\/]+/ and ref($_[1]) ne 'HASH') { |
499
|
0
|
|
|
|
|
|
$timezone = $_[1]; |
500
|
|
|
|
|
|
|
} else { |
501
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
502
|
0
|
|
|
|
|
|
$attribute = undef; |
503
|
|
|
|
|
|
|
} |
504
|
|
|
|
|
|
|
# For $_[2] : |
505
|
0
|
0
|
|
|
|
|
if (ref($_[2]) eq "HASH") { |
506
|
0
|
|
|
|
|
|
$attribute = $_[2]; |
507
|
|
|
|
|
|
|
} else { |
508
|
0
|
|
|
|
|
|
$attribute = undef; |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
} else { |
511
|
0
|
|
|
|
|
|
$timestamp = time(); |
512
|
0
|
|
|
|
|
|
$timezone = 'Asia/Makassar'; |
513
|
|
|
|
|
|
|
} |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
# Print Result : |
517
|
0
|
|
|
|
|
|
print "TimeStamp : $timestamp <br>"; |
518
|
0
|
|
|
|
|
|
print "TimeZone : $timezone <br>"; |
519
|
0
|
|
|
|
|
|
print "index 0 : <br>"; |
520
|
0
|
|
|
|
|
|
print Dumper $_[0]; |
521
|
0
|
|
|
|
|
|
print "<br>"; |
522
|
0
|
|
|
|
|
|
print "index 1 : <br>"; |
523
|
0
|
|
|
|
|
|
print Dumper $_[1]; |
524
|
0
|
|
|
|
|
|
print "<br>"; |
525
|
0
|
|
|
|
|
|
print "index 2 : <br>"; |
526
|
0
|
|
|
|
|
|
print Dumper $_[2]; |
527
|
0
|
|
|
|
|
|
print "<br>"; |
528
|
0
|
|
|
|
|
|
print "Attribute <br>"; |
529
|
0
|
|
|
|
|
|
print Dumper $attribute; |
530
|
0
|
|
|
|
|
|
print "<pre>"; |
531
|
0
|
|
|
|
|
|
print Dumper \@_; |
532
|
0
|
|
|
|
|
|
print "</pre>"; |
533
|
0
|
|
|
|
|
|
print "<br>"; |
534
|
0
|
|
|
|
|
|
print "<hr>"; |
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
# End of Subroutine for Test Module NKTIweb::DateTime |
537
|
|
|
|
|
|
|
# =========================================================================================================== |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
1; |
540
|
|
|
|
|
|
|
__END__ |
541
|
|
|
|
|
|
|
# |