chiark / gitweb /
Extract Subversion ignore data.
[getdate-python] / module.c
CommitLineData
6f110c11 1#include <Python.h>
2#include "getdate.h"
3
4static PyObject *meth_getdate(PyObject *me, PyObject *arg, PyObject *kw)
5{
6 time_t now, t;
7 int tnow = -1;
8 char *p;
9 static char *kwlist[] = { "string", "now", 0 };
10
11 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s|i:getdate", kwlist,
12 &p, &tnow))
13 return (0);
14 if (tnow != -1) now = tnow;
15 if ((t = get_date(p, (tnow == -1) ? 0 : &now)) == (time_t)-1) {
16 PyErr_SetString(PyExc_SyntaxError, "Bad time string");
17 return (0);
18 }
19 return (PyInt_FromLong(t));
20}
21
22static PyMethodDef methods[] = {
23 { "getdate", (PyCFunction)meth_getdate, METH_VARARGS | METH_KEYWORDS,
24 "getdate(STRING, now = time.time()) -> TIME" },
25 { 0 }
26};
27
28void initgetdate(void) { Py_InitModule("getdate", methods); }
29