Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: $SECS



> Any chance we could have some documentation for this? I take it that the
> first argument is the strftime format and the second is the number of
> seconds since the epoch. Would be nice if the second argument was
> optional and defaulted to the current time.

With the following patch, you can do

strftime "%d-%m-%y" $SECS

Is it worth having the second argument be optional?  Is SECS too generic
a name?

Index: Src/Modules/datetime.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/datetime.c,v
retrieving revision 1.3
diff -u -r1.3 datetime.c
--- Src/Modules/datetime.c	27 Aug 2002 21:10:34 -0000	1.3
+++ Src/Modules/datetime.c	28 Sep 2003 16:16:56 -0000
@@ -63,10 +63,21 @@
     return 0;
 }
 
+static zlong
+getcurrentsecs()
+{
+    return (zlong) time(NULL);
+}
+
 static struct builtin bintab[] = {
     BUILTIN("strftime",    0, bin_strftime,    2,   2, 0, NULL, NULL),
 };
 
+static struct paramdef patab[] = {
+    PARAMDEF("SECS", PM_INTEGER|PM_SPECIAL|PM_READONLY,
+		    NULL, NULL, &getcurrentsecs, NULL),
+};
+
 /**/
 int
 setup_(Module m)
@@ -78,7 +89,9 @@
 int
 boot_(Module m)
 {
-    return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+    return !(addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) |
+	     addparamdefs(m->nam, patab, sizeof(patab)/sizeof(*patab))
+	    );
 }
 
 /**/



Messages sorted by: Reverse Date, Date, Thread, Author