summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-09-13 17:38:35 +0000
committerGuido van Rossum <guido@python.org>1995-09-13 17:38:35 +0000
commit7d800bf5db6fb004844a11c1d96bc0fa84160db3 (patch)
tree12e0bb83e53b13702e0c189297623d0efdb7025b
parentc46f18e58037a945d7464d988971f9ae17f10886 (diff)
downloadcpython-7d800bf5db6fb004844a11c1d96bc0fa84160db3.tar.gz
added time.strftime()
-rw-r--r--Modules/timemodule.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index f7738354cd..ba2b700dfc 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -179,6 +179,53 @@ gettmarg(args, p)
return 1;
}
+#ifdef HAVE_STRFTIME
+static object *
+time_strftime(self, args)
+ object *self;
+ object *args;
+{
+ struct tm buf;
+ const char *fmt;
+ char *outbuf = 0;
+ int i;
+
+ if (!PyArg_ParseTuple(args, "s(iiiiiiiii)",
+ &fmt,
+ &(buf.tm_year),
+ &(buf.tm_mon),
+ &(buf.tm_mday),
+ &(buf.tm_hour),
+ &(buf.tm_min),
+ &(buf.tm_sec),
+ &(buf.tm_wday),
+ &(buf.tm_yday),
+ &(buf.tm_isdst)))
+ return NULL;
+ if (buf.tm_year >= 1900)
+ buf.tm_year -= 1900;
+ buf.tm_mon--;
+ buf.tm_wday = (buf.tm_wday + 1) % 7;
+ buf.tm_yday--;
+ /* I hate these functions that presume you know how big the output */
+ /* will be ahead of time... */
+ for (i = 1024 ; i < 8192 ; i += 1024) {
+ outbuf = malloc(i);
+ if (outbuf == NULL) {
+ return err_nomem();
+ }
+ if (strftime(outbuf, i-1, fmt, &buf) != 0) {
+ object *ret;
+ ret = newstringobject(outbuf);
+ free(outbuf);
+ return ret;
+ }
+ free(outbuf);
+ }
+ return err_nomem();
+}
+#endif /* HAVE_STRFTIME */
+
static object *
time_asctime(self, args)
object *self;
@@ -233,6 +280,9 @@ static struct methodlist time_methods[] = {
{"asctime", time_asctime},
{"ctime", time_ctime},
{"mktime", time_mktime},
+#ifdef HAVE_STRFTIME
+ {"strftime", time_strftime},
+#endif
{NULL, NULL} /* sentinel */
};