|
March 2004
Shell Corner: Dateplus: Incremented, Decremented, Repeated, and Other Tools
Hosted by Ed Schaefer
This month, Bob Orlando shares his standalone "C" and awk utilities for processing and adjusting dates.
Dateplus: Incremented, Decremented, Repeated, and Other Tools
by Bob Orlando
dateplus.c
dateplus.awk
I've always been fascinated by date routines. That fascination, coupled with the frenzied push at the end of the last century to make everything Y2K-compliant, prompted me to develop some useful date routines written in "C". My objective was not to develop libraries or functions that could be easily incorporated into other "C" programs there are plenty of "C" date libraries out there already rather, my objective was to develop a standalone, highly portable program that returned a variety of frequently requested and adjusted dates, suitable for Bourne shell scripts.
Bourne shell scripts were my target primarily because in our shop, batch production scripts were written in Bourne. The policy was Korn for interactive use; Bourne for batch. Besides, anything written in Bourne runs in Korn shell (and practically any other shell, as well). Korn has many fine date tools and features ($SECONDS is one of which I am particularly fond for calculating process elapsed time), but those capabilities were not available to Bourne scripts. Hence, dateplus.c was Bourne born.
Date arithmetic in Unix is, at best, an inconsistent mess. There are myriad methods in Awk, Perl, TCL, etc., for manipulating time in Unix.
|