Permalink
Browse files

ENH: Add get_mktime function to support multiple platforms.

  • Loading branch information...
1 parent 260061c commit c401afd379e6a46ae33330fe782ef2b31ef7b686 @87 committed Feb 20, 2012
Showing with 31 additions and 0 deletions.
  1. +31 −0 numpy/core/src/multiarray/datetime_strings.c
@@ -122,6 +122,37 @@ get_gmtime(NPY_TIME_T *ts, struct tm *tms)
}
/*
+ * Wraps `mktime` functionality for multiple platforms. This
+ * converts a local time struct to an UTC value.
+ *
+ * Returns timestamp on success, -1 on failure.
+ */
+static NPY_TIME_T
+get_mktime(struct tm *tms)
+{
+ char *func_name = "<unknown>";
+ NPY_TIME_T ts;
+#if defined(NPY_MINGW_USE_CUSTOM_MSVCR)
+ ts = _mktime64(tms);
+ if (ts == -1) {
+ func_name = "_mktime64";
+ goto fail;
+ }
+#else
+ ts = mktime(tms)
+ if (ts == -1) {
+ func_name = "mktime";
+ goto fail;
+ }
+#endif
+ return ts;
+fail:
+ PyErr_Format(PyExc_OSError, "Failed to use '%s' to convert "
+ "local time to UTC", func_name);
+ return -1;
+}
+
+/*
* Converts a datetimestruct in UTC to a datetimestruct in local time,
* also returning the timezone offset applied.
*

0 comments on commit c401afd

Please sign in to comment.