flat assembler
Message board for the users of flat assembler.

Index > Linux > How to obtain the current local time offset?

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 30 Jun 2012, 12:02
sys_time returns the UTC time.
The question is how to get the current timezone bias?

According to the documentation sys_gettimeofday should return the time and timezone information, but on my tests it returns always 0 as a timezone bias and UTC time as a time.

So, how to obtain the proper timezone information, using system calls?

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9


Last edited by JohnFound on 02 Jul 2012, 16:22; edited 2 times in total
Post 30 Jun 2012, 12:02
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 02 Jul 2012, 10:47
As far as i know, its not possible. The way "date" seems to do it is by using the clock_gettime(CLOCK_REALTIME..) and then reading /etc/localtime in order to get offset info.

I tested - and I also get 0/0 for timezone info as a return from gettimeofday.. so yeah.. i think you may have to open /etc/localtime and figure it out from there (not sure what the format of that file is - but its probably described somewhere out there, seems to be binary rather than just a text/config file).
Post 02 Jul 2012, 10:47
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 02 Jul 2012, 12:29
Thanks. I will search this file format. (Or can try to reverse it - in Linux it is often easier, than searching for documentation. Very Happy)

IMHO, it is bad idea to read different config files from inside the library function, but I can read this file on start up and keep the data in a variable.

Thanks for this information.
Post 02 Jul 2012, 12:29
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Jul 2012, 14:29
Isn't an option just using libc (or whatever library providing the function)? The problem is what if some distro doesn't work that way (using /etc/localtime I mean).*

BTW, reading the file at startup only might not be a good idea, if the user changes the config while your app is still running I think it should start reporting the same time as the rest of the system.
Post 02 Jul 2012, 14:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20629
Location: In your JS exploiting you and your system
revolution 02 Jul 2012, 16:00
LocoDelAssembly wrote:
BTW, reading the file at startup only might not be a good idea, if the user changes the config while your app is still running I think it should start reporting the same time as the rest of the system.
Yes, I think this is quite important because ...
  1. User sets TZ to desired value
  2. User starts JohnFound's program
  3. User hibernates system
  4. User flies to a different TZ
  5. User starts system
  6. User sets TZ to new value
  7. User sees JohnFound's program displaying wrong time
Post 02 Jul 2012, 16:00
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 02 Jul 2012, 16:40
LocoDelAssembly, I want to use libc as little as possible and possibly to not use it at all.

You and revolution, both are right that reading once is not a good idea as well. I will think about it. At least searching the timezone information is not so often used functions, so I can make it simply to read the file (2104bytes) on my system Confused What these people keep in this file? A road map?
Post 02 Jul 2012, 16:40
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 02 Jul 2012, 17:23
OK, I found the file format. It is described in "man tzfile". The file format keeps information about all local time changes sinse 1970year, that is why it is so big.
Anyway, the format is relatively simple and I will make some procedure to read it.

Thanks for pointing me in the right direction.
Post 02 Jul 2012, 17:23
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.