Project

General

Profile

Bug #1854

timegm() works incorrect

Added by Roman Strashkin almost 9 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
lib - userland libraries
Start date:
2011-12-04
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

test code:

#include <stdio.h>
#include <time.h>

int main (void) {

    struct tm Tm; 
    time_t time;

    strptime("Sun, 04 Dec 2011 13:09:43 GMT", "%a, %d %b %Y %H:%M:%S %Z", &Tm);
    time = timegm(&Tm);
    printf("Time1: %d\n", time);

    strptime("Sun, 04 Dec 2011 17:09:43 MSK", "%a, %d %b %Y %H:%M:%S %Z", &Tm);
    time = mktime(&Tm);
    printf("Time2: %d\n", time);
}

Result:

# ./test
Time1: 1323018583
Time2: 1323004183

As you can see timegm() returns seconds from the Epoch, with correction to local TZ, that is incorrect.

Result of same code, which compiled and started on Linux:

# ./test
Time1: 1323004183
Time2: 1323004183

History

#1

Updated by Vitaliy Gusev almost 9 years ago

  • Assignee set to Vitaliy Gusev
#2

Updated by Vitaliy Gusev almost 9 years ago

It is a strptime() issue. It does convert to locale's timezone if "GMT" specifier is in format.

#3

Updated by Vitaliy Gusev almost 9 years ago

  • Status changed from New to Closed

WONTFIX

#4

Updated by Vitaliy Gusev almost 9 years ago

As Garrett said "behavior is correct".

Also available in: Atom PDF