From: Michael Tremer Date: Thu, 6 Oct 2022 12:49:37 +0000 (+0000) Subject: _pakfire: Move PyDateTime_FromTime_t to util X-Git-Tag: 0.9.28~278 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8d67f1de068a6abe4ce6bd06012841d18eac592;p=pakfire.git _pakfire: Move PyDateTime_FromTime_t to util Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/file.c b/src/_pakfire/file.c index a6ed35fce..80fcda63f 100644 --- a/src/_pakfire/file.c +++ b/src/_pakfire/file.c @@ -151,26 +151,6 @@ static int File_set_mode(FileObject* self, PyObject* value) { return 0; } -static PyObject* PyDateTime_FromTime_t(const time_t* t) { - struct tm buffer; - - struct tm* tm = gmtime_r(t, &buffer); - if (!tm) - return NULL; - - PyDateTime_IMPORT; - - return PyDateTime_FromDateAndTime( - 1900 + tm->tm_year, - 1 + tm->tm_mon, - tm->tm_mday, - tm->tm_hour, - tm->tm_min, - tm->tm_sec, - 0 - ); -} - static time_t PyDateTime_AsTime_t(PyObject* value) { if (!PyDateTime_Check(value)) return -1; diff --git a/src/_pakfire/util.c b/src/_pakfire/util.c index e269cf09a..69e20c6d4 100644 --- a/src/_pakfire/util.c +++ b/src/_pakfire/util.c @@ -19,6 +19,7 @@ #############################################################################*/ #include +#include #include #include @@ -141,3 +142,23 @@ ERROR: Py_XDECREF(list); return NULL; } + +PyObject* PyDateTime_FromTime_t(const time_t* t) { + struct tm buffer; + + struct tm* tm = gmtime_r(t, &buffer); + if (!tm) + return NULL; + + PyDateTime_IMPORT; + + return PyDateTime_FromDateAndTime( + 1900 + tm->tm_year, + 1 + tm->tm_mon, + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec, + 0 + ); +} diff --git a/src/_pakfire/util.h b/src/_pakfire/util.h index a8113cb06..e9cf9fe70 100644 --- a/src/_pakfire/util.h +++ b/src/_pakfire/util.h @@ -31,4 +31,6 @@ extern PyObject* performance_index(PyObject* self, PyObject* args); PyObject* PyList_FromPackageList(struct pakfire_packagelist* packagelist); PyObject* PyList_FromFileList(struct pakfire_filelist* filelist); +PyObject* PyDateTime_FromTime_t(const time_t* t); + #endif /* PYTHON_PAKFIRE_UTIL_H */