From 7f22b32e6359bb1381fc2336b9ec876036eb72a6 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 1 Sep 2012 14:12:29 +0200 Subject: [PATCH] isodate in libc? revert every commit for great justice! --- sys/include/libc.h | 2 -- sys/man/1/date | 6 ----- sys/man/2/ctime | 15 +------------ sys/src/cmd/date.c | 25 +++++++-------------- sys/src/libc/9sys/ctime.c | 47 --------------------------------------- 5 files changed, 9 insertions(+), 86 deletions(-) diff --git a/sys/include/libc.h b/sys/include/libc.h index a16ab4ef4..833a3f50b 100644 --- a/sys/include/libc.h +++ b/sys/include/libc.h @@ -328,8 +328,6 @@ extern double cputime(void); extern long times(long*); extern long tm2sec(Tm*); extern vlong nsec(void); -extern char* isotime(Tm*); -extern char* isodate(Tm*); extern void cycles(uvlong*); /* 64-bit value of the cycle counter if there is one, 0 if there isn't */ diff --git a/sys/man/1/date b/sys/man/1/date index b49d65192..705a95425 100644 --- a/sys/man/1/date +++ b/sys/man/1/date @@ -24,12 +24,6 @@ Report Greenwich Mean Time (GMT) rather than local time. .B -n Report the date as the number of seconds since the epoch, 00:00:00 GMT, January 1, 1970. -.TP -.B -i -Report the date as ISO-8601 without time and timezone suffix. -.TP -.B -t -Report the date as ISO-8601 with time and timezone suffix. .PP The conversion from Greenwich Mean Time to local time depends on the .B $timezone diff --git a/sys/man/2/ctime b/sys/man/2/ctime index 411f2cd65..a4e074343 100644 --- a/sys/man/2/ctime +++ b/sys/man/2/ctime @@ -1,6 +1,6 @@ .TH CTIME 2 .SH NAME -ctime, localtime, gmtime, asctime, tm2sec, timezone, isodate, isotime \- convert date and time +ctime, localtime, gmtime, asctime, tm2sec, timezone \- convert date and time .SH SYNOPSIS .B #include .br @@ -23,12 +23,6 @@ char* asctime(Tm *tm) long tm2sec(Tm *tm) .PP .B -char* isodate(Tm *tm) -.PP -.B -char* isotime(Tm *tm) -.PP -.B /env/timezone .SH DESCRIPTION .I Ctime @@ -90,13 +84,6 @@ if is not .BR GMT . .PP -.I Isotime -converts a broken-down time to a date and timestamp according to ISO-8601 with timezone, and returns a string of up to 24 characters. -.PP -.I Isodate -converts a broken-down time to a datestamp -without timezone, and returns a 10 byte string. -.PP When local time is first requested, the program consults the .B timezone diff --git a/sys/src/cmd/date.c b/sys/src/cmd/date.c index 9d6504b3f..fc2ec5af5 100644 --- a/sys/src/cmd/date.c +++ b/sys/src/cmd/date.c @@ -1,19 +1,17 @@ #include #include -int uflg, nflg, iflg, tflg; +int uflg, nflg; void main(int argc, char *argv[]) { ulong now; - Tm *tm; + ARGBEGIN{ case 'n': nflg = 1; break; case 'u': uflg = 1; break; - case 't': tflg = 1; /* implies -i */ - case 'i': iflg = 1; break; - default: fprint(2, "usage: date [-itun] [seconds]\n"); exits("usage"); + default: fprint(2, "usage: date [-un] [seconds]\n"); exits("usage"); }ARGEND if(argc == 1) @@ -23,17 +21,10 @@ main(int argc, char *argv[]) if(nflg) print("%ld\n", now); - else if(iflg) { - tm = uflg ? gmtime(now) : localtime(now); - if(tflg) - print("%s\n", isotime(tm)); - else - print("%s\n", isodate(tm)); - } else { - if(uflg) - print("%s", asctime(gmtime(now))); - else - print("%s", ctime(now)); - } + else if(uflg) + print("%s", asctime(gmtime(now))); + else + print("%s", ctime(now)); + exits(0); } diff --git a/sys/src/libc/9sys/ctime.c b/sys/src/libc/9sys/ctime.c index a99727225..11340ea41 100644 --- a/sys/src/libc/9sys/ctime.c +++ b/sys/src/libc/9sys/ctime.c @@ -299,50 +299,3 @@ rd_long(char **f, long *p) *p = l; return 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; - return c; -} - -char* -isotime(Tm *t) -{ - 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); - tz = t->tzoff / 60; - if(t->tzoff) { - /* localtime */ - if (t->tzoff > 0) { - c[9] = '+'; - } else { - c[9] = '-'; - tz = -tz; - } - ct_numb(c+10, tz / 60 + 100); - ct_numb(c+12, tz % 60 + 100); - c[14] = 0; - } else { - c[9] = 'Z'; - c[10] = 0; - } - return d; -}