PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / Safe / generated / datetime.php

datetime.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/Safe/generated/datetime.php

637 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_DEFENDER_VENDOR\Safe;
4
5 use WP_DEFENDER_VENDOR\Safe\Exceptions\DatetimeException;
6
7 /**
8 * Returns associative array with detailed info about given date/time.
9 *
10 * @param string $format Format accepted by DateTime::createFromFormat.
11 * @param string $datetime String representing the date/time.
12 * @return array Returns associative array with detailed info about given date/time.
13 * @throws DatetimeException
14 *
15 */
16 function date_parse_from_format(string $format, string $datetime): array
17 {
18 error_clear_last();
19 $result = \date_parse_from_format($format, $datetime);
20 if ($result === false) {
21 throw DatetimeException::createFromPhpError();
22 }
23 return $result;
24 }
25
26
27 /**
28 *
29 *
30 * @param string $datetime Date/time in format accepted by
31 * DateTimeImmutable::__construct.
32 * @return array Returns array with information about the parsed date/time
33 * on success.
34 * @throws DatetimeException
35 *
36 */
37 function date_parse(string $datetime): array
38 {
39 error_clear_last();
40 $result = \date_parse($datetime);
41 if ($result === false) {
42 throw DatetimeException::createFromPhpError();
43 }
44 return $result;
45 }
46
47
48 /**
49 *
50 *
51 * @param int $timestamp Unix timestamp.
52 * @param float $latitude Latitude in degrees.
53 * @param float $longitude Longitude in degrees.
54 * @return array Returns array on success.
55 * The structure of the array is detailed in the following list:
56 *
57 *
58 *
59 * sunrise
60 *
61 *
62 * The timestamp of the sunrise (zenith angle = 90°35').
63 *
64 *
65 *
66 *
67 * sunset
68 *
69 *
70 * The timestamp of the sunset (zenith angle = 90°35').
71 *
72 *
73 *
74 *
75 * transit
76 *
77 *
78 * The timestamp when the sun is at its zenith, i.e. has reached its topmost
79 * point.
80 *
81 *
82 *
83 *
84 * civil_twilight_begin
85 *
86 *
87 * The start of the civil dawn (zenith angle = 96°). It ends at sunrise.
88 *
89 *
90 *
91 *
92 * civil_twilight_end
93 *
94 *
95 * The end of the civil dusk (zenith angle = 96°). It starts at sunset.
96 *
97 *
98 *
99 *
100 * nautical_twilight_begin
101 *
102 *
103 * The start of the nautical dawn (zenith angle = 102°). It ends at
104 * civil_twilight_begin.
105 *
106 *
107 *
108 *
109 * nautical_twilight_end
110 *
111 *
112 * The end of the nautical dusk (zenith angle = 102°). It starts at
113 * civil_twilight_end.
114 *
115 *
116 *
117 *
118 * astronomical_twilight_begin
119 *
120 *
121 * The start of the astronomical dawn (zenith angle = 108°). It ends at
122 * nautical_twilight_begin.
123 *
124 *
125 *
126 *
127 * astronomical_twilight_end
128 *
129 *
130 * The end of the astronomical dusk (zenith angle = 108°). It starts at
131 * nautical_twilight_end.
132 *
133 *
134 *
135 *
136 *
137 * The values of the array elements are either UNIX timestamps, FALSE if the
138 * sun is below the respective zenith for the whole day, or TRUE if the sun is
139 * above the respective zenith for the whole day.
140 * @throws DatetimeException
141 *
142 */
143 function date_sun_info(int $timestamp, float $latitude, float $longitude): array
144 {
145 error_clear_last();
146 $result = \date_sun_info($timestamp, $latitude, $longitude);
147 if ($result === false) {
148 throw DatetimeException::createFromPhpError();
149 }
150 return $result;
151 }
152
153
154 /**
155 * date_sunrise returns the sunrise time for a given
156 * day (specified as a timestamp) and location.
157 *
158 * @param int $timestamp The timestamp of the day from which the sunrise
159 * time is taken.
160 * @param int $returnFormat
161 * returnFormat constants
162 *
163 *
164 *
165 * constant
166 * description
167 * example
168 *
169 *
170 *
171 *
172 * SUNFUNCS_RET_STRING
173 * returns the result as string
174 * 16:46
175 *
176 *
177 * SUNFUNCS_RET_DOUBLE
178 * returns the result as float
179 * 16.78243132
180 *
181 *
182 * SUNFUNCS_RET_TIMESTAMP
183 * returns the result as integer (timestamp)
184 * 1095034606
185 *
186 *
187 *
188 *
189 * @param float|null $latitude Defaults to North, pass in a negative value for South.
190 * See also: date.default_latitude
191 * @param float|null $longitude Defaults to East, pass in a negative value for West.
192 * See also: date.default_longitude
193 * @param float|null $zenith zenith is the angle between the center of the sun
194 * and a line perpendicular to earth's surface. It defaults to
195 * date.sunrise_zenith
196 *
197 * Common zenith angles
198 *
199 *
200 *
201 * Angle
202 * Description
203 *
204 *
205 *
206 *
207 * 90°50'
208 * Sunrise: the point where the sun becomes visible.
209 *
210 *
211 * 96°
212 * Civil twilight: conventionally used to signify the start of dawn.
213 *
214 *
215 * 102°
216 * Nautical twilight: the point at which the horizon starts being visible at sea.
217 *
218 *
219 * 108°
220 * Astronomical twilight: the point at which the sun starts being the source of any illumination.
221 *
222 *
223 *
224 *
225 * @param float $utcOffset Specified in hours.
226 * The utcOffset is ignored, if
227 * returnFormat is
228 * SUNFUNCS_RET_TIMESTAMP.
229 *
230 * @return mixed Returns the sunrise time in a specified returnFormat on
231 * success. One potential reason for failure is that the
232 * sun does not rise at all, which happens inside the polar circles for part of
233 * the year.
234 * @throws DatetimeException
235 *
236 */
237 function date_sunrise(int $timestamp, int $returnFormat = SUNFUNCS_RET_STRING, ?float $latitude = null, ?float $longitude = null, ?float $zenith = null, float $utcOffset = 0)
238 {
239 error_clear_last();
240 if ($utcOffset !== 0) {
241 $result = \date_sunrise($timestamp, $returnFormat, $latitude, $longitude, $zenith, $utcOffset);
242 } elseif ($zenith !== null) {
243 $result = \date_sunrise($timestamp, $returnFormat, $latitude, $longitude, $zenith);
244 } elseif ($longitude !== null) {
245 $result = \date_sunrise($timestamp, $returnFormat, $latitude, $longitude);
246 } elseif ($latitude !== null) {
247 $result = \date_sunrise($timestamp, $returnFormat, $latitude);
248 } else {
249 $result = \date_sunrise($timestamp, $returnFormat);
250 }
251 if ($result === false) {
252 throw DatetimeException::createFromPhpError();
253 }
254 return $result;
255 }
256
257
258 /**
259 * date_sunset returns the sunset time for a given
260 * day (specified as a timestamp) and location.
261 *
262 * @param int $timestamp The timestamp of the day from which the sunset
263 * time is taken.
264 * @param int $returnFormat
265 * returnFormat constants
266 *
267 *
268 *
269 * constant
270 * description
271 * example
272 *
273 *
274 *
275 *
276 * SUNFUNCS_RET_STRING
277 * returns the result as string
278 * 16:46
279 *
280 *
281 * SUNFUNCS_RET_DOUBLE
282 * returns the result as float
283 * 16.78243132
284 *
285 *
286 * SUNFUNCS_RET_TIMESTAMP
287 * returns the result as integer (timestamp)
288 * 1095034606
289 *
290 *
291 *
292 *
293 * @param float|null $latitude Defaults to North, pass in a negative value for South.
294 * See also: date.default_latitude
295 * @param float|null $longitude Defaults to East, pass in a negative value for West.
296 * See also: date.default_longitude
297 * @param float|null $zenith zenith is the angle between the center of the sun
298 * and a line perpendicular to earth's surface. It defaults to
299 * date.sunset_zenith
300 *
301 * Common zenith angles
302 *
303 *
304 *
305 * Angle
306 * Description
307 *
308 *
309 *
310 *
311 * 90°50'
312 * Sunset: the point where the sun becomes invisible.
313 *
314 *
315 * 96°
316 * Civil twilight: conventionally used to signify the end of dusk.
317 *
318 *
319 * 102°
320 * Nautical twilight: the point at which the horizon ends being visible at sea.
321 *
322 *
323 * 108°
324 * Astronomical twilight: the point at which the sun ends being the source of any illumination.
325 *
326 *
327 *
328 *
329 * @param float $utcOffset Specified in hours.
330 * The utcOffset is ignored, if
331 * returnFormat is
332 * SUNFUNCS_RET_TIMESTAMP.
333 *
334 * @return mixed Returns the sunset time in a specified returnFormat on
335 * success. One potential reason for failure is that the
336 * sun does not set at all, which happens inside the polar circles for part of
337 * the year.
338 * @throws DatetimeException
339 */
340 function date_sunset(int $timestamp, int $returnFormat = SUNFUNCS_RET_STRING, ?float $latitude = null, ?float $longitude = null, ?float $zenith = null, float $utcOffset = 0)
341 {
342 error_clear_last();
343 if ($utcOffset !== 0) {
344 $result = \date_sunset($timestamp, $returnFormat, $latitude, $longitude, $zenith, $utcOffset);
345 } elseif ($zenith !== null) {
346 $result = \date_sunset($timestamp, $returnFormat, $latitude, $longitude, $zenith);
347 } elseif ($longitude !== null) {
348 $result = \date_sunset($timestamp, $returnFormat, $latitude, $longitude);
349 } elseif ($latitude !== null) {
350 $result = \date_sunset($timestamp, $returnFormat, $latitude);
351 } else {
352 $result = \date_sunset($timestamp, $returnFormat);
353 }
354 if ($result === false) {
355 throw DatetimeException::createFromPhpError();
356 }
357 return $result;
358 }
359
360
361 /**
362 * Returns a string formatted according to the given format string using the
363 * given integer timestamp or the current time
364 * if no timestamp is given. In other words, timestamp
365 * is optional and defaults to the value of time.
366 *
367 * @param string $format Format accepted by DateTimeInterface::format.
368 * @param int|null $timestamp The optional timestamp parameter is an
369 * integer Unix timestamp that defaults to the current
370 * local time if a timestamp is not given. In other
371 * words, it defaults to the value of time.
372 *
373 * @return string Returns a formatted date string. If a non-numeric value is used for
374 * timestamp, FALSE is returned and an
375 * E_WARNING level error is emitted.
376 * @throws DatetimeException
377 *
378 */
379 function date(string $format, ?int $timestamp = null): string
380 {
381 error_clear_last();
382 if ($timestamp !== null) {
383 $result = \date($format, $timestamp);
384 } else {
385 $result = \date($format);
386 }
387 if ($result === false) {
388 throw DatetimeException::createFromPhpError();
389 }
390 return $result;
391 }
392
393
394 /**
395 * Identical to the date function except that
396 * the time returned is Greenwich Mean Time (GMT).
397 *
398 * @param string $format The format of the outputted date string. See the formatting
399 * options for the date function.
400 * @param int|null $timestamp The optional timestamp parameter is an
401 * integer Unix timestamp that defaults to the current
402 * local time if a timestamp is not given. In other
403 * words, it defaults to the value of time.
404 *
405 * @return string Returns a formatted date string. If a non-numeric value is used for
406 * timestamp, FALSE is returned and an
407 * E_WARNING level error is emitted.
408 * @throws DatetimeException
409 *
410 */
411 function gmdate(string $format, ?int $timestamp = null): string
412 {
413 error_clear_last();
414 if ($timestamp !== null) {
415 $result = \gmdate($format, $timestamp);
416 } else {
417 $result = \gmdate($format);
418 }
419 if ($result === false) {
420 throw DatetimeException::createFromPhpError();
421 }
422 return $result;
423 }
424
425
426 /**
427 * Returns the Unix timestamp corresponding to the arguments
428 * given. This timestamp is a long integer containing the number of
429 * seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time
430 * specified.
431 *
432 * Arguments may be left out in order from right to left; any
433 * arguments thus omitted will be set to the current value according
434 * to the local date and time.
435 *
436 * @param int|null $hour The number of the hour relative to the start of the day determined by
437 * month, day and year.
438 * Negative values reference the hour before midnight of the day in question.
439 * Values greater than 23 reference the appropriate hour in the following day(s).
440 * @param int|null $minute The number of the minute relative to the start of the hour.
441 * Negative values reference the minute in the previous hour.
442 * Values greater than 59 reference the appropriate minute in the following hour(s).
443 * @param int|null $second The number of seconds relative to the start of the minute.
444 * Negative values reference the second in the previous minute.
445 * Values greater than 59 reference the appropriate second in the following minute(s).
446 * @param int|null $month The number of the month relative to the end of the previous year.
447 * Values 1 to 12 reference the normal calendar months of the year in question.
448 * Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc.
449 * Values greater than 12 reference the appropriate month in the following year(s).
450 * @param int|null $day The number of the day relative to the end of the previous month.
451 * Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month.
452 * Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc.
453 * Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).
454 * @param int|null $year The number of the year, may be a two or four digit value,
455 * with values between 0-69 mapping to 2000-2069 and 70-100 to
456 * 1970-2000. On systems where time_t is a 32bit signed integer, as
457 * most common today, the valid range for year
458 * is somewhere between 1901 and 2038. However, before PHP 5.1.0 this
459 * range was limited from 1970 to 2038 on some systems (e.g. Windows).
460 *
461 * @return int mktime returns the Unix timestamp of the arguments
462 * given.
463 * If the arguments are invalid, the function returns FALSE (before PHP 5.1
464 * it returned -1).
465 * @throws DatetimeException
466 *
467 */
468 function mktime( ?int $hour = null, ?int $minute = null, ?int $second = null, ?int $month = null, ?int $day = null, ?int $year = null): int
469 {
470 error_clear_last();
471 if ($year !== null) {
472 $result = \mktime($hour, $minute, $second, $month, $day, $year);
473 } elseif ($day !== null) {
474 $result = \mktime($hour, $minute, $second, $month, $day);
475 } elseif ($month !== null) {
476 $result = \mktime($hour, $minute, $second, $month);
477 } elseif ($second !== null) {
478 $result = \mktime($hour, $minute, $second);
479 } elseif ($minute !== null) {
480 $result = \mktime($hour, $minute);
481 } elseif ($hour !== null) {
482 $result = \mktime($hour);
483 } else {
484 $result = \mktime(0);
485 }
486 if ($result === false) {
487 throw DatetimeException::createFromPhpError();
488 }
489 return $result;
490 }
491
492
493 /**
494 * strptime returns an array with the
495 * date parsed.
496 *
497 * Month and weekday names and other language dependent strings respect the
498 * current locale set with setlocale (LC_TIME).
499 *
500 * @param string $date The string to parse (e.g. returned from strftime).
501 * @param string $format The format used in date (e.g. the same as
502 * used in strftime). Note that some of the format
503 * options available to strftime may not have any
504 * effect within strptime; the exact subset that are
505 * supported will vary based on the operating system and C library in
506 * use.
507 *
508 * For more information about the format options, read the
509 * strftime page.
510 * @return array Returns an array.
511 *
512 *
513 * The following parameters are returned in the array
514 *
515 *
516 *
517 * parameters
518 * Description
519 *
520 *
521 *
522 *
523 * "tm_sec"
524 * Seconds after the minute (0-61)
525 *
526 *
527 * "tm_min"
528 * Minutes after the hour (0-59)
529 *
530 *
531 * "tm_hour"
532 * Hour since midnight (0-23)
533 *
534 *
535 * "tm_mday"
536 * Day of the month (1-31)
537 *
538 *
539 * "tm_mon"
540 * Months since January (0-11)
541 *
542 *
543 * "tm_year"
544 * Years since 1900
545 *
546 *
547 * "tm_wday"
548 * Days since Sunday (0-6)
549 *
550 *
551 * "tm_yday"
552 * Days since January 1 (0-365)
553 *
554 *
555 * "unparsed"
556 * the date part which was not
557 * recognized using the specified format
558 *
559 *
560 *
561 *
562 * @throws DatetimeException
563 *
564 */
565 function strptime(string $date, string $format): array
566 {
567 error_clear_last();
568 $result = \strptime($date, $format);
569 if ($result === false) {
570 throw DatetimeException::createFromPhpError();
571 }
572 return $result;
573 }
574
575
576 /**
577 * Each parameter of this function uses the default time zone unless a
578 * time zone is specified in that parameter. Be careful not to use
579 * different time zones in each parameter unless that is intended.
580 * See date_default_timezone_get on the various
581 * ways to define the default time zone.
582 *
583 * @param string $datetime A date/time string. Valid formats are explained in Date and Time Formats.
584 * @param int|null $now The timestamp which is used as a base for the calculation of relative
585 * dates.
586 *
587 * @return int Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0,
588 * this function would return -1 on failure.
589 * @throws DatetimeException
590 *
591 */
592 function strtotime(string $datetime, ?int $now = null): int
593 {
594 error_clear_last();
595 if ($now !== null) {
596 $result = \strtotime($datetime, $now);
597 } else {
598 $result = \strtotime($datetime);
599 }
600 if ($result === false) {
601 throw DatetimeException::createFromPhpError();
602 }
603 return $result;
604 }
605
606
607 /**
608 *
609 *
610 * @param string $abbr Time zone abbreviation.
611 * @param int $utcOffset Offset from GMT in seconds. Defaults to -1 which means that first found
612 * time zone corresponding to abbr is returned.
613 * Otherwise exact offset is searched and only if not found then the first
614 * time zone with any offset is returned.
615 * @param int $isDST Daylight saving time indicator. Defaults to -1, which means that
616 * whether the time zone has daylight saving or not is not taken into
617 * consideration when searching. If this is set to 1, then the
618 * utcOffset is assumed to be an offset with
619 * daylight saving in effect; if 0, then utcOffset
620 * is assumed to be an offset without daylight saving in effect. If
621 * abbr doesn't exist then the time zone is
622 * searched solely by the utcOffset and
623 * isDST.
624 * @return string Returns time zone name on success.
625 * @throws DatetimeException
626 *
627 */
628 function timezone_name_from_abbr(string $abbr, int $utcOffset = -1, int $isDST = -1): string
629 {
630 error_clear_last();
631 $result = \timezone_name_from_abbr($abbr, $utcOffset, $isDST);
632 if ($result === false) {
633 throw DatetimeException::createFromPhpError();
634 }
635 return $result;
636 }
637