1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
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]) U
28 : Convert UNIX timestamp to Julian Day */
29 : PHP_FUNCTION(unixtojd)
30 3 : {
31 : time_t timestamp;
32 : long jdate, t;
33 : struct tm *ta, tmbuf;
34 :
35 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) == FAILURE) {
36 0 : return;
37 : }
38 :
39 3 : if (ZEND_NUM_ARGS()) {
40 3 : timestamp = (time_t) t;
41 : } else {
42 0 : timestamp = time(NULL);
43 : }
44 :
45 3 : if (timestamp < 0) {
46 0 : RETURN_FALSE;
47 : }
48 :
49 3 : ta = php_localtime_r(×tamp, &tmbuf);
50 3 : if (!ta) {
51 0 : RETURN_FALSE;
52 : }
53 :
54 3 : jdate = GregorianToSdn(ta->tm_year+1900, ta->tm_mon+1, ta->tm_mday);
55 3 : RETURN_LONG(jdate);
56 : }
57 : /* }}} */
58 :
59 : /* {{{ proto int jdtounix(int jday) U
60 : Convert Julian Day to UNIX timestamp */
61 : PHP_FUNCTION(jdtounix)
62 3 : {
63 : long uday, jday;
64 :
65 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &jday) != SUCCESS) {
66 0 : return;
67 : }
68 :
69 3 : uday = jday - 2440588; /* J.D. of 1.1.1970 */
70 3 : if(uday<0) RETURN_FALSE; /* before beginning of unix epoch */
71 3 : if(uday>24755) RETURN_FALSE; /* behind end of unix epoch */
72 :
73 3 : RETURN_LONG(uday*24*3600);
74 : }
75 : /* }}} */
76 :
77 : /*
78 : * Local variables:
79 : * tab-width: 4
80 : * c-basic-offset: 4
81 : * End:
82 : * vim600: sw=4 ts=4 fdm=marker
83 : * vim<600: sw=4 ts=4
84 : */
|