Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!portal!cup.portal.com!ts From: ts@cup.portal.com (Tim W Smith) Newsgroups: comp.lang.c Subject: Re: need "yy-ddd-hh:mm:ss ==> (time_t) clock" converter Message-ID: <39375@cup.portal.com> Date: 17 Feb 91 17:54:53 GMT References: <368@bria> <6586@gssc.UUCP> <2323@stsci.EDU> Organization: The Portal System (TM) Lines: 20 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