Time zones (again)

Robert Helling helling at atdotde.de
Tue Jun 21 13:43:04 PDT 2016


Hi,

> Am 21.06.2016 um 17:18 schrieb Linus Torvalds <torvalds at linux-foundation.org>:
> 
> 
> On Jun 21, 2016 01:16, "Robert Helling" <helling at atdotde.de <mailto:helling at atdotde.de>> wrote:
> >
> > What I propose is upon initialization setTimezoneSpec
> > once with UTC then for conversion functions there is no
> > further need to explicitly state time zone specifications
> 
> I don't think we can do that.
> 
> There are several cases where we do want local time, notably when we ask the system "what time is it now". Then we want the hours, minutes and seconds as they are locally, not as they are in UTC.
> 
> 
100% ACK
> We then convert the end result into "what would that be in UTC", but to initially get the current time field we need local time conversion.
> 
> 
ACK.
> Globally setting "we want UTC" might also screw up other things - I could imagine things like file open dialogs showing odd times etc
> 
> 
I think I was really talking about the Qt data structure as those are related to the UI. For example, to set the start time of a dive, we have a QTimeEdit widget. There the user enters something like „5:00pm“ or „17:00“. The widget delivers the result as a Time and eventually (together with a QDateEdit) we obtain a QDateTime. The user never saw any time zone information, just 5pm. But internally, this value goes into dive->when which is a time_t and so far, as far as I can tell, our rule for conversion of a dive starting at 5pm (local time of the dive) into time_t was: Since we don’t want to know about time zones, for the purpose of the conversion, the time_t value for us is „number of seconds between 1 Jan 1970 0:00 UTC and whatever day 5pm UTC“.

QDateTime is time zone aware and by default  it lives in the default system time zone. So what we do is compute the number of seconds between 1 Jan 1970 0:00 UTC and some date 5pm system time zone and the subtract gettimezoneoffset() which is the difference between some date 5pm UTC and 5pm system time zone.

All I am proposing is to tell the QDateTime (that corresponds to the QTimeEdit) right after its creation (in an OO sense) that it should pretend to be in UTC. Then we would not need to do the gettimezoneoffset() gymnastics.

We would of course then have to do it, as you and I said, when the current time comes into play. But as far as I can see these places are much fewer.

I am not proposing to set the total subsurface time zone (what I called system time zone) to UTC. I just want it for QDateTime objects that are related to displaying things like „5pm“ to the user.
> But maybe I misunderstand what you were proposing. But I think the UTC thing needs to be done per operation, not set once at init time.
> 
> 
I didn’t mean init of subsurface. I meant init of QDateTime.

Best
Robert

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20160621/b8d06143/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20160621/b8d06143/attachment.sig>


More information about the subsurface mailing list