diff options
author | 2025-05-13 18:34:32 +0200 | |
---|---|---|
committer | 2025-05-13 18:34:32 +0200 | |
commit | cb76e4da84c61609c13e84c922f14a27b8348a36 (patch) | |
tree | 6f0057efd11780ec38da6e8b686726f51bd10f30 /cython/plist_util.c | |
parent | d7fe479707af57aeedf7e41c08e7fb698cd2e2a3 (diff) | |
download | libplist-cb76e4da84c61609c13e84c922f14a27b8348a36.tar.gz libplist-cb76e4da84c61609c13e84c922f14a27b8348a36.tar.bz2 |
Add plist_new_unix_date, plist_get_unix_date_val, plist_set_unix_date_val functions
These functions work with int64_t values representing a UNIX timestamp instead
of using the 'MAC epoch'. They should be used instead of plist_new_date,
plist_get_date_val, and plist_set_date_val, which are now marked deprecated
and might be removed in a future version of libplist.
Diffstat (limited to 'cython/plist_util.c')
-rw-r--r-- | cython/plist_util.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/cython/plist_util.c b/cython/plist_util.c index 4f922e5..27084fa 100644 --- a/cython/plist_util.c +++ b/cython/plist_util.c @@ -3,13 +3,11 @@ #include <time.h> #include <datetime.h> -void datetime_to_ints(PyObject* obj, int32_t* sec, int32_t* usec) { +int64_t datetime_to_timestamp(PyObject* obj) { PyDateTime_IMPORT; if (!PyDateTime_Check(obj)) { - PyErr_SetString(PyExc_ValueError,"Expected a datetime"); - sec = NULL; - usec = NULL; - return; + PyErr_SetString(PyExc_ValueError,"Expected a datetime"); + return 0; } struct tm t; memset(&t, 0, sizeof(t)); @@ -19,22 +17,21 @@ void datetime_to_ints(PyObject* obj, int32_t* sec, int32_t* usec) { t.tm_mday = PyDateTime_GET_DAY(obj); t.tm_mon = PyDateTime_GET_MONTH(obj)-1; t.tm_year = PyDateTime_GET_YEAR(obj)-1900; - *sec = (int32_t)mktime(&t); - *usec = PyDateTime_DATE_GET_MICROSECOND(obj); + return mktime(&t); } -PyObject* ints_to_datetime(int32_t sec, int32_t usec) { - time_t sec_tt = sec; +PyObject* timestamp_to_datetime(int64_t sec) { + time_t sec_tt = sec; struct tm* t = gmtime(&sec_tt); if(t){ - PyDateTime_IMPORT; - return PyDateTime_FromDateAndTime(t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, usec); + PyDateTime_IMPORT; + return PyDateTime_FromDateAndTime(t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, 0); } - return NULL; + return NULL; } int check_datetime(PyObject* ob) { - if(ob){ - PyDateTime_IMPORT; - return PyDateTime_Check(ob); - } - return 0; + if(ob){ + PyDateTime_IMPORT; + return PyDateTime_Check(ob); + } + return 0; } |