9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] tm2sec()
@ 2013-08-10 20:02 cinap_lenrek
  2013-08-10 20:09 ` erik quanstrom
  0 siblings, 1 reply; 3+ messages in thread
From: cinap_lenrek @ 2013-08-10 20:02 UTC (permalink / raw)
  To: 9fans

noticed that atime on files served by dossrv is wrong.

dossrv builds a Tm structure with Tm.zone=="" and
passes it to tm2sec().

there are other servers, like zipfs using similar code
which i assume would also return wrong time as well but
havnt tested it.

the problem seems to be this:

tm2sec() ignores Tm.zone if its not one of the ones specified
in the timezone variabe. but the manual states:

Tm2sec converts a broken-down time to seconds since the
start of the epoch.  It ignores wday, and assumes the local
time zone if zone is not GMT.

as Tm.zone is not explicitely set to "GMT", i think
tm2sec() should specially handle the Tm.zone==""
case the following way:

	/*
	 * Only handles zones mentioned in /env/timezone,
	 * but things get too ambiguous otherwise.
	 */
	if(strcmp(tm->zone, timezone.stname) == 0)
		secs -= timezone.stdiff;
	else if(strcmp(tm->zone, timezone.dlname) == 0)
		secs -= timezone.dldiff;
	else if(tm->zone[0] == 0){
		secs -= timezone.dldiff;
		for(p = timezone.dlpairs; *p; p += 2)
			if(secs >= p[0] && secs < p[1])
				break;
		if(*p == 0){
			secs += timezone.dldiff;
			secs -= timezone.stdiff;
		}
	}

so basically, if Tm.zone=="", we assume that the local timezone
applies (as stated in the manual). we check if the time falls
in a daylight saving period, otherwise assume normal time
offset. (this should be the reverse of what localtime() does).

this code seems to work ok for dossrv, but i'm not sure of any
unintended side effects.

--
cinap



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] tm2sec()
  2013-08-10 20:02 [9fans] tm2sec() cinap_lenrek
@ 2013-08-10 20:09 ` erik quanstrom
  2013-08-10 20:18   ` cinap_lenrek
  0 siblings, 1 reply; 3+ messages in thread
From: erik quanstrom @ 2013-08-10 20:09 UTC (permalink / raw)
  To: 9fans

> Tm2sec converts a broken-down time to seconds since the
> start of the epoch.  It ignores wday, and assumes the local
> time zone if zone is not GMT.
>
> as Tm.zone is not explicitely set to "GMT", i think
> tm2sec() should specially handle the Tm.zone==""
> case the following way:

shouldn't it assume GMT?  epoch is in GMT, and file times
(as written to the disk) should be in GMT so that conversion
to any time zone for display will not be incorrect.

- erik



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] tm2sec()
  2013-08-10 20:09 ` erik quanstrom
@ 2013-08-10 20:18   ` cinap_lenrek
  0 siblings, 0 replies; 3+ messages in thread
From: cinap_lenrek @ 2013-08-10 20:18 UTC (permalink / raw)
  To: 9fans

dos, windows and dossrv store timestamps in local time on disk.
which is indeed crazy, but that seems to be the standard for fat.

--
cinap



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-10 20:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-10 20:02 [9fans] tm2sec() cinap_lenrek
2013-08-10 20:09 ` erik quanstrom
2013-08-10 20:18   ` cinap_lenrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).