|
|
|
@ -28,35 +28,24 @@ |
|
|
|
Convert UNIX timestamp to Julian Day */ |
|
|
|
PHP_FUNCTION(unixtojd) |
|
|
|
{ |
|
|
|
zval *timestamp; |
|
|
|
long jdate; |
|
|
|
time_t t; |
|
|
|
struct tm *ta, tmbuf; |
|
|
|
int myargc=ZEND_NUM_ARGS(); |
|
|
|
|
|
|
|
if ((myargc > 1) || (zend_get_parameters(ht, myargc, ×tamp) != SUCCESS)) { |
|
|
|
WRONG_PARAM_COUNT; |
|
|
|
} |
|
|
|
time_t ts = 0; |
|
|
|
struct tm *ta, tmbuf; |
|
|
|
|
|
|
|
if(myargc==1) { |
|
|
|
convert_to_long(timestamp); |
|
|
|
t = Z_LVAL_P(timestamp); |
|
|
|
} else { |
|
|
|
t = time(NULL); |
|
|
|
} |
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts) == FAILURE) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if(t < 0) { |
|
|
|
RETURN_FALSE; |
|
|
|
} |
|
|
|
if (!ts) { |
|
|
|
ts = time(NULL); |
|
|
|
} else if (ts < 0) { |
|
|
|
RETURN_FALSE; |
|
|
|
} |
|
|
|
|
|
|
|
ta = php_localtime_r(&t, &tmbuf); |
|
|
|
if (!ta) { |
|
|
|
RETURN_FALSE; |
|
|
|
} |
|
|
|
if (!(ta = php_localtime_r(&ts, &tmbuf))) { |
|
|
|
RETURN_FALSE; |
|
|
|
} |
|
|
|
|
|
|
|
jdate = GregorianToSdn(ta->tm_year+1900, ta->tm_mon+1, ta->tm_mday); |
|
|
|
|
|
|
|
RETURN_LONG(jdate); |
|
|
|
RETURN_LONG(GregorianToSdn(ta->tm_year+1900, ta->tm_mon+1, ta->tm_mday)); |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
@ -64,21 +53,18 @@ PHP_FUNCTION(unixtojd) |
|
|
|
Convert Julian Day to UNIX timestamp */ |
|
|
|
PHP_FUNCTION(jdtounix) |
|
|
|
{ |
|
|
|
zval *jday; |
|
|
|
long uday; |
|
|
|
long uday; |
|
|
|
|
|
|
|
if ((ZEND_NUM_ARGS()!= 1) || (zend_get_parameters(ht, 1, &jday) != SUCCESS)) { |
|
|
|
WRONG_PARAM_COUNT; |
|
|
|
} |
|
|
|
|
|
|
|
convert_to_long(jday); |
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &uday) == FAILURE) { |
|
|
|
return; |
|
|
|
} |
|
|
|
uday -= 2440588 /* J.D. of 1.1.1970 */; |
|
|
|
|
|
|
|
uday = Z_LVAL_P(jday) - 2440588 /* J.D. of 1.1.1970 */; |
|
|
|
|
|
|
|
if(uday<0) RETURN_FALSE; /* before beginning of unix epoch */ |
|
|
|
if(uday>24755) RETURN_FALSE; /* behind end of unix epoch */ |
|
|
|
if (uday < 0 || uday > 24755) { /* before beginning of unix epoch or behind end of unix epoch */ |
|
|
|
RETURN_FALSE; |
|
|
|
} |
|
|
|
|
|
|
|
RETURN_LONG(uday*24*3600); |
|
|
|
RETURN_LONG(uday * 24 * 3600); |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
|