Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!ginosko!uunet!mcsun!ukc!warwick!alfie From: alfie@cs.warwick.ac.uk (Nick Holloway) Newsgroups: comp.unix.questions Subject: Re: Inverse for localtime(). Keywords: localtime(), ctime, struct tm Message-ID: <1967@diamond.warwick.ac.uk> Date: 29 Aug 89 15:33:15 GMT References: <20750@sequent.UUCP> Sender: news@warwick.ac.uk Reply-To: alfie@cs.warwick.ac.uk (Nick Holloway) Organization: Computer Science, Warwick University, UK Lines: 23 In article <20750@sequent.UUCP> paulr@sequent.UUCP (Paul Reger) writes: > A while back someone asked if there was such a thing as an inverse > localtime() function. (localtime() maps a time_t * to a struct *tm). > I guess there isn't one, so I wrote one (The problem interested me > since it seemed natural for one to exist.). Here it is: > [ ... code ... ] SunOS 4.x (possibly also 3.x) has a routine called timelocal(), which takes (struct tm*) and returns a time_t. If there is no valid time, (you give 1:30am, on the day when the clock goes forward an hour at 1:00am) a value of -1 is returned. There is also a routine timegm(), which is to timegm() as timelocal() is to localtime(). These also only uses the tm_hour, tm_min, tm_sec, tm_mday, tm_mon, tm_year fields in the structure [discovered by experimentation]. I thought it was natural for there to be an inverse to localtime(). Does this mean that this is another useful SunOS'ism [like statfs(2)] only available on Suns, or will this spread to other platforms? Alfie -- In real life: Nick Holloway