Inverse for localtime().

Nick Holloway alfie at cs.warwick.ac.uk
Wed Aug 30 01:33:15 AEST 1989


In article <20750 at sequent.UUCP> paulr at 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 <alfie at cs.warwick.ac.uk>



More information about the Comp.unix.questions mailing list