1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System PHP Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
// ------------------------------------------------------------------------ |
12
|
|
|
|
13
|
|
|
if ( ! function_exists('timestamp')) { |
14
|
|
|
/** |
15
|
|
|
* Timestamp |
16
|
|
|
* |
17
|
|
|
* SQL Timestamp |
18
|
|
|
* |
19
|
|
|
* @param $timestamp |
20
|
|
|
* |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
function timestamp($timestamp = null) |
24
|
|
|
{ |
25
|
|
|
if ( ! isset($timestamp) OR $timestamp === 'NOW') { |
26
|
|
|
$timestamp = now(); |
27
|
|
|
} elseif (is_string($timestamp)) { |
28
|
|
|
$timestamp = strtotime($timestamp); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return date('Y-m-d H:i:s', $timestamp); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
// ------------------------------------------------------------------------ |
35
|
|
|
|
36
|
|
|
if ( ! function_exists('unix_timestamp')) { |
37
|
|
|
/** |
38
|
|
|
* Unix Timestamp |
39
|
|
|
* |
40
|
|
|
* SQL Unix Timestamp |
41
|
|
|
* |
42
|
|
|
* @param $timestamp |
43
|
|
|
* |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
function unix_timestamp($timestamp = null) |
47
|
|
|
{ |
48
|
|
|
if ( ! isset($timestamp) OR $timestamp === 'NOW') { |
49
|
|
|
return now(); |
50
|
|
|
} elseif (is_string($timestamp)) { |
51
|
|
|
return strtotime($timestamp); |
52
|
|
|
} elseif (is_numeric($timestamp)) { |
53
|
|
|
return $timestamp; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return now(); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// ------------------------------------------------------------------------ |
61
|
|
|
|
62
|
|
|
if ( ! function_exists('format_date')) { |
63
|
|
|
/** |
64
|
|
|
* Day Date Time Functions |
65
|
|
|
* |
66
|
|
|
* Returns string of day, date time or else, depend on type setting, with custom date separator and multi language |
67
|
|
|
* support |
68
|
|
|
* |
69
|
|
|
* Author : Steeven Andrian Salim |
70
|
|
|
* Email : [email protected] |
71
|
|
|
* URL : www.steevenz.com |
72
|
|
|
* Copyright (c) 2010 |
73
|
|
|
* |
74
|
|
|
* @access public |
75
|
|
|
* |
76
|
|
|
* @param string timezone |
|
|
|
|
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
function format_date($timestamp = null, $format = '%l, %d-%F-%Y %h:%i:%s %a') |
81
|
|
|
{ |
82
|
|
|
$timestamp = (is_null($timestamp) |
83
|
|
|
? now() |
84
|
|
|
: (is_numeric($timestamp) |
85
|
|
|
? $timestamp |
86
|
|
|
: strtotime( |
87
|
|
|
$timestamp |
88
|
|
|
))); |
89
|
|
|
$date = parse_date($timestamp); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$output = $format; |
92
|
|
|
|
93
|
|
|
foreach ($date as $replace => $value) { |
94
|
|
|
$output = str_ireplace('%' . $replace, $value, $output); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $output; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
// ------------------------------------------------------------------------ |
101
|
|
|
|
102
|
|
|
if ( ! function_exists('parse_date')) { |
103
|
|
|
/** |
104
|
|
|
* Parse Date into Array |
105
|
|
|
* |
106
|
|
|
* Simple function to take in a date format and return array of associated formats for each date element |
107
|
|
|
* |
108
|
|
|
* Author : Steeven Andrian Salim |
109
|
|
|
* Email : [email protected] |
110
|
|
|
* URL : www.steevenz.com |
111
|
|
|
* Copyright (c) 2010 |
112
|
|
|
* |
113
|
|
|
* |
114
|
|
|
* @access public |
115
|
|
|
* |
116
|
|
|
* @param numeric $timestamp |
|
|
|
|
117
|
|
|
* |
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
|
|
function parse_date($timestamp = null) |
121
|
|
|
{ |
122
|
|
|
$timestamp = (is_null($timestamp) |
123
|
|
|
? now() |
124
|
|
|
: (is_numeric($timestamp) |
|
|
|
|
125
|
|
|
? $timestamp |
126
|
|
|
: strtotime( |
127
|
|
|
$timestamp |
128
|
|
|
))); |
129
|
|
|
$date_parts = new \O2System\Spl\Datastructures\SplArrayObject( |
130
|
|
|
[ |
131
|
|
|
't' => $timestamp, |
132
|
|
|
'd' => date('d', $timestamp), |
133
|
|
|
'Y' => date('Y', $timestamp), |
134
|
|
|
'y' => date('y', $timestamp), |
135
|
|
|
'am' => time_meridiem($timestamp), |
|
|
|
|
136
|
|
|
'a' => date('a', $timestamp), |
137
|
|
|
'h' => date('h', $timestamp), |
138
|
|
|
'H' => date('H', $timestamp), |
139
|
|
|
'i' => date('i', $timestamp), |
140
|
|
|
's' => date('s', $timestamp), |
141
|
|
|
'w' => date('w', $timestamp), |
142
|
|
|
'l' => day_name($timestamp, 'l'), |
143
|
|
|
'm' => date('m', $timestamp), |
144
|
|
|
'n' => date('n', $timestamp), |
145
|
|
|
'F' => month_name($timestamp, 'F'), |
146
|
|
|
'M' => month_name($timestamp, 'M'), |
147
|
|
|
'e' => string_time_elapsed($timestamp), |
148
|
|
|
] |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
return $date_parts; |
|
|
|
|
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
// ------------------------------------------------------------------------ |
155
|
|
|
|
156
|
|
|
if ( ! function_exists('day_name')) { |
157
|
|
|
/** |
158
|
|
|
* Day Name in Languages |
159
|
|
|
* |
160
|
|
|
* @access public |
161
|
|
|
* |
162
|
|
|
* @param numeric |
163
|
|
|
* @param string |
164
|
|
|
* |
165
|
|
|
* @return array |
166
|
|
|
*/ |
167
|
|
|
function day_name($timestamp = null, $type = 'D') |
168
|
|
|
{ |
169
|
|
|
$timestamp = (is_null($timestamp) |
170
|
|
|
? now() |
171
|
|
|
: (is_numeric($timestamp) |
172
|
|
|
? $timestamp |
173
|
|
|
: strtotime( |
174
|
|
|
$timestamp |
175
|
|
|
))); |
176
|
|
|
|
177
|
|
|
language()->loadFile('calendar'); |
178
|
|
|
|
179
|
|
|
return language()->getLine(strtoupper('CAL_' . date($type, $timestamp))); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
// ------------------------------------------------------------------------ |
183
|
|
|
|
184
|
|
|
if ( ! function_exists('month_name')) { |
185
|
|
|
/** |
186
|
|
|
* Month Name in Languages |
187
|
|
|
* |
188
|
|
|
* @access public |
189
|
|
|
* |
190
|
|
|
* @param numeric |
191
|
|
|
* @param string |
192
|
|
|
* |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
function month_name($timestamp = null, $type = 'M') |
196
|
|
|
{ |
197
|
|
|
$timestamp = (is_null($timestamp) |
198
|
|
|
? now() |
199
|
|
|
: (is_numeric($timestamp) |
200
|
|
|
? $timestamp |
201
|
|
|
: strtotime( |
202
|
|
|
$timestamp |
203
|
|
|
))); |
204
|
|
|
language()->loadFile('calendar'); |
205
|
|
|
|
206
|
|
|
return language()->getLine(strtoupper('CAL_' . date($type, $timestamp))); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
// ------------------------------------------------------------------------ |
210
|
|
|
|
211
|
|
|
if ( ! function_exists('part_time')) { |
212
|
|
|
/** |
213
|
|
|
* Part Time in Languages |
214
|
|
|
* |
215
|
|
|
* Author : Steeven Andrian Salim |
216
|
|
|
* Email : [email protected] |
217
|
|
|
* URL : www.steevenz.com |
218
|
|
|
* Copyright (c) 2010 |
219
|
|
|
* |
220
|
|
|
* |
221
|
|
|
* @access public |
222
|
|
|
* |
223
|
|
|
* @param numeric $timestamp |
224
|
|
|
* @param string $lang |
225
|
|
|
* |
226
|
|
|
* @return array |
227
|
|
|
*/ |
228
|
|
|
function time_meridiem($timestamp = null) |
229
|
|
|
{ |
230
|
|
|
$timestamp = (is_null($timestamp) |
231
|
|
|
? now() |
232
|
|
|
: (is_numeric($timestamp) |
|
|
|
|
233
|
|
|
? $timestamp |
234
|
|
|
: strtotime( |
235
|
|
|
$timestamp |
236
|
|
|
))); |
237
|
|
|
$part_time_number = date('G', $timestamp); |
238
|
|
|
language()->loadFile('date'); |
239
|
|
|
|
240
|
|
|
if ($part_time_number >= 5 AND $part_time_number < 11) { |
241
|
|
|
return language()->getLine('DATE_MORNING'); |
242
|
|
|
} elseif ($part_time_number >= 11 AND $part_time_number < 15) { |
243
|
|
|
return language()->getLine('DATE_MORNING'); |
244
|
|
|
} elseif ($part_time_number >= 15 AND $part_time_number < 18) { |
245
|
|
|
return language()->getLine('DATE_DAYTIME'); |
246
|
|
|
} elseif ($part_time_number >= 18 AND $part_time_number < 19) { |
247
|
|
|
return language()->getLine('DATE_AFTERNOON'); |
248
|
|
|
} elseif ($part_time_number >= 19 AND $part_time_number < 24) { |
249
|
|
|
return language()->getLine('DATE_NIGHT'); |
250
|
|
|
} elseif ($part_time_number >= 24 AND $part_time_number < 5) { |
251
|
|
|
return language()->getLine('DATE_MIDNIGHT'); |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
// ------------------------------------------------------------------------ |
256
|
|
|
|
257
|
|
|
if ( ! function_exists('string_time_elapsed')) { |
258
|
|
|
/** |
259
|
|
|
* Day Date Time in String Format |
260
|
|
|
* |
261
|
|
|
* Returns String of Day date time |
262
|
|
|
* |
263
|
|
|
* @param integer $time Time |
264
|
|
|
* @param bool $full Full String |
265
|
|
|
* |
266
|
|
|
* @access public |
267
|
|
|
* @return string |
268
|
|
|
*/ |
269
|
|
|
function string_time_elapsed($time = null, $full = false) |
270
|
|
|
{ |
271
|
|
|
language()->loadFile('date'); |
272
|
|
|
|
273
|
|
|
$time = is_null($time) ? now() : $time; |
274
|
|
|
$time = is_numeric($time) ? $time : strtotime($time); |
|
|
|
|
275
|
|
|
|
276
|
|
|
$now = new DateTime; |
277
|
|
|
$ago = new DateTime(date('r', $time)); |
278
|
|
|
$diff = $now->diff($ago); |
279
|
|
|
|
280
|
|
|
$diff->w = floor($diff->d / 7); |
|
|
|
|
281
|
|
|
$diff->d -= $diff->w * 7; |
282
|
|
|
|
283
|
|
|
$string = [ |
284
|
|
|
'y' => language()->getLine('DATE_YEAR'), |
285
|
|
|
'm' => language()->getLine('DATE_MONTH'), |
286
|
|
|
'w' => language()->getLine('DATE_WEEK'), |
287
|
|
|
'd' => language()->getLine('DATE_DAY'), |
288
|
|
|
'h' => language()->getLine('DATE_HOUR'), |
289
|
|
|
'i' => language()->getLine('DATE_MINUTE'), |
290
|
|
|
's' => language()->getLine('DATE_SECOND'), |
291
|
|
|
]; |
292
|
|
|
|
293
|
|
|
foreach ($string as $key => &$value) { |
294
|
|
|
if ($diff->$key) { |
295
|
|
|
$value = $diff->$key . ' ' . $value . ($diff->$key > 1 && language()->getDefaultLocale() === 'en' ? 's' : ''); |
296
|
|
|
} else { |
297
|
|
|
unset($string[ $key ]); |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
if ( ! $full) { |
302
|
|
|
$string = array_slice($string, 0, 1); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
return $string ? implode(', ', |
306
|
|
|
$string) . ' ' . language()->getLine('DATE_AGO') : language()->getLine('DATE_JUST_NOW'); |
307
|
|
|
|
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
// ------------------------------------------------------------------------ |
312
|
|
|
|
313
|
|
|
if ( ! function_exists('dates_between')) { |
314
|
|
|
/** |
315
|
|
|
* Date Between |
316
|
|
|
* |
317
|
|
|
* Here is a simple function that gets all the dates between 2 given dates and returns an array (including the dates |
318
|
|
|
* specified) |
319
|
|
|
* |
320
|
|
|
* Example: dates_between('2001-12-28', '2002-01-01'); |
321
|
|
|
* |
322
|
|
|
* @param time|date $start_date Start Date |
323
|
|
|
* @param time|date $end_date End Date |
|
|
|
|
324
|
|
|
* |
325
|
|
|
* @return array |
326
|
|
|
*/ |
327
|
|
|
function dates_between($start_date, $end_date, $format = 'Y-m-d') |
328
|
|
|
{ |
329
|
|
|
$day = 60 * 60 * 24; |
330
|
|
|
$start_date = (! is_numeric($start_date) ? strtotime($start_date) : $start_date); |
|
|
|
|
331
|
|
|
$end_date = (! is_numeric($end_date) ? strtotime($end_date) : $end_date); |
|
|
|
|
332
|
|
|
|
333
|
|
|
$days_diff = round( |
334
|
|
|
($end_date - $start_date) / $day |
335
|
|
|
); // Unix time difference devided by 1 day to get total days in between |
336
|
|
|
|
337
|
|
|
$dates_array = []; |
338
|
|
|
|
339
|
|
|
if ($format == 'time') { |
340
|
|
|
$dates_array[] = $start_date; |
341
|
|
|
} else { |
342
|
|
|
$dates_array[] = date($format, $start_date); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
for ($x = 1; $x < $days_diff; $x++) { |
346
|
|
|
if ($format == 'time') { |
347
|
|
|
$dates_array[] = $start_date + ($day * $x); |
348
|
|
|
} else { |
349
|
|
|
$dates_array[] = date($format, ($start_date + ($day * $x))); |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
if ($format == 'time') { |
354
|
|
|
$dates_array[] = $end_date; |
355
|
|
|
} else { |
356
|
|
|
$dates_array[] = date($format, $end_date); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
return $dates_array; |
360
|
|
|
} |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
// ------------------------------------------------------------------------ |
364
|
|
|
|
365
|
|
|
if ( ! function_exists('time_range')) { |
366
|
|
|
/** |
367
|
|
|
* Time Range List |
368
|
|
|
* |
369
|
|
|
* Returns Array of Time Range Options in 15 Minutes Step |
370
|
|
|
* |
371
|
|
|
* @param int $mode 12|24 Hour Mode |
372
|
|
|
* @param int $step Minutes Step |
373
|
|
|
* |
374
|
|
|
* @return array |
375
|
|
|
*/ |
376
|
|
|
function time_range($mode = 24, $step = 15) |
377
|
|
|
{ |
378
|
|
|
$time = []; |
379
|
|
|
$minutes = range(0, (60 - $step), $step); |
380
|
|
|
for ($i = 0; $i <= 23; $i++) { |
381
|
|
|
$hour = (strlen($i) == 1 ? '0' . $i : $i); |
382
|
|
|
foreach ($minutes as $minute) { |
383
|
|
|
$hours = $hour . ':' . (strlen($minute) == 1 ? '0' . $minute : $minute); |
384
|
|
|
$time_12 = date("h:i a", strtotime($hours)); |
385
|
|
|
$time_24 = $hours; |
386
|
|
|
if ($mode == 12) { |
387
|
|
|
$time[ $time_12 ] = $time_12; |
388
|
|
|
} elseif ($mode == 24) { |
389
|
|
|
$time[ $time_24 ] = $time_24; |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
return $time; |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
// ------------------------------------------------------------------------ |
399
|
|
|
|
400
|
|
|
if ( ! function_exists('calculate_days')) { |
401
|
|
|
/** |
402
|
|
|
* calculate_days |
403
|
|
|
* |
404
|
|
|
* Returns amount of weeks |
405
|
|
|
* |
406
|
|
|
* @param time|date $start_date Start Date |
407
|
|
|
* @param time|date $end_date End Date |
408
|
|
|
* @param hour $hour Hour |
|
|
|
|
409
|
|
|
* |
410
|
|
|
* @return int |
411
|
|
|
*/ |
412
|
|
|
function calculate_days($start_date, $end_date, $hour = '12:00:00 am') |
413
|
|
|
{ |
414
|
|
|
$start_date = (is_numeric($start_date) ? date('d-m-Y', $start_date) : $start_date); |
|
|
|
|
415
|
|
|
$end_date = (is_numeric($end_date) ? date('d-m-Y', $end_date) : $end_date); |
|
|
|
|
416
|
|
|
$hour = (is_numeric($hour) ? date('h:i:s a', $hour) : $hour); |
|
|
|
|
417
|
|
|
|
418
|
|
|
$start_date = $start_date . ' ' . $hour; |
419
|
|
|
$end_date = $end_date . ' ' . $hour; |
420
|
|
|
|
421
|
|
|
$start_date = strtotime($start_date); |
422
|
|
|
$end_date = strtotime($end_date); |
423
|
|
|
|
424
|
|
|
$hours = 24 * 60 * 60; // Hours in a day |
425
|
|
|
$time = $end_date - $start_date; |
426
|
|
|
|
427
|
|
|
return round($time / $hours); |
428
|
|
|
} |
429
|
|
|
} |
430
|
|
|
// ------------------------------------------------------------------------ |
431
|
|
|
|
432
|
|
|
if ( ! function_exists('calculate_weeks')) { |
433
|
|
|
/** |
434
|
|
|
* calculate_weeks |
435
|
|
|
* |
436
|
|
|
* Returns amount of weeks |
437
|
|
|
* |
438
|
|
|
* @param time|date $start_date Start Date |
439
|
|
|
* @param time|date $end_date End Date |
440
|
|
|
* @param hour $hour Hour |
441
|
|
|
* |
442
|
|
|
* @return int |
443
|
|
|
*/ |
444
|
|
|
function calculate_weeks($start_date, $end_date, $hour = '12:00:00 am') |
445
|
|
|
{ |
446
|
|
|
$start_date = (is_numeric($start_date) ? date('d-m-Y', $start_date) : $start_date); |
|
|
|
|
447
|
|
|
$end_date = (is_numeric($end_date) ? date('d-m-Y', $end_date) : $end_date); |
|
|
|
|
448
|
|
|
$hour = (is_numeric($hour) ? date('h:i:s a', $hour) : $hour); |
|
|
|
|
449
|
|
|
|
450
|
|
|
$start_date = $start_date . ' ' . $hour; |
451
|
|
|
$end_date = $end_date . ' ' . $hour; |
452
|
|
|
|
453
|
|
|
$start_date = strtotime($start_date); |
454
|
|
|
$end_date = strtotime($end_date); |
455
|
|
|
|
456
|
|
|
$hours = 24 * 60 * 60 * 7; // Hours in a day |
457
|
|
|
$time = $end_date - $start_date; |
458
|
|
|
|
459
|
|
|
return floor($time / $hours); |
460
|
|
|
} |
461
|
|
|
} |
462
|
|
|
// ------------------------------------------------------------------------ |
463
|
|
|
|
464
|
|
|
if ( ! function_exists('is_weekend')) { |
465
|
|
|
/** |
466
|
|
|
* Is Weekend |
467
|
|
|
* |
468
|
|
|
* Validate is the date is a weekend |
469
|
|
|
* |
470
|
|
|
* @param date|time $date Date |
471
|
|
|
* |
472
|
|
|
* @return bool |
473
|
|
|
*/ |
474
|
|
|
function is_weekend($date) |
475
|
|
|
{ |
476
|
|
|
$date = (! is_numeric($date) ? strtotime(str_replace('/', '-', $date)) : $date); |
|
|
|
|
477
|
|
|
$date = date('D', $date); |
478
|
|
|
|
479
|
|
|
if ($date == 'Sat' OR $date == 'Sun') { |
480
|
|
|
return true; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
return false; |
484
|
|
|
} |
485
|
|
|
} |
486
|
|
|
// ------------------------------------------------------------------------ |
487
|
|
|
|
488
|
|
|
if ( ! function_exists('is_weekday')) { |
489
|
|
|
/** |
490
|
|
|
* Is Week Day |
491
|
|
|
* |
492
|
|
|
* Validate is the date is a week day |
493
|
|
|
* |
494
|
|
|
* @param date|time $date Date |
495
|
|
|
* |
496
|
|
|
* @return bool |
497
|
|
|
*/ |
498
|
|
|
function is_weekday($date) |
499
|
|
|
{ |
500
|
|
|
$date = (! is_numeric($date) ? strtotime(str_replace('/', '-', $date)) : $date); |
|
|
|
|
501
|
|
|
$date = date('D', $date); |
502
|
|
|
|
503
|
|
|
if ( ! in_array($date, ['Sat', 'Sun'])) { |
504
|
|
|
return true; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
return false; |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
// ------------------------------------------------------------------------ |
511
|
|
|
|
512
|
|
|
if ( ! function_exists('get_age')) { |
513
|
|
|
/** |
514
|
|
|
* Get Age |
515
|
|
|
* |
516
|
|
|
* Gets the age of an individual |
517
|
|
|
* |
518
|
|
|
* @param date|time $birthday |
519
|
|
|
* @param string $return Return value days|months|years |
520
|
|
|
* |
521
|
|
|
* @return int |
522
|
|
|
*/ |
523
|
|
|
function get_age($birthday, $return = 'years') |
524
|
|
|
{ |
525
|
|
|
$birthday = (! is_numeric($birthday) ? strtotime(str_replace('/', '-', $birthday)) : $birthday); |
|
|
|
|
526
|
|
|
|
527
|
|
|
$birthday = new DateTime(date('Y-m-d', $birthday)); |
528
|
|
|
$now = new DateTime(date('Y-m-d')); |
529
|
|
|
$interval = $birthday->diff($now); |
530
|
|
|
|
531
|
|
|
$available = [ |
532
|
|
|
'years' => 'y', |
533
|
|
|
'months' => 'm', |
534
|
|
|
'hours' => 'h', |
535
|
|
|
'minutes' => 'i', |
536
|
|
|
'seconds' => 's', |
537
|
|
|
]; |
538
|
|
|
|
539
|
|
|
if (array_key_exists($return, $available)) { |
540
|
|
|
return $interval->{$available[ $return ]}; |
541
|
|
|
} elseif (isset($interval->{$return})) { |
542
|
|
|
return $interval->{$return}; |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
return $interval; |
|
|
|
|
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
// ------------------------------------------------------------------------ |
549
|
|
|
|
550
|
|
|
if ( ! function_exists('get_tenure')) { |
551
|
|
|
/** |
552
|
|
|
* get_tenure |
553
|
|
|
* |
554
|
|
|
* Gets tenure from start date and end date |
555
|
|
|
* |
556
|
|
|
* @param date|time $date_start |
557
|
|
|
* @param date|time|null $date_end |
558
|
|
|
* |
559
|
|
|
* @return string |
560
|
|
|
*/ |
561
|
|
|
function get_tenure($date_start, $date_end = null) |
562
|
|
|
{ |
563
|
|
|
language()->loadFile('date'); |
564
|
|
|
|
565
|
|
|
$date_start = new \DateTime($date_start); |
566
|
|
|
|
567
|
|
|
if (empty($date_end)) { |
568
|
|
|
$date_end = new \DateTime($date_end); |
569
|
|
|
} else { |
570
|
|
|
$date_end = new DateTime(date('Y-m-d')); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
$dateInterval = $date_start->diff($date_end); |
574
|
|
|
|
575
|
|
|
return strtolower($dateInterval->format( |
576
|
|
|
'%y ' . language()->getLine('DATE_YEARS') . |
577
|
|
|
' — %m ' . language()->getLine('DATE_MONTHS') . |
578
|
|
|
' — %d ' . language()->getLine('DATE_DAYS'))); |
579
|
|
|
} |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
// ------------------------------------------------------------------------ |
583
|
|
|
|
584
|
|
|
if ( ! function_exists('time_breakdown')) { |
585
|
|
|
/** |
586
|
|
|
* Time Breakdown |
587
|
|
|
* |
588
|
|
|
* Breaksdown a timestamp into an array of days, months, etc since the current time |
589
|
|
|
* |
590
|
|
|
* @param int $time |
591
|
|
|
* |
592
|
|
|
* @return array |
593
|
|
|
*/ |
594
|
|
|
function time_breakdown($time) |
595
|
|
|
{ |
596
|
|
|
if ( ! is_numeric($time)) { |
|
|
|
|
597
|
|
|
$time = strtotime($time); |
598
|
|
|
} |
599
|
|
|
$currentTime = time(); |
600
|
|
|
$periods = [ |
601
|
|
|
'years' => 31556926, |
602
|
|
|
'months' => 2629743, |
603
|
|
|
'weeks' => 604800, |
604
|
|
|
'days' => 86400, |
605
|
|
|
'hours' => 3600, |
606
|
|
|
'minutes' => 60, |
607
|
|
|
'seconds' => 1, |
608
|
|
|
]; |
609
|
|
|
$durations = [ |
610
|
|
|
'years' => 0, |
611
|
|
|
'months' => 0, |
612
|
|
|
'weeks' => 0, |
613
|
|
|
'days' => 0, |
614
|
|
|
'hours' => 0, |
615
|
|
|
'minutes' => 0, |
616
|
|
|
'seconds' => 0, |
617
|
|
|
]; |
618
|
|
|
if ($time) { |
619
|
|
|
$seconds = $currentTime - $time; |
620
|
|
|
if ($seconds <= 0) { |
621
|
|
|
return $durations; |
622
|
|
|
} |
623
|
|
|
foreach ($periods as $period => $seconds_in_period) { |
624
|
|
|
if ($seconds >= $seconds_in_period) { |
625
|
|
|
$durations[ $period ] = floor($seconds / $seconds_in_period); |
626
|
|
|
$seconds -= $durations[ $period ] * $seconds_in_period; |
627
|
|
|
} |
628
|
|
|
} |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
return $durations; |
632
|
|
|
} |
633
|
|
|
} |
634
|
|
|
// ------------------------------------------------------------------------ |
635
|
|
|
|
636
|
|
|
if ( ! function_exists('sec2hms')) { |
637
|
|
|
/** |
638
|
|
|
* Second to Miliseconds |
639
|
|
|
* |
640
|
|
|
* @param $num_secs |
641
|
|
|
* |
642
|
|
|
* @return string |
643
|
|
|
*/ |
644
|
|
|
function sec2hms($num_secs) |
645
|
|
|
{ |
646
|
|
|
$str = ''; |
647
|
|
|
$hours = intval(intval($num_secs) / 3600); |
648
|
|
|
$str .= $hours . ':'; |
649
|
|
|
$minutes = intval(((intval($num_secs) / 60) % 60)); |
650
|
|
|
if ($minutes < 10) { |
651
|
|
|
$str .= '0'; |
652
|
|
|
} |
653
|
|
|
$str .= $minutes . ':'; |
654
|
|
|
$seconds = intval(intval(($num_secs % 60))); |
655
|
|
|
if ($seconds < 10) { |
656
|
|
|
$str .= '0'; |
657
|
|
|
} |
658
|
|
|
$str .= $seconds; |
659
|
|
|
|
660
|
|
|
return $str; |
661
|
|
|
} |
662
|
|
|
} |
663
|
|
|
// ------------------------------------------------------------------------ |
664
|
|
|
|
665
|
|
|
if ( ! function_exists('add_time_duration')) { |
666
|
|
|
/** |
667
|
|
|
* Add Time Duration |
668
|
|
|
* |
669
|
|
|
* @param time|date $start_time Time or Date |
670
|
|
|
* @param int $duration |
671
|
|
|
* @param string $return Return value|date |
672
|
|
|
* |
673
|
|
|
* @return mixed |
674
|
|
|
*/ |
675
|
|
|
function add_time_duration($start_time, $duration, $return = 'time') |
676
|
|
|
{ |
677
|
|
|
$start_time = (! is_numeric($start_time) ? strtotime($start_time) : $start_time); |
|
|
|
|
678
|
|
|
$duration = $duration * 60 * 60; // (x) hours * 60 minutes * 60 seconds |
679
|
|
|
|
680
|
|
|
$add_time = $start_time + $duration; |
681
|
|
|
|
682
|
|
|
if ($return === 'time') { |
683
|
|
|
return $add_time; |
684
|
|
|
} else { |
685
|
|
|
return format_date($add_time, $return); |
686
|
|
|
} |
687
|
|
|
} |
688
|
|
|
} |
689
|
|
|
// ------------------------------------------------------------------------ |
690
|
|
|
|
691
|
|
|
if ( ! function_exists('calculate_hours')) { |
692
|
|
|
/** |
693
|
|
|
* Calculate Hours |
694
|
|
|
* |
695
|
|
|
* @param time|date $start_time Time or Date |
696
|
|
|
* @param time|date $end_time Time or Date |
697
|
|
|
* @param string $return Return value time|hours |
698
|
|
|
* |
699
|
|
|
* @return mixed |
700
|
|
|
*/ |
701
|
|
|
function calculate_hours($start_time, $end_time, $return = 'time') |
702
|
|
|
{ |
703
|
|
|
$start_time = (! is_numeric($start_time) ? strtotime($start_time) : $start_time); |
|
|
|
|
704
|
|
|
$end_time = (! is_numeric($end_time) ? strtotime($end_time) : $end_time); |
|
|
|
|
705
|
|
|
|
706
|
|
|
// Times Difference |
707
|
|
|
$difference = $end_time - $start_time; |
708
|
|
|
|
709
|
|
|
// Hours |
710
|
|
|
$hours = $difference / 3600; |
711
|
|
|
|
712
|
|
|
// Minutes |
713
|
|
|
$minutes = ($hours - floor($hours)) * 60; |
714
|
|
|
|
715
|
|
|
$hours = ($minutes != 0 ? $hours - 1 : $hours); |
716
|
|
|
|
717
|
|
|
// Final |
718
|
|
|
$final_hours = round($hours, 0); |
719
|
|
|
$final_minutes = round($minutes); |
720
|
|
|
|
721
|
|
|
if ($return === 'time') { |
722
|
|
|
$final_hours = ($final_hours < 10 ? '0' . $final_hours : $final_hours); |
723
|
|
|
$final_minutes = ($final_minutes < 10 ? '0' . $final_minutes : $final_minutes); |
724
|
|
|
|
725
|
|
|
return $final_hours . ':' . $final_minutes; |
726
|
|
|
} elseif ($return === 'hours') { |
727
|
|
|
return $final_hours + ($final_minutes / 60); |
728
|
|
|
} |
729
|
|
|
} |
730
|
|
|
} |
731
|
|
|
// ------------------------------------------------------------------------ |
732
|
|
|
|
733
|
|
|
if ( ! function_exists('time_difference')) { |
734
|
|
|
/** |
735
|
|
|
* Time Difference |
736
|
|
|
* |
737
|
|
|
* @param time|date $start_time Time or Date |
738
|
|
|
* @param time|date $end_time Time or Date |
739
|
|
|
* @param string $return Return value array|object |
740
|
|
|
* |
741
|
|
|
* @return mixed |
742
|
|
|
*/ |
743
|
|
|
function time_difference($start_time, $end_time, $return = 'array') |
744
|
|
|
{ |
745
|
|
|
$start_time = (! is_numeric($start_time) ? strtotime($start_time) : $start_time); |
|
|
|
|
746
|
|
|
$end_time = (! is_numeric($end_time) ? strtotime($end_time) : $end_time); |
|
|
|
|
747
|
|
|
|
748
|
|
|
// Times Difference |
749
|
|
|
$difference = $end_time - $start_time; |
750
|
|
|
$result = format_time(abs($difference)); |
751
|
|
|
|
752
|
|
|
if ($return == 'array') { |
753
|
|
|
return $result; |
754
|
|
|
} else { |
755
|
|
|
return implode(':', $result); |
|
|
|
|
756
|
|
|
} |
757
|
|
|
} |
758
|
|
|
} |
759
|
|
|
// ------------------------------------------------------------------------ |
760
|
|
|
|
761
|
|
|
if ( ! function_exists('weeks_in_month')) { |
762
|
|
|
/** |
763
|
|
|
* @param null $month |
|
|
|
|
764
|
|
|
* @param null $year |
|
|
|
|
765
|
|
|
* |
766
|
|
|
* @return int |
767
|
|
|
*/ |
768
|
|
|
function weeks_in_month($month = null, $year = null) |
769
|
|
|
{ |
770
|
|
|
// Start Date in Month |
771
|
|
|
$start_date_month = mktime(0, 0, 0, $month, 1, $year); |
772
|
|
|
$start_week_month = (int)date('W', $start_date_month); |
773
|
|
|
|
774
|
|
|
$amount_day = days_in_month($month, $year); |
775
|
|
|
|
776
|
|
|
// Finish Date in onth |
777
|
|
|
$finish_date_month = mktime(0, 0, 0, $month, $amount_day, $year); |
778
|
|
|
$finish_week_month = (int)date('W', $finish_date_month); |
779
|
|
|
|
780
|
|
|
$amount_week = $finish_week_month - $start_week_month + 1; |
781
|
|
|
|
782
|
|
|
return $amount_week; |
783
|
|
|
} |
784
|
|
|
} |
785
|
|
|
// ------------------------------------------------------------------------ |
786
|
|
|
|
787
|
|
|
if ( ! function_exists('monday_of_week')) { |
788
|
|
|
/** |
789
|
|
|
* Monday of Week |
790
|
|
|
* |
791
|
|
|
* @param $week_number |
792
|
|
|
* @param $year |
793
|
|
|
* |
794
|
|
|
* @return int |
795
|
|
|
*/ |
796
|
|
|
function monday_of_week($week_number, $year = null) |
797
|
|
|
{ |
798
|
|
|
$year = is_null($year) ? date('Y') : $year; |
799
|
|
|
|
800
|
|
|
$new_year_date = mktime(0, 0, 0, 1, 1, $year); |
|
|
|
|
801
|
|
|
$first_monday_date = 7 + 1 - date("w", mktime(0, 0, 0, 1, 1, $year)); |
802
|
|
|
$dates_from_first_monday = 7 * $week_number; |
803
|
|
|
$second_from_first_monday = 60 * 60 * 24 * ($first_monday_date + $dates_from_first_monday); |
804
|
|
|
$monday_day_of_week = $new_year_date + $second_from_first_monday; |
805
|
|
|
$date_of_monday_day_of_week = 0 + date("j", $monday_day_of_week); |
806
|
|
|
|
807
|
|
|
return $date_of_monday_day_of_week; |
808
|
|
|
} |
809
|
|
|
} |
810
|
|
|
// ------------------------------------------------------------------------ |
811
|
|
|
|
812
|
|
|
if ( ! function_exists('week_number_of_month')) { |
813
|
|
|
/** |
814
|
|
|
* Week Number of Month |
815
|
|
|
* |
816
|
|
|
* @param int|null $date Date Number |
817
|
|
|
* @param int|null $month Month Number |
818
|
|
|
* @param int|null $year Year Number |
819
|
|
|
* |
820
|
|
|
* @return int |
821
|
|
|
*/ |
822
|
|
|
function week_number_of_month($date = null, $month = null, $year = null) |
823
|
|
|
{ |
824
|
|
|
$month = is_null($month) ? date('m') : $month; |
825
|
|
|
$year = is_null($year) ? date('Y') : $year; |
826
|
|
|
|
827
|
|
|
// Start Date in Month |
828
|
|
|
$start_date_month = mktime(0, 0, 0, $month, 1, $year); |
|
|
|
|
829
|
|
|
$start_week_month = (int)date('W', $start_date_month); |
830
|
|
|
|
831
|
|
|
// Date Search |
832
|
|
|
$date_search = mktime(0, 0, 0, $month, $date, $year); |
833
|
|
|
$date_week_search = (int)date('W', $date_search); |
834
|
|
|
|
835
|
|
|
$number_of_week = $date_week_search - $start_week_month + 1; |
836
|
|
|
|
837
|
|
|
return $number_of_week; |
838
|
|
|
} |
839
|
|
|
} |
840
|
|
|
// ------------------------------------------------------------------------ |
841
|
|
|
|
842
|
|
|
if ( ! function_exists('format_time')) { |
843
|
|
|
/** |
844
|
|
|
* Format Time from seconds |
845
|
|
|
* |
846
|
|
|
* @param int |
847
|
|
|
* @param numeric (for decimal) |
|
|
|
|
848
|
|
|
* |
849
|
|
|
* @return ArrayObject |
850
|
|
|
*/ |
851
|
|
|
function format_time($seconds) |
852
|
|
|
{ |
853
|
|
|
@$days = floor($seconds / 86400); |
854
|
|
|
if ($days > 0) { |
855
|
|
|
$seconds -= $days * 86400; |
856
|
|
|
} |
857
|
|
|
|
858
|
|
|
@$years = floor($days / 365); |
859
|
|
|
@$months = floor($days / 30); |
860
|
|
|
|
861
|
|
|
@$hours = floor($seconds / 3600); |
862
|
|
|
if ($days > 0 || $hours > 0) { |
863
|
|
|
$seconds -= $hours * 3600; |
864
|
|
|
} |
865
|
|
|
|
866
|
|
|
@$minutes = floor($seconds / 60); |
867
|
|
|
if ($days > 0 || $hours > 0 || $minutes > 0) { |
868
|
|
|
$seconds -= $minutes * 60; |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
$format[ 'days' ] = $days; |
|
|
|
|
872
|
|
|
$format[ 'years' ] = $years; |
873
|
|
|
$format[ 'months' ] = $months; |
874
|
|
|
$format[ 'hours' ] = $hours; |
875
|
|
|
$format[ 'minutes' ] = $minutes; |
876
|
|
|
$format[ 'seconds' ] = $seconds; |
877
|
|
|
|
878
|
|
|
return new \O2System\Spl\Datastructures\SplArrayObject($format); |
879
|
|
|
} |
880
|
|
|
} |
881
|
|
|
|
882
|
|
|
/** |
883
|
|
|
* CodeIgniter |
884
|
|
|
* |
885
|
|
|
* An open source application development framework for PHP |
886
|
|
|
* |
887
|
|
|
* This content is released under the MIT License (MIT) |
888
|
|
|
* |
889
|
|
|
* Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
890
|
|
|
* |
891
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
892
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
893
|
|
|
* in the Software without restriction, including without limitation the rights |
894
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
895
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
896
|
|
|
* furnished to do so, subject to the following conditions: |
897
|
|
|
* |
898
|
|
|
* The above copyright notice and this permission notice shall be included in |
899
|
|
|
* all copies or substantial portions of the Software. |
900
|
|
|
* |
901
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
902
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
903
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
904
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
905
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
906
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
907
|
|
|
* THE SOFTWARE. |
908
|
|
|
* |
909
|
|
|
* @package CodeIgniter |
910
|
|
|
* @author EllisLab Dev Team |
911
|
|
|
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
912
|
|
|
* @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
913
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
914
|
|
|
* @link http://codeigniter.com |
915
|
|
|
* @since Version 1.0.0 |
916
|
|
|
* @filesource |
917
|
|
|
*/ |
918
|
|
|
|
919
|
|
|
/** |
920
|
|
|
* CodeIgniter Date Helpers |
921
|
|
|
* |
922
|
|
|
* @package CodeIgniter |
923
|
|
|
* @subpackage Helpers |
924
|
|
|
* @category Helpers |
925
|
|
|
* @author EllisLab Dev Team |
926
|
|
|
* @link http://codeigniter.com/user_guide/helpers/date_helper.html |
927
|
|
|
*/ |
928
|
|
|
|
929
|
|
|
// ------------------------------------------------------------------------ |
930
|
|
|
|
931
|
|
|
if ( ! function_exists('now')) { |
932
|
|
|
/** |
933
|
|
|
* now |
934
|
|
|
* |
935
|
|
|
* Get "now" time |
936
|
|
|
* |
937
|
|
|
* Returns time() based on the timezone parameter or on the |
938
|
|
|
* "time_reference" setting |
939
|
|
|
* |
940
|
|
|
* @param $timezone string |
941
|
|
|
* |
942
|
|
|
* @return int |
943
|
|
|
*/ |
944
|
|
|
function now($timezone = null) |
945
|
|
|
{ |
946
|
|
|
if (empty($timezone)) { |
947
|
|
|
$timezone = config()->getItem('datetime')->timezone; |
|
|
|
|
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
if ($timezone === 'local' OR $timezone === date_default_timezone_get()) { |
951
|
|
|
return time(); |
952
|
|
|
} |
953
|
|
|
|
954
|
|
|
$datetime = new DateTime('now', new DateTimeZone($timezone)); |
955
|
|
|
sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second); |
|
|
|
|
956
|
|
|
|
957
|
|
|
return mktime($hour, $minute, $second, $month, $day, $year); |
958
|
|
|
} |
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
// ------------------------------------------------------------------------ |
962
|
|
|
|
963
|
|
|
if ( ! function_exists('mdate')) { |
964
|
|
|
/** |
965
|
|
|
* Convert MySQL Style Datecodes |
966
|
|
|
* |
967
|
|
|
* This function is identical to PHPs date() function, |
968
|
|
|
* except that it allows date codes to be formatted using |
969
|
|
|
* the MySQL style, where each code letter is preceded |
970
|
|
|
* with a percent sign: %Y %m %d etc... |
971
|
|
|
* |
972
|
|
|
* The benefit of doing dates this way is that you don't |
973
|
|
|
* have to worry about escaping your text letters that |
974
|
|
|
* match the date codes. |
975
|
|
|
* |
976
|
|
|
* @param string |
977
|
|
|
* @param int |
978
|
|
|
* |
979
|
|
|
* @return int |
980
|
|
|
*/ |
981
|
|
|
function mdate($date = '', $time = '') |
982
|
|
|
{ |
983
|
|
|
if ($date === '') { |
984
|
|
|
return ''; |
|
|
|
|
985
|
|
|
} elseif (empty($time)) { |
986
|
|
|
$time = now(); |
987
|
|
|
} |
988
|
|
|
|
989
|
|
|
$date = str_replace( |
990
|
|
|
'%\\', |
991
|
|
|
'', |
992
|
|
|
preg_replace('/([a-z]+?){1}/i', '\\\\\\1', $date) |
993
|
|
|
); |
994
|
|
|
|
995
|
|
|
return date($date, $time); |
|
|
|
|
996
|
|
|
} |
997
|
|
|
} |
998
|
|
|
|
999
|
|
|
// ------------------------------------------------------------------------ |
1000
|
|
|
|
1001
|
|
|
if ( ! function_exists('standard_date')) { |
1002
|
|
|
/** |
1003
|
|
|
* Standard Date |
1004
|
|
|
* |
1005
|
|
|
* Returns a date formatted according to the submitted standard. |
1006
|
|
|
* |
1007
|
|
|
* As of PHP 5.2, the DateTime extension provides constants that |
1008
|
|
|
* serve for the exact same purpose and are used with date(). |
1009
|
|
|
* |
1010
|
|
|
* @todo Remove in version 3.1+. |
1011
|
|
|
* @deprecated 3.0.0 Use PHP's native date() instead. |
1012
|
|
|
* @link http://www.php.net/manual/en/class.datetime.php#datetime.constants.types |
1013
|
|
|
* |
1014
|
|
|
* @example date(DATE_RFC822, now()); // default |
1015
|
|
|
* @example date(DATE_W3C, $time); // a different format and time |
1016
|
|
|
* |
1017
|
|
|
* @param string $fmt = 'DATE_RFC822' the chosen format |
1018
|
|
|
* @param int $time = NULL Unix timestamp |
1019
|
|
|
* |
1020
|
|
|
* @return string |
1021
|
|
|
*/ |
1022
|
|
|
function standard_date($fmt = 'DATE_RFC822', $time = null) |
1023
|
|
|
{ |
1024
|
|
|
if (empty($time)) { |
1025
|
|
|
$time = now(); |
1026
|
|
|
} |
1027
|
|
|
|
1028
|
|
|
// Procedural style pre-defined constants from the DateTime extension |
1029
|
|
|
if (strpos($fmt, 'DATE_') !== 0 OR defined($fmt) === false) { |
1030
|
|
|
return false; |
|
|
|
|
1031
|
|
|
} |
1032
|
|
|
|
1033
|
|
|
return date(constant($fmt), $time); |
1034
|
|
|
} |
1035
|
|
|
} |
1036
|
|
|
|
1037
|
|
|
// ------------------------------------------------------------------------ |
1038
|
|
|
|
1039
|
|
|
if ( ! function_exists('timespan')) { |
1040
|
|
|
/** |
1041
|
|
|
* Timespan |
1042
|
|
|
* |
1043
|
|
|
* Returns a span of seconds in this format: |
1044
|
|
|
* 10 days 14 hours 36 minutes 47 seconds |
1045
|
|
|
* |
1046
|
|
|
* @param int a number of seconds |
1047
|
|
|
* @param int Unix timestamp |
1048
|
|
|
* @param int a number of display units |
1049
|
|
|
* |
1050
|
|
|
* @return string |
1051
|
|
|
*/ |
1052
|
|
|
function timespan($seconds = 1, $time = '', $units = 7) |
1053
|
|
|
{ |
1054
|
|
|
language()->loadFile('date'); |
1055
|
|
|
|
1056
|
|
|
is_numeric($seconds) OR $seconds = 1; |
1057
|
|
|
is_numeric($time) OR $time = time(); |
1058
|
|
|
is_numeric($units) OR $units = 7; |
1059
|
|
|
|
1060
|
|
|
$seconds = ($time <= $seconds) ? 1 : $time - $seconds; |
1061
|
|
|
|
1062
|
|
|
$str = []; |
1063
|
|
|
$years = floor($seconds / 31557600); |
1064
|
|
|
|
1065
|
|
|
if ($years > 0) { |
1066
|
|
|
$str[] = $years . ' ' . language()->getLine($years > 1 ? 'DATE_YEARS' : 'DATE_YEAR'); |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
$seconds -= $years * 31557600; |
1070
|
|
|
$months = floor($seconds / 2629743); |
1071
|
|
|
|
1072
|
|
|
if (count($str) < $units && ($years > 0 OR $months > 0)) { |
1073
|
|
|
if ($months > 0) { |
1074
|
|
|
$str[] = $months . ' ' . language()->getLine($months > 1 ? 'DATE_MONTHS' : 'DATE_MONTH'); |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
$seconds -= $months * 2629743; |
1078
|
|
|
} |
1079
|
|
|
|
1080
|
|
|
$weeks = floor($seconds / 604800); |
1081
|
|
|
|
1082
|
|
|
if (count($str) < $units && ($years > 0 OR $months > 0 OR $weeks > 0)) { |
1083
|
|
|
if ($weeks > 0) { |
1084
|
|
|
$str[] = $weeks . ' ' . language()->getLine($weeks > 1 ? 'DATE_WEEKS' : 'DATE_WEEK'); |
1085
|
|
|
} |
1086
|
|
|
|
1087
|
|
|
$seconds -= $weeks * 604800; |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
$days = floor($seconds / 86400); |
1091
|
|
|
|
1092
|
|
|
if (count($str) < $units && ($months > 0 OR $weeks > 0 OR $days > 0)) { |
1093
|
|
|
if ($days > 0) { |
1094
|
|
|
$str[] = $days . ' ' . language()->getLine($days > 1 ? 'DATE_DAYS' : 'DATE_DAY'); |
1095
|
|
|
} |
1096
|
|
|
|
1097
|
|
|
$seconds -= $days * 86400; |
1098
|
|
|
} |
1099
|
|
|
|
1100
|
|
|
$hours = floor($seconds / 3600); |
1101
|
|
|
|
1102
|
|
|
if (count($str) < $units && ($days > 0 OR $hours > 0)) { |
1103
|
|
|
if ($hours > 0) { |
1104
|
|
|
$str[] = $hours . ' ' . language()->getLine($hours > 1 ? 'DATE_HOURS' : 'DATE_HOUR'); |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
$seconds -= $hours * 3600; |
1108
|
|
|
} |
1109
|
|
|
|
1110
|
|
|
$minutes = floor($seconds / 60); |
1111
|
|
|
|
1112
|
|
|
if (count($str) < $units && ($days > 0 OR $hours > 0 OR $minutes > 0)) { |
1113
|
|
|
if ($minutes > 0) { |
1114
|
|
|
$str[] = $minutes . ' ' . language()->getLine($minutes > 1 ? 'DATE_MINUTES' : 'DATE_MINUTE'); |
1115
|
|
|
} |
1116
|
|
|
|
1117
|
|
|
$seconds -= $minutes * 60; |
1118
|
|
|
} |
1119
|
|
|
|
1120
|
|
|
if (count($str) === 0) { |
1121
|
|
|
$str[] = $seconds . ' ' . language()->getLine($seconds > 1 ? 'DATE_SECONDS' : 'DATE_SECOND'); |
1122
|
|
|
} |
1123
|
|
|
|
1124
|
|
|
return implode(', ', $str); |
1125
|
|
|
} |
1126
|
|
|
} |
1127
|
|
|
|
1128
|
|
|
// ------------------------------------------------------------------------ |
1129
|
|
|
|
1130
|
|
|
if ( ! function_exists('days_in_month')) { |
1131
|
|
|
/** |
1132
|
|
|
* Number of days in a month |
1133
|
|
|
* |
1134
|
|
|
* Takes a month/year as input and returns the number of days |
1135
|
|
|
* for the given month/year. Takes leap years into consideration. |
1136
|
|
|
* |
1137
|
|
|
* @param int a numeric month |
1138
|
|
|
* @param int a numeric year |
1139
|
|
|
* |
1140
|
|
|
* @return int |
1141
|
|
|
*/ |
1142
|
|
|
function days_in_month($month = 0, $year = '') |
1143
|
|
|
{ |
1144
|
|
|
if ($month < 1 OR $month > 12) { |
1145
|
|
|
return 0; |
1146
|
|
|
} elseif ( ! is_numeric($year) OR strlen($year) !== 4) { |
1147
|
|
|
$year = date('Y'); |
1148
|
|
|
} |
1149
|
|
|
|
1150
|
|
|
if (defined('CAL_GREGORIAN')) { |
1151
|
|
|
return cal_days_in_month(CAL_GREGORIAN, $month, $year); |
1152
|
|
|
} |
1153
|
|
|
|
1154
|
|
|
if ($year >= 1970) { |
1155
|
|
|
return (int)date('t', mktime(12, 0, 0, $month, 1, $year)); |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
if ($month == 2) { |
1159
|
|
|
if ($year % 400 === 0 OR ($year % 4 === 0 && $year % 100 !== 0)) { |
1160
|
|
|
return 29; |
1161
|
|
|
} |
1162
|
|
|
} |
1163
|
|
|
|
1164
|
|
|
$days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; |
1165
|
|
|
|
1166
|
|
|
return $days_in_month[ $month - 1 ]; |
1167
|
|
|
} |
1168
|
|
|
} |
1169
|
|
|
|
1170
|
|
|
// ------------------------------------------------------------------------ |
1171
|
|
|
|
1172
|
|
|
if ( ! function_exists('local_to_gmt')) { |
1173
|
|
|
/** |
1174
|
|
|
* Converts a local Unix timestamp to GMT |
1175
|
|
|
* |
1176
|
|
|
* @param int Unix timestamp |
|
|
|
|
1177
|
|
|
* |
1178
|
|
|
* @return int |
1179
|
|
|
*/ |
1180
|
|
|
function local_to_gmt($time = '') |
1181
|
|
|
{ |
1182
|
|
|
if ($time === '') { |
1183
|
|
|
$time = time(); |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
|
return mktime( |
1187
|
|
|
gmdate('G', $time), |
|
|
|
|
1188
|
|
|
gmdate('i', $time), |
|
|
|
|
1189
|
|
|
gmdate('s', $time), |
|
|
|
|
1190
|
|
|
gmdate('n', $time), |
|
|
|
|
1191
|
|
|
gmdate('j', $time), |
|
|
|
|
1192
|
|
|
gmdate('Y', $time) |
|
|
|
|
1193
|
|
|
); |
1194
|
|
|
} |
1195
|
|
|
} |
1196
|
|
|
|
1197
|
|
|
// ------------------------------------------------------------------------ |
1198
|
|
|
|
1199
|
|
|
if ( ! function_exists('gmt_to_local')) { |
1200
|
|
|
/** |
1201
|
|
|
* Converts GMT time to a localized value |
1202
|
|
|
* |
1203
|
|
|
* Takes a Unix timestamp (in GMT) as input, and returns |
1204
|
|
|
* at the local value based on the timezone and DST setting |
1205
|
|
|
* submitted |
1206
|
|
|
* |
1207
|
|
|
* @param int Unix timestamp |
1208
|
|
|
* @param string timezone |
1209
|
|
|
* @param bool whether DST is active |
|
|
|
|
1210
|
|
|
* |
1211
|
|
|
* @return int |
1212
|
|
|
*/ |
1213
|
|
|
function gmt_to_local($time = '', $timezone = 'UTC', $dst = false) |
1214
|
|
|
{ |
1215
|
|
|
if ($time === '') { |
1216
|
|
|
return now(); |
1217
|
|
|
} |
1218
|
|
|
|
1219
|
|
|
$time += timezones($timezone) * 3600; |
1220
|
|
|
|
1221
|
|
|
return ($dst === true) ? $time + 3600 : $time; |
1222
|
|
|
} |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
// ------------------------------------------------------------------------ |
1226
|
|
|
|
1227
|
|
|
if ( ! function_exists('mysql_to_unix')) { |
1228
|
|
|
/** |
1229
|
|
|
* Converts a MySQL Timestamp to Unix |
1230
|
|
|
* |
1231
|
|
|
* @param int MySQL timestamp YYYY-MM-DD HH:MM:SS |
1232
|
|
|
* |
1233
|
|
|
* @return int Unix timstamp |
1234
|
|
|
*/ |
1235
|
|
|
function mysql_to_unix($time = '') |
1236
|
|
|
{ |
1237
|
|
|
// We'll remove certain characters for backward compatibility |
1238
|
|
|
// since the formatting changed with MySQL 4.1 |
1239
|
|
|
// YYYY-MM-DD HH:MM:SS |
1240
|
|
|
|
1241
|
|
|
$time = str_replace(['-', ':', ' '], '', $time); |
1242
|
|
|
|
1243
|
|
|
// YYYYMMDDHHMMSS |
1244
|
|
|
return mktime( |
1245
|
|
|
substr($time, 8, 2), |
|
|
|
|
1246
|
|
|
substr($time, 10, 2), |
|
|
|
|
1247
|
|
|
substr($time, 12, 2), |
|
|
|
|
1248
|
|
|
substr($time, 4, 2), |
|
|
|
|
1249
|
|
|
substr($time, 6, 2), |
|
|
|
|
1250
|
|
|
substr($time, 0, 4) |
|
|
|
|
1251
|
|
|
); |
1252
|
|
|
} |
1253
|
|
|
} |
1254
|
|
|
|
1255
|
|
|
// ------------------------------------------------------------------------ |
1256
|
|
|
|
1257
|
|
|
if ( ! function_exists('unix_to_human')) { |
1258
|
|
|
/** |
1259
|
|
|
* Unix to "Human" |
1260
|
|
|
* |
1261
|
|
|
* Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM |
1262
|
|
|
* |
1263
|
|
|
* @param int Unix timestamp |
1264
|
|
|
* @param bool whether to show seconds |
1265
|
|
|
* @param string format: us or euro |
1266
|
|
|
* |
1267
|
|
|
* @return string |
1268
|
|
|
*/ |
1269
|
|
|
function unix_to_human($time = '', $seconds = false, $fmt = 'us') |
1270
|
|
|
{ |
1271
|
|
|
$r = date('Y', $time) . '-' . date('m', $time) . '-' . date('d', $time) . ' '; |
1272
|
|
|
|
1273
|
|
|
if ($fmt === 'us') { |
1274
|
|
|
$r .= date('h', $time) . ':' . date('i', $time); |
1275
|
|
|
} else { |
1276
|
|
|
$r .= date('H', $time) . ':' . date('i', $time); |
1277
|
|
|
} |
1278
|
|
|
|
1279
|
|
|
if ($seconds) { |
1280
|
|
|
$r .= ':' . date('s', $time); |
1281
|
|
|
} |
1282
|
|
|
|
1283
|
|
|
if ($fmt === 'us') { |
1284
|
|
|
return $r . ' ' . date('A', $time); |
1285
|
|
|
} |
1286
|
|
|
|
1287
|
|
|
return $r; |
1288
|
|
|
} |
1289
|
|
|
} |
1290
|
|
|
|
1291
|
|
|
// ------------------------------------------------------------------------ |
1292
|
|
|
|
1293
|
|
|
if ( ! function_exists('human_to_unix')) { |
1294
|
|
|
/** |
1295
|
|
|
* Convert "human" date to GMT |
1296
|
|
|
* |
1297
|
|
|
* Reverses the above process |
1298
|
|
|
* |
1299
|
|
|
* @param string format: us or euro |
1300
|
|
|
* |
1301
|
|
|
* @return int |
1302
|
|
|
*/ |
1303
|
|
|
function human_to_unix($date = '') |
1304
|
|
|
{ |
1305
|
|
|
if ($date === '') { |
1306
|
|
|
return false; |
|
|
|
|
1307
|
|
|
} |
1308
|
|
|
|
1309
|
|
|
$date = preg_replace('/\040+/', ' ', trim($date)); |
1310
|
|
|
|
1311
|
|
|
if ( ! preg_match( |
1312
|
|
|
'/^(\d{2}|\d{4})\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', |
1313
|
|
|
$date |
1314
|
|
|
) |
1315
|
|
|
) { |
1316
|
|
|
return false; |
|
|
|
|
1317
|
|
|
} |
1318
|
|
|
|
1319
|
|
|
sscanf($date, '%d-%d-%d %s %s', $year, $month, $day, $time, $ampm); |
|
|
|
|
1320
|
|
|
sscanf($time, '%d:%d:%d', $hour, $min, $sec); |
|
|
|
|
1321
|
|
|
isset($sec) OR $sec = 0; |
|
|
|
|
1322
|
|
|
|
1323
|
|
|
if (isset($ampm)) { |
|
|
|
|
1324
|
|
|
$ampm = strtolower($ampm); |
1325
|
|
|
|
1326
|
|
|
if ($ampm[ 0 ] === 'p' && $hour < 12) { |
1327
|
|
|
$hour += 12; |
1328
|
|
|
} elseif ($ampm[ 0 ] === 'a' && $hour === 12) { |
1329
|
|
|
$hour = 0; |
1330
|
|
|
} |
1331
|
|
|
} |
1332
|
|
|
|
1333
|
|
|
return mktime($hour, $min, $sec, $month, $day, $year); |
1334
|
|
|
} |
1335
|
|
|
} |
1336
|
|
|
|
1337
|
|
|
// ------------------------------------------------------------------------ |
1338
|
|
|
|
1339
|
|
|
if ( ! function_exists('nice_date')) { |
1340
|
|
|
/** |
1341
|
|
|
* Turns many "reasonably-date-like" strings into something |
1342
|
|
|
* that is actually useful. This only works for dates after unix epoch. |
1343
|
|
|
* |
1344
|
|
|
* @param string The terribly formatted date-like string |
1345
|
|
|
* @param string Date format to return (same as php date function) |
1346
|
|
|
* |
1347
|
|
|
* @return string |
1348
|
|
|
*/ |
1349
|
|
|
function nice_date($bad_date = '', $format = false) |
1350
|
|
|
{ |
1351
|
|
|
if (empty($bad_date)) { |
1352
|
|
|
return 'Unknown'; |
1353
|
|
|
} elseif (empty($format)) { |
1354
|
|
|
$format = 'U'; |
1355
|
|
|
} |
1356
|
|
|
|
1357
|
|
|
// Date like: YYYYMM |
1358
|
|
|
if (preg_match('/^\d{6}$/i', $bad_date)) { |
1359
|
|
|
if (in_array(substr($bad_date, 0, 2), ['19', '20'])) { |
1360
|
|
|
$year = substr($bad_date, 0, 4); |
1361
|
|
|
$month = substr($bad_date, 4, 2); |
1362
|
|
|
} else { |
1363
|
|
|
$month = substr($bad_date, 0, 2); |
1364
|
|
|
$year = substr($bad_date, 2, 4); |
1365
|
|
|
} |
1366
|
|
|
|
1367
|
|
|
return date($format, strtotime($year . '-' . $month . '-01')); |
1368
|
|
|
} |
1369
|
|
|
|
1370
|
|
|
// Date Like: YYYYMMDD |
1371
|
|
|
if (preg_match('/^(\d{2})\d{2}(\d{4})$/i', $bad_date, $matches)) { |
1372
|
|
|
return date($format, strtotime($matches[ 1 ] . '/01/' . $matches[ 2 ])); |
1373
|
|
|
} |
1374
|
|
|
|
1375
|
|
|
// Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between) |
1376
|
|
|
if (preg_match('/^(\d{1,2})-(\d{1,2})-(\d{4})$/i', $bad_date, $matches)) { |
1377
|
|
|
return date($format, strtotime($matches[ 3 ] . '-' . $matches[ 1 ] . '-' . $matches[ 2 ])); |
1378
|
|
|
} |
1379
|
|
|
|
1380
|
|
|
// Any other kind of string, when converted into UNIX time, |
1381
|
|
|
// produces "0 seconds after epoc..." is probably bad... |
1382
|
|
|
// return "Invalid Date". |
1383
|
|
|
if (date('U', strtotime($bad_date)) === '0') { |
1384
|
|
|
return 'Invalid Date'; |
1385
|
|
|
} |
1386
|
|
|
|
1387
|
|
|
// It's probably a valid-ish date format already |
1388
|
|
|
return date($format, strtotime($bad_date)); |
1389
|
|
|
} |
1390
|
|
|
} |
1391
|
|
|
|
1392
|
|
|
// ------------------------------------------------------------------------ |
1393
|
|
|
|
1394
|
|
|
if ( ! function_exists('timezones')) { |
1395
|
|
|
/** |
1396
|
|
|
* Timezones |
1397
|
|
|
* |
1398
|
|
|
* Returns an array of timezones. This is a helper function |
1399
|
|
|
* for various other ones in this library |
1400
|
|
|
* |
1401
|
|
|
* @param string timezone |
1402
|
|
|
* |
1403
|
|
|
* @return string |
1404
|
|
|
*/ |
1405
|
|
|
function timezones($tz = '') |
1406
|
|
|
{ |
1407
|
|
|
// Note: Don't change the order of these even though |
1408
|
|
|
// some items appear to be in the wrong order |
1409
|
|
|
|
1410
|
|
|
$zones = [ |
1411
|
|
|
'UM12' => -12, |
1412
|
|
|
'UM11' => -11, |
1413
|
|
|
'UM10' => -10, |
1414
|
|
|
'UM95' => -9.5, |
1415
|
|
|
'UM9' => -9, |
1416
|
|
|
'UM8' => -8, |
1417
|
|
|
'UM7' => -7, |
1418
|
|
|
'UM6' => -6, |
1419
|
|
|
'UM5' => -5, |
1420
|
|
|
'UM45' => -4.5, |
1421
|
|
|
'UM4' => -4, |
1422
|
|
|
'UM35' => -3.5, |
1423
|
|
|
'UM3' => -3, |
1424
|
|
|
'UM2' => -2, |
1425
|
|
|
'UM1' => -1, |
1426
|
|
|
'UTC' => 0, |
1427
|
|
|
'UP1' => +1, |
1428
|
|
|
'UP2' => +2, |
1429
|
|
|
'UP3' => +3, |
1430
|
|
|
'UP35' => +3.5, |
1431
|
|
|
'UP4' => +4, |
1432
|
|
|
'UP45' => +4.5, |
1433
|
|
|
'UP5' => +5, |
1434
|
|
|
'UP55' => +5.5, |
1435
|
|
|
'UP575' => +5.75, |
1436
|
|
|
'UP6' => +6, |
1437
|
|
|
'UP65' => +6.5, |
1438
|
|
|
'UP7' => +7, |
1439
|
|
|
'UP8' => +8, |
1440
|
|
|
'UP875' => +8.75, |
1441
|
|
|
'UP9' => +9, |
1442
|
|
|
'UP95' => +9.5, |
1443
|
|
|
'UP10' => +10, |
1444
|
|
|
'UP105' => +10.5, |
1445
|
|
|
'UP11' => +11, |
1446
|
|
|
'UP115' => +11.5, |
1447
|
|
|
'UP12' => +12, |
1448
|
|
|
'UP1275' => +12.75, |
1449
|
|
|
'UP13' => +13, |
1450
|
|
|
'UP14' => +14, |
1451
|
|
|
]; |
1452
|
|
|
|
1453
|
|
|
if ($tz === '') { |
1454
|
|
|
return $zones; |
|
|
|
|
1455
|
|
|
} |
1456
|
|
|
|
1457
|
|
|
return isset($zones[ $tz ]) ? $zones[ $tz ] : 0; |
1458
|
|
|
} |
1459
|
|
|
} |
1460
|
|
|
|
1461
|
|
|
// ------------------------------------------------------------------------ |
1462
|
|
|
|
1463
|
|
|
if ( ! function_exists('date_range_unix')) { |
1464
|
|
|
/** |
1465
|
|
|
* Date range |
1466
|
|
|
* |
1467
|
|
|
* Returns a list of dates within a specified period. |
1468
|
|
|
* |
1469
|
|
|
* @param int unix_start UNIX timestamp of period start date |
1470
|
|
|
* @param int unix_end|days UNIX timestamp of period end date |
|
|
|
|
1471
|
|
|
* or interval in days. |
1472
|
|
|
* @param mixed is_unix Specifies whether the second parameter |
|
|
|
|
1473
|
|
|
* is a UNIX timestamp or a day interval |
1474
|
|
|
* - TRUE or 'unix' for a timestamp |
1475
|
|
|
* - FALSE or 'days' for an interval |
1476
|
|
|
* @param string date_format Browser date format, same as in date() |
|
|
|
|
1477
|
|
|
* |
1478
|
|
|
* @return array |
1479
|
|
|
*/ |
1480
|
|
|
function date_range_unix($unix_start = '', $mixed = '', $is_unix = true, $format = 'Y-m-d') |
1481
|
|
|
{ |
1482
|
|
|
if ($unix_start == '' OR $mixed == '' OR $format == '') { |
1483
|
|
|
return false; |
|
|
|
|
1484
|
|
|
} |
1485
|
|
|
|
1486
|
|
|
$is_unix = ! ( ! $is_unix OR $is_unix === 'days'); |
1487
|
|
|
|
1488
|
|
|
// Validate input and try strtotime() on invalid timestamps/intervals, just in case |
1489
|
|
|
if (( ! ctype_digit((string)$unix_start) && ($unix_start = @strtotime($unix_start)) === false) |
1490
|
|
|
OR ( ! ctype_digit((string)$mixed) && ($is_unix === false OR ($mixed = @strtotime( |
1491
|
|
|
$mixed |
1492
|
|
|
)) === false)) |
1493
|
|
|
OR ($is_unix === true && $mixed < $unix_start) |
1494
|
|
|
) { |
1495
|
|
|
return false; |
|
|
|
|
1496
|
|
|
} |
1497
|
|
|
|
1498
|
|
|
if ($is_unix && ($unix_start == $mixed OR date($format, $unix_start) === date($format, $mixed))) { |
|
|
|
|
1499
|
|
|
return [date($format, $unix_start)]; |
1500
|
|
|
} |
1501
|
|
|
|
1502
|
|
|
$range = []; |
1503
|
|
|
|
1504
|
|
|
/* NOTE: Even though the DateTime object has many useful features, it appears that |
1505
|
|
|
* it doesn't always handle properly timezones, when timestamps are passed |
1506
|
|
|
* directly to its constructor. Neither of the following gave proper results: |
1507
|
|
|
* |
1508
|
|
|
* new DateTime('<timestamp>') |
1509
|
|
|
* new DateTime('<timestamp>', '<timezone>') |
1510
|
|
|
* |
1511
|
|
|
* --- available in PHP 5.3: |
1512
|
|
|
* |
1513
|
|
|
* DateTime::createFromFormat('<format>', '<timestamp>') |
1514
|
|
|
* DateTime::createFromFormat('<format>', '<timestamp>', '<timezone') |
1515
|
|
|
* |
1516
|
|
|
* ... so we'll have to set the timestamp after the object is instantiated. |
1517
|
|
|
* Furthermore, in PHP 5.3 we can use DateTime::setTimestamp() to do that and |
1518
|
|
|
* given that we have UNIX timestamps - we should use it. |
1519
|
|
|
*/ |
1520
|
|
|
$from = new DateTime(); |
1521
|
|
|
|
1522
|
|
|
if (is_php('5.3')) { |
1523
|
|
|
$from->setTimestamp($unix_start); |
1524
|
|
|
if ($is_unix) { |
1525
|
|
|
$arg = new DateTime(); |
1526
|
|
|
$arg->setTimestamp($mixed); |
|
|
|
|
1527
|
|
|
} else { |
1528
|
|
|
$arg = (int)$mixed; |
1529
|
|
|
} |
1530
|
|
|
|
1531
|
|
|
$period = new DatePeriod($from, new DateInterval('P1D'), $arg); |
|
|
|
|
1532
|
|
|
foreach ($period as $date) { |
1533
|
|
|
$range[] = $date->format($format); |
1534
|
|
|
} |
1535
|
|
|
|
1536
|
|
|
/* If a period end date was passed to the DatePeriod constructor, it might not |
1537
|
|
|
* be in our results. Not sure if this is a bug or it's just possible because |
1538
|
|
|
* the end date might actually be less than 24 hours away from the previously |
1539
|
|
|
* generated DateTime object, but either way - we have to append it manually. |
1540
|
|
|
*/ |
1541
|
|
|
if ( ! is_int($arg) && $range[ count($range) - 1 ] !== $arg->format($format)) { |
1542
|
|
|
$range[] = $arg->format($format); |
1543
|
|
|
} |
1544
|
|
|
|
1545
|
|
|
return $range; |
1546
|
|
|
} |
1547
|
|
|
|
1548
|
|
|
$from->setDate(date('Y', $unix_start), date('n', $unix_start), date('j', $unix_start)); |
|
|
|
|
1549
|
|
|
$from->setTime(date('G', $unix_start), date('i', $unix_start), date('s', $unix_start)); |
|
|
|
|
1550
|
|
|
if ($is_unix) { |
1551
|
|
|
$arg = new DateTime(); |
1552
|
|
|
$arg->setDate(date('Y', $mixed), date('n', $mixed), date('j', $mixed)); |
1553
|
|
|
$arg->setTime(date('G', $mixed), date('i', $mixed), date('s', $mixed)); |
1554
|
|
|
} else { |
1555
|
|
|
$arg = (int)$mixed; |
1556
|
|
|
} |
1557
|
|
|
$range[] = $from->format($format); |
1558
|
|
|
|
1559
|
|
|
if (is_int($arg)) // Day intervals |
1560
|
|
|
{ |
1561
|
|
|
do { |
1562
|
|
|
$from->modify('+1 day'); |
1563
|
|
|
$range[] = $from->format($format); |
1564
|
|
|
} while (--$arg > 0); |
1565
|
|
|
} else // end date UNIX timestamp |
1566
|
|
|
{ |
1567
|
|
|
for ($from->modify('+1 day'), $end_check = $arg->format('Ymd'); $from->format( |
1568
|
|
|
'Ymd' |
1569
|
|
|
) < $end_check; $from->modify('+1 day')) { |
1570
|
|
|
$range[] = $from->format($format); |
1571
|
|
|
} |
1572
|
|
|
|
1573
|
|
|
// Our loop only appended dates prior to our end date |
1574
|
|
|
$range[] = $arg->format($format); |
1575
|
|
|
} |
1576
|
|
|
|
1577
|
|
|
return $range; |
1578
|
|
|
} |
1579
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths