summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-09-13 17:38:35 (GMT)
committerGuido van Rossum <guido@python.org>1995-09-13 17:38:35 (GMT)
commit8d8c1eeed7fa7749f8247d1b5172acbb033f87ac (patch)
tree406f235b46eea22273f887787f7442c93ead04a5 /Modules
parent26ee80947ed9a2aaa4f467e5337b7d60f6b21637 (diff)
downloadcpython-8d8c1eeed7fa7749f8247d1b5172acbb033f87ac.zip
cpython-8d8c1eeed7fa7749f8247d1b5172acbb033f87ac.tar.gz
cpython-8d8c1eeed7fa7749f8247d1b5172acbb033f87ac.tar.bz2
added time.strftime()
Diffstat (limited to 'Modules')
-rw-r--r--Modules/timemodule.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index f773835..ba2b700 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 */
};