diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2008-02-13 23:50:35 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2008-02-13 23:50:35 +0000 |
commit | e6e162bc8ea5c49b7549ed2971864241fbeb7144 (patch) | |
tree | 3f3e34e9c55d0ff96cbe6e5f98c198def7a80752 /ext/calendar | |
parent | 3edbc7b0b385079f9c7c138e99cc5724f37d1baf (diff) | |
download | php-git-e6e162bc8ea5c49b7549ed2971864241fbeb7144.tar.gz |
New calendar parsing API
Diffstat (limited to 'ext/calendar')
-rw-r--r-- | ext/calendar/cal_unix.c | 60 |
1 files changed, 23 insertions, 37 deletions
diff --git a/ext/calendar/cal_unix.c b/ext/calendar/cal_unix.c index be0e0c5a2b..b565ca0233 100644 --- a/ext/calendar/cal_unix.c +++ b/ext/calendar/cal_unix.c @@ -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); } /* }}} */ |