Linux kernel provides time_to_tm() (see here):
/**
* time_to_tm - converts the calendar time to local broken-down time
*
* @totalsecs the number of seconds elapsed since 00:00:00 on January 1, 1970,
* Coordinated Universal Time (UTC).
* @offset offset seconds adding to totalsecs.
* @result pointer to struct tm variable to receive broken-down time
*/
void time_to_tm(time_t totalsecs, int offset, struct tm *result)
According to description, tm will be local broken-down time.
Thus I understand tm will respect my local time zone and DST.
If this correct, I don’t see it in the code.
Maybe argument offset should be used to “provide” local time zone and DST?
UPDATE
Following this question, thus using sys_tz in conjunction with time_to_tm() we can get “true” local time?
AFAIK, localtime notation belongs to userland. For example DST is defined in specially compiled configuration files per time zone.
I’m confused. What is the meaning of sys_tz in kernel than?
The kernel doesn’t know or care about timezones or DST, everything it does is in terms of seconds since the epoch. Timezones and DST are handled by libraries in user mode, which check your environment variables and can scan the timezone files.
This function is not callable by the end user — there’s no system call interface to it. It’s just used internally within the kernel. If you look in the cross-reference (http://lxr.free-electrons.com/ident?v=2.6.33;i=time_to_tm), the only place it’s currently called from is the FAT filesystem driver. It is indeed used to adjust for timezone; it was done to support the
tzoffmount option.