]> git.ipfire.org Git - pakfire.git/commitdiff
_pakfire: Move PyDateTime_FromTime_t to util
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Oct 2022 12:49:37 +0000 (12:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Oct 2022 11:19:34 +0000 (11:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/file.c
src/_pakfire/util.c
src/_pakfire/util.h

index a6ed35fce9d7f4ccb19899c05b97a635b0415be1..80fcda63f3396f44497713222e7660b5af23ac68 100644 (file)
@@ -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;
index e269cf09a29225dd1acf962d9effe59d1427f688..69e20c6d4489e1b69cfb658b12b7d8c5a05c01a7 100644 (file)
@@ -19,6 +19,7 @@
 #############################################################################*/
 
 #include <Python.h>
+#include <datetime.h>
 
 #include <errno.h>
 #include <time.h>
@@ -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
+       );
+}
index a8113cb06dffc8654b63f910dd3db0442b0ec0d2..e9cf9fe70ca9c28b59a31f2dbe1fe1eb1bd59439 100644 (file)
@@ -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 */