add %s for number of seconds since the Epoch
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 1 Dec 1990 04:44:02 +0000 (20:44 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 1 Dec 1990 04:44:02 +0000 (20:44 -0800)
SCCS-vsn: lib/libc/string/strftime.3 5.7
SCCS-vsn: lib/libc/string/strftime.c 5.9

usr/src/lib/libc/string/strftime.3
usr/src/lib/libc/string/strftime.c

index 9c0895f..1ff424e 100644 (file)
@@ -3,7 +3,7 @@
 .\"
 .\" %sccs.include.redist.man%
 .\"
 .\"
 .\" %sccs.include.redist.man%
 .\"
-.\"    @(#)strftime.3  5.6 (Berkeley) %G%
+.\"    @(#)strftime.3  5.7 (Berkeley) %G%
 .\"
 .TH STRFTIME 3 "%Q"
 .AT 3
 .\"
 .TH STRFTIME 3 "%Q"
 .AT 3
@@ -125,6 +125,10 @@ is replaced by a tab.
 .B %S
 is replaced by the second as a decimal number (00-60).
 .TP
 .B %S
 is replaced by the second as a decimal number (00-60).
 .TP
+.B %s
+is replaced by the number of seconds since the Epoch, UCT (see
+.IR mktime (3)).
+.TP
 .B %T or %X
 is equivalent to ``%H:%M:%S''.
 .TP
 .B %T or %X
 is equivalent to ``%H:%M:%S''.
 .TP
@@ -156,6 +160,8 @@ is replaced by the time zone name.
 is replaced by ``%''.
 .SH "SEE ALSO"
 date(1), ctime(3), printf(1), printf(3)
 is replaced by ``%''.
 .SH "SEE ALSO"
 date(1), ctime(3), printf(1), printf(3)
+.SH BUGS
+The is no conversion specification for the phase of the moon.
 .SH STANDARDS
 .B Strftime
 conforms to ANSI X3.159-1989 (``ANSI C'').
 .SH STANDARDS
 .B Strftime
 conforms to ANSI X3.159-1989 (``ANSI C'').
index 4bf3100..f7f04af 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strftime.c 5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)strftime.c 5.9 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -96,10 +96,6 @@ _fmt(format, t)
                                if (!_fmt("%m/%d/%y %H:%M:%S", t))
                                        return(0);
                                continue;
                                if (!_fmt("%m/%d/%y %H:%M:%S", t))
                                        return(0);
                                continue;
-                       case 'e':
-                               if (!_conv(t->tm_mday, 2, ' '))
-                                       return(0);
-                               continue;
                        case 'D':
                                if (!_fmt("%m/%d/%y", t))
                                        return(0);
                        case 'D':
                                if (!_fmt("%m/%d/%y", t))
                                        return(0);
@@ -108,6 +104,10 @@ _fmt(format, t)
                                if (!_conv(t->tm_mday, 2, '0'))
                                        return(0);
                                continue;
                                if (!_conv(t->tm_mday, 2, '0'))
                                        return(0);
                                continue;
+                       case 'e':
+                               if (!_conv(t->tm_mday, 2, ' '))
+                                       return(0);
+                               continue;
                        case 'H':
                                if (!_conv(t->tm_hour, 2, '0'))
                                        return(0);
                        case 'H':
                                if (!_conv(t->tm_hour, 2, '0'))
                                        return(0);
@@ -158,6 +158,10 @@ _fmt(format, t)
                                if (!_conv(t->tm_sec, 2, '0'))
                                        return(0);
                                continue;
                                if (!_conv(t->tm_sec, 2, '0'))
                                        return(0);
                                continue;
+                       case 's':
+                               if (!_secs(t))
+                                       return(0);
+                               continue;
                        case 'T':
                        case 'X':
                                if (!_fmt("%H:%M:%S", t))
                        case 'T':
                        case 'X':
                                if (!_fmt("%H:%M:%S", t))
@@ -215,6 +219,20 @@ _fmt(format, t)
        return(gsize);
 }
 
        return(gsize);
 }
 
+static
+_secs(t)
+       struct tm *t;
+{
+       static char buf[15];
+       register time_t s;
+       register char *p;
+
+       s = mktime(t);
+       for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10)
+               *p-- = s % 10 + '0';
+       return(_add(++p));
+}
+
 static
 _conv(n, digits, pad)
        int n, digits;
 static
 _conv(n, digits, pad)
        int n, digits;