need "yy-ddd-hh:mm:ss ==> (time_t) clock" converter

Tim W Smith ts at cup.portal.com
Mon Feb 18 04:54:53 AEST 1991


If your standard libraries have a seconds to date string converter,
then there is a simple way to convert the other way.

	1. Get rough lower and upper bounds on the answer, such
	as YEAR * 365 * 24 * 3600 and (YEAR+1) * 366 * 24 * 3600.

	2. Write a function that compares two dates in string form
	and determines which is first.

	3. Do a binary search of the 3e6 possible values between
	the bounds determined in step #1, using the library routine
	that converts a time from seconds to a date string and
	the function your wrote in step #2.

With this method, you don't have to know about leap years, or other
funny things.  For example, if the next release of the library for
your system knows about certain leap seconds, all you have to do
is relink, and they your code knows about them too.

						Tim Smith



More information about the Comp.lang.c mailing list