[GH-ISSUE #110] dcterms created and modified timestamps incorrect #89

Closed
opened 2026-05-05 11:38:31 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @patrick-rotsaert on GitHub (Jul 14, 2017).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/110

Originally assigned to: @jmcnamara on GitHub.

In core.c the static function _localtime_to_iso8601_date is used to convert time_t to ISO8601 timestamp.
The time_t (epoch UTC) is first converted to local time struct tm and then to a string, but with a Z-suffix. This is wrong. In order to use the Z-suffix, the time stamp must be UTC time, not local.
To convert the time_t to a UTC time struct tm, the gmtime function could be used instead of localtime.

I'd suggest to change the function to:

static void
_gmtime_to_iso8601_date(time_t *timer, char *str, size_t size)
{
    struct tm *tmp_gmtime;
    time_t current_time = time(NULL);    
    if (*timer)
        tmp_gmtime = gmtime(timer);
    else
        tmp_gmtime = gmtime(&current_time);
    strftime(str, size - 1, "%Y-%m-%dT%H:%M:%SZ", tmp_gmtime);
}
Originally created by @patrick-rotsaert on GitHub (Jul 14, 2017). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/110 Originally assigned to: @jmcnamara on GitHub. In core.c the static function _localtime_to_iso8601_date is used to convert `time_t` to ISO8601 timestamp. The `time_t` (epoch UTC) is first converted to local time `struct tm` and then to a string, but with a Z-suffix. This is wrong. In order to use the Z-suffix, the time stamp must be UTC time, not local. To convert the `time_t` to a UTC time `struct tm`, the `gmtime` function could be used instead of `localtime`. I'd suggest to change the function to: ```C static void _gmtime_to_iso8601_date(time_t *timer, char *str, size_t size) { struct tm *tmp_gmtime; time_t current_time = time(NULL); if (*timer) tmp_gmtime = gmtime(timer); else tmp_gmtime = gmtime(&current_time); strftime(str, size - 1, "%Y-%m-%dT%H:%M:%SZ", tmp_gmtime); } ```
gitea-mirror 2026-05-05 11:38:31 -06:00
Author
Owner

@jmcnamara commented on GitHub (Jul 24, 2017):

Hi,

Thanks. I had a similar issue in the Perl and Python versions as well but forgot to fix it in the C version.

I'll look into it.

Thanks,

John

<!-- gh-comment-id:317472317 --> @jmcnamara commented on GitHub (Jul 24, 2017): Hi, Thanks. I had a similar issue in the Perl and Python versions as well but forgot to fix it in the C version. I'll look into it. Thanks, John
Author
Owner

@jmcnamara commented on GitHub (Jul 24, 2017):

Fixed in version 0.7.1.

Thanks for the report.

<!-- gh-comment-id:317541570 --> @jmcnamara commented on GitHub (Jul 24, 2017): Fixed in version 0.7.1. Thanks for the report.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#89
No description provided.