php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
cal_unix.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Shane Caraveo <shane@caraveo.com> |
14 | Colin Viebrock <colin@easydns.com> |
15 | Hartmut Holzgraefe <hholzgra@php.net> |
16 +----------------------------------------------------------------------+
17 */
18
19#include "php.h"
20#include "php_calendar.h"
21#include "sdncal.h"
22#include <time.h>
23
24#define SECS_PER_DAY (24 * 3600)
25
26/* {{{ Convert UNIX timestamp to Julian Day */
28{
29 time_t ts;
30 zend_long tl = 0;
31 bool tl_is_null = 1;
32 struct tm *ta, tmbuf;
33
34 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &tl, &tl_is_null) == FAILURE) {
36 }
37
38 if (tl_is_null) {
39 ts = time(NULL);
40 } else if (tl >= 0) {
41 ts = (time_t) tl;
42 } else {
43 zend_argument_value_error(1, "must be greater than or equal to 0");
45 }
46
47 if (!(ta = php_localtime_r(&ts, &tmbuf))) {
49 }
50
51 RETURN_LONG(GregorianToSdn(ta->tm_year+1900, ta->tm_mon+1, ta->tm_mday));
52}
53/* }}} */
54
55/* {{{ Convert Julian Day to UNIX timestamp */
57{
58 zend_long uday;
59
60 if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &uday) == FAILURE) {
62 }
63 if (uday < 2440588 || (uday - 2440588) > (ZEND_LONG_MAX / SECS_PER_DAY)) { /* before beginning of unix epoch or greater than representable */
64 zend_value_error("jday must be between 2440588 and " ZEND_LONG_FMT, ZEND_LONG_MAX / SECS_PER_DAY + 2440588);
66 }
67
68 uday -= 2440588 /* J.D. of 1.1.1970 */;
69
71}
72/* }}} */
#define SECS_PER_DAY
Definition cal_unix.c:24
unixtojd(?int $timestamp=null)
jdtounix(int $julian_day)
#define NULL
Definition gdcache.h:45
zend_long GregorianToSdn(int inputYear, int inputMonth, int inputDay)
Definition gregor.c:202
#define PHP_FUNCTION
Definition php.h:364
time()
PHPAPI struct tm * php_localtime_r(const time_t *const timep, struct tm *p_tm)
Definition reentrancy.c:110
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
Definition zend.c:1849
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
Definition zend_API.c:1300
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
Definition zend_API.c:433
#define ZEND_NUM_ARGS()
Definition zend_API.h:530
#define RETURN_FALSE
Definition zend_API.h:1058
#define RETURN_LONG(l)
Definition zend_API.h:1037
#define RETURN_THROWS()
Definition zend_API.h:1060
int32_t zend_long
Definition zend_long.h:42
#define ZEND_LONG_FMT
Definition zend_long.h:87
#define ZEND_LONG_MAX
Definition zend_long.h:45
@ FAILURE
Definition zend_types.h:61