mujtaba
mujtaba

Reputation: 215

does time function handles time zone changes when the application is running

while (utc_service_status.dwCurrentState == SERVICE_RUNNING){

    time(&secs);
    tptr1 = localtime( &secs );
    local_secs = mktime( tptr1 );
    tptr2 = gmtime( &secs );
    tptr2->tm_isdst = -1;
    gmt_secs = mktime( tptr2 );
    diff_secs = (local_secs - gmt_secs);
    *utc_bias = diff_secs/60;
}

This is the sample code.when this service is running am changing the timezone.

Upvotes: 0

Views: 144

Answers (1)

Tim Pierce
Tim Pierce

Reputation: 5664

Technically, this depends on your implementation of localtime and how it chooses to do time zone conversion.

The manual page for localtime(3) on Linux says:

Time zone adjustments are performed as specified by the TZ environment variable (see tzset(3)). The function localtime() uses tzset(3) to initialize time conversion information, if tzset(3) has not already been called by the process.

It also adds this note, under "BUGS":

The C Standard provides no mechanism for a program to modify its current local timezone setting, and the POSIX-standard method is not reentrant. (However, thread-safe implementations are provided in the POSIX threaded environment.)

So this seems to suggest "probably not." You might find it useful to test yourself, with a program that calls localtime, then changes the TZ environment variable (and/or the /etc/timezone symlink) and calls localtime again.

Upvotes: 1

Related Questions