ref: 4cd4b8255378a0c2f28da7a9cf1ab0925c88f5a1
parent: 2dfe66d72f23e9e4cf24cd3634ebe786c68440e3
author: google <[email protected]>
date: Sat Sep 1 21:06:38 EDT 2012
Fixes previous commit: dc3f9d299b40
--- a/sys/src/cmd/date.c
+++ b/sys/src/cmd/date.c
@@ -3,18 +3,20 @@
int uflg, nflg, iflg, tflg;
+static
+void
+numstr(char *cp, int n)
+{
+ cp[0] = (n/10)%10 + '0';
+ cp[1] = n%10 + '0';
+}
+
char*
isodate(Tm *t)
{
- static char c[10+14+1]; /* leave room to append isotime */
-
- ct_numb(c, t->year / 100 + 119);
- ct_numb(c+2, t->year % 100 + 100);
- c[4] = '-';
- ct_numb(c+5, t->mon + 101);
- c[7] = '-';
- ct_numb(c+8, t->mday + 100);
- c[10] = 0;
+ static char c[25]; /* leave room to append isotime */
+ snprint(c, 11, "%04d-%02d-%02d",
+ t->year +1900, t->mon + 1, t->mday);
return c;
}
@@ -24,13 +26,9 @@
int tz;
char *c, *d;
d = isodate(t);
- c = d + 10; /* append to isodate */
- c[0] = 'T';
- ct_numb(c+1, t->hour+100);
- c[3] = ':';
- ct_numb(c+4, t->min+100);
- c[6] = ':';
- ct_numb(c+7, t->sec+100);
+ c = d+10;
+ snprint(c, 10, "T%02d:%02d:%02d",
+ t->hour, t->min, t->sec); /* append to isodate */
tz = t->tzoff / 60;
if(t->tzoff) {
/* localtime */
@@ -40,9 +38,7 @@
c[9] = '-';
tz = -tz;
}
- ct_numb(c+10, tz / 60 + 100);
- ct_numb(c+12, tz % 60 + 100);
- c[14] = 0;
+ snprint(c+10, 5, "%02d%02d", tz / 60, tz % 60);
} else {
c[9] = 'Z';
c[10] = 0;