home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.unix
- From: arnold@skeeve.atl.ga.us (Arnold Robbins)
- Subject: v26i235: strftime-3.0 - still more strftime(3) and date(1), Patch01
- Sender: unix-sources-moderator@efficacy.home.vix.com
- Approved: vixie@efficacy.home.vix.com
-
- Submitted-By: arnold@skeeve.atl.ga.us (Arnold Robbins)
- Posting-Number: Volume 26, Issue 235
- Archive-Name: strftime-3.0/patch01
-
- This brings it up to 3.1. A bug fix plus a test routine.
-
- Arnold
-
- *** strftime.c.orig Sun May 2 22:09:18 1993
- --- strftime.c Fri May 7 08:47:49 1993
- ***************
- *** 27,32 ****
- --- 27,34 ----
- *
- * Fixes from ado@elsie.nci.nih.gov
- * February 1991, May 1992
- + * Fixes from Tor Lillqvist tor@tik.vtt.fi
- + * May, 1993
- */
-
- #ifndef GAWK
- ***************
- *** 511,517 ****
- simple_wknum = weeknumber(timeptr, 1) + 1;
-
- /*
- ! * With thanks and tip of the hatlo to ado@elsie.nci.nih.gov
- *
- * What day of the week does January 1 fall on?
- * We know that
- --- 513,519 ----
- simple_wknum = weeknumber(timeptr, 1) + 1;
-
- /*
- ! * With thanks and tip of the hatlo to tml@tik.vtt.fi
- *
- * What day of the week does January 1 fall on?
- * We know that
- ***************
- *** 518,529 ****
- * (timeptr->tm_yday - jan1.tm_yday) MOD 7 ==
- * (timeptr->tm_wday - jan1.tm_wday) MOD 7
- * and that
- ! * jan1.tm_yday == 1
- * and that
- * timeptr->tm_wday MOD 7 == timeptr->tm_wday
- * from which it follows that. . .
- */
- ! jan1day = (timeptr->tm_yday - 1) % 7 - timeptr->tm_wday;
- if (jan1day < 0)
- jan1day += 7;
-
- --- 520,531 ----
- * (timeptr->tm_yday - jan1.tm_yday) MOD 7 ==
- * (timeptr->tm_wday - jan1.tm_wday) MOD 7
- * and that
- ! * jan1.tm_yday == 0
- * and that
- * timeptr->tm_wday MOD 7 == timeptr->tm_wday
- * from which it follows that. . .
- */
- ! jan1day = timeptr->tm_wday - (timeptr->tm_yday % 7);
- if (jan1day < 0)
- jan1day += 7;
-
- ***************
- *** 589,591 ****
- --- 591,707 ----
- Michal
- ntomczak@vm.ucs.ualberta.ca
- #endif
- +
- + #ifdef TEST_STRFTIME
- +
- + /*
- + * NAME:
- + * tst
- + *
- + * SYNOPSIS:
- + * tst
- + *
- + * DESCRIPTION:
- + * "tst" is a test driver for the function "strftime".
- + *
- + * OPTIONS:
- + * None.
- + *
- + * AUTHOR:
- + * Karl Vogel
- + * Control Data Systems, Inc.
- + * vogelke@c-17igp.wpafb.af.mil
- + *
- + * BUGS:
- + * None noticed yet.
- + *
- + * COMPILE:
- + * cc -o tst -DTEST_STRFTIME strftime.c
- + */
- +
- + /* ADR: I reformatted this to my liking, and deleted some unneeded code. */
- +
- + #ifndef NULL
- + #include <stdio.h>
- + #endif
- + #include <sys/time.h>
- + #include <string.h>
- +
- + #define MAXTIME 132
- +
- + /*
- + * Array of time formats.
- + */
- +
- + static char *array[] =
- + {
- + "(%%A) full weekday name, var length (Sunday..Saturday) %A",
- + "(%%B) full month name, var length (January..December) %B",
- + "(%%C) Century %C",
- + "(%%D) date (%%m/%%d/%%y) %D",
- + "(%%E) Locale extensions (ignored) %E",
- + "(%%H) hour (24-hour clock, 00..23) %H",
- + "(%%I) hour (12-hour clock, 01..12) %I",
- + "(%%M) minute (00..59) %M",
- + "(%%O) Locale extensions (ignored) %O",
- + "(%%R) time, 24-hour (%%H:%%M) %R",
- + "(%%S) second (00..61) %S",
- + "(%%T) time, 24-hour (%%H:%%M:%%S) %T",
- + "(%%U) week of year, Sunday as first day of week (00..53) %U",
- + "(%%V) week of year according to ISO 8601 %V",
- + "(%%W) week of year, Monday as first day of week (00..53) %W",
- + "(%%X) appropriate locale time representation (%H:%M:%S) %X",
- + "(%%Y) year with century (1970...) %Y",
- + "(%%Z) timezone (EDT), or blank if timezone not determinable %Z",
- + "(%%a) locale's abbreviated weekday name (Sun..Sat) %a",
- + "(%%b) locale's abbreviated month name (Jan..Dec) %b",
- + "(%%c) full date (Sat Nov 4 12:02:33 1989)%n%t%t%t %c",
- + "(%%d) day of the month (01..31) %d",
- + "(%%e) day of the month, blank-padded ( 1..31) %e",
- + "(%%h) should be same as (%%b) %h",
- + "(%%j) day of the year (001..366) %j",
- + "(%%k) hour, 24-hour clock, blank pad ( 0..23) %k",
- + "(%%l) hour, 12-hour clock, blank pad ( 0..12) %l",
- + "(%%m) month (01..12) %m",
- + "(%%p) locale's AM or PM based on 12-hour clock %p",
- + "(%%r) time, 12-hour (same as %%I:%%M:%%S %%p) %r",
- + "(%%u) ISO 8601: Weekday as decimal number [1 (Monday) - 7] %u",
- + "(%%v) VAX date (dd-bbb-YYYY) %v",
- + "(%%w) day of week (0..6, Sunday == 0) %w",
- + "(%%x) appropriate locale date representation %x",
- + "(%%y) last two digits of year (00..99) %y",
- + (char *) NULL
- + };
- +
- + /* Main routine. */
- +
- + int
- + main(argc, argv)
- + int argc;
- + char **argv;
- + {
- + long time();
- +
- + char *next;
- + char string[MAXTIME];
- +
- + int k;
- + int length;
- +
- + struct tm *tm;
- +
- + long clock;
- +
- + /* Call the function. */
- +
- + clock = time((long *) 0);
- + tm = localtime(&clock);
- +
- + for (k = 0; next = array[k]; k++) {
- + length = strftime(string, MAXTIME, next, tm);
- + printf("%s\n", string);
- + }
- +
- + exit(0);
- + }
- + #endif /* TEST_STRFTIME */
-