1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
12 : | obtain it through the world-wide-web, please send a note to |
13 : | license@php.net so we can mail you a copy immediately. |
14 : +----------------------------------------------------------------------+
15 : | Authors: Shane Caraveo <shane@caraveo.com> |
16 : | Colin Viebrock <colin@easydns.com> |
17 : | Hartmut Holzgraefe <hholzgra@php.net> |
18 : +----------------------------------------------------------------------+
19 : */
20 : /* $Id: */
21 :
22 : #include "php.h"
23 : #include "php_calendar.h"
24 : #include "sdncal.h"
25 : #include <time.h>
26 :
27 : /* {{{ proto int unixtojd([int timestamp])
28 : Convert UNIX timestamp to Julian Day */
29 : PHP_FUNCTION(unixtojd)
30 3 : {
31 : zval *timestamp;
32 : long jdate;
33 : time_t t;
34 : struct tm *ta, tmbuf;
35 3 : int myargc=ZEND_NUM_ARGS();
36 :
37 3 : if ((myargc > 1) || (zend_get_parameters(ht, myargc, ×tamp) != SUCCESS)) {
38 0 : WRONG_PARAM_COUNT;
39 : }
40 :
41 3 : if(myargc==1) {
42 3 : convert_to_long(timestamp);
43 3 : t = Z_LVAL_P(timestamp);
44 : } else {
45 0 : t = time(NULL);
46 : }
47 :
48 3 : if(t < 0) {
49 0 : RETURN_FALSE;
50 : }
51 :
52 3 : ta = php_localtime_r(&t, &tmbuf);
53 3 : if (!ta) {
54 0 : RETURN_FALSE;
55 : }
56 :
57 3 : jdate = GregorianToSdn(ta->tm_year+1900, ta->tm_mon+1, ta->tm_mday);
58 :
59 3 : RETURN_LONG(jdate);
60 : }
61 : /* }}} */
62 :
63 : /* {{{ proto int jdtounix(int jday)
64 : Convert Julian Day to UNIX timestamp */
65 : PHP_FUNCTION(jdtounix)
66 3 : {
67 : zval *jday;
68 : long uday;
69 :
70 3 : if ((ZEND_NUM_ARGS()!= 1) || (zend_get_parameters(ht, 1, &jday) != SUCCESS)) {
71 0 : WRONG_PARAM_COUNT;
72 : }
73 :
74 3 : convert_to_long(jday);
75 :
76 3 : uday = Z_LVAL_P(jday) - 2440588 /* J.D. of 1.1.1970 */;
77 :
78 3 : if(uday<0) RETURN_FALSE; /* before beginning of unix epoch */
79 3 : if(uday>24755) RETURN_FALSE; /* behind end of unix epoch */
80 :
81 3 : RETURN_LONG(uday*24*3600);
82 : }
83 : /* }}} */
84 :
85 : /*
86 : * Local variables:
87 : * tab-width: 4
88 : * c-basic-offset: 4
89 : * End:
90 : * vim600: sw=4 ts=4 fdm=marker
91 : * vim<600: sw=4 ts=4
92 : */
|