I
Ilja Booij
Hi all,
I have some trouble with the following:
I'm getting a time string, in YYYY-MM-DD HH:mm:ss format, which I
need to translate into a string with DD-Mon-YYYY HH:mm:ss +HHMM,
where the last part is the timezone offset.
I've tried to do it with the following function. This works for me,
I get +0200 for the timezone part, which makes sense, because we're
on daylight savings time at the moment here in the Netherlands.
However, another user of the same code is located in Australia, he
gets +1100 as timezone offset. It's winter out there now, and at the
moment he's really at +1000. All his other software does it in the
right way. So... what am I doing wrong?
char *date_sql2imap(const char *sqldate)
{
char *last_char;
struct tm tm_localtime, tm_sqldate;
time_t td;
/* we need to get the localtime to get the current timezone */
if (time(&td) == -1) {
trace(TRACE_ERROR, "%s,%s: error getting time()",
__FILE__, __func__);
return IMAP_STANDARD_DATE;
}
tm_localtime = *localtime(&td);
/* parse sqldate */
last_char = strptime(sqldate, "%Y-%m-%d %T", &tm_sqldate);
if (*last_char != '\0') {
trace(TRACE_DEBUG, "%s,%s, error parsing date [%s]",
__FILE__, __func__, sqldate);
strcpy(_imapdate, IMAP_STANDARD_DATE);
return _imapdate;
}
tm_sqldate.tm_gmtoff = tm_localtime.tm_gmtoff;
(void) strftime(_imapdate, IMAP_INTERNALDATE_LEN,
"%d-%b-%Y %T %z", &tm_sqldate);
return _imapdate;
}
Thanks for your time,
Ilja Booij
I have some trouble with the following:
I'm getting a time string, in YYYY-MM-DD HH:mm:ss format, which I
need to translate into a string with DD-Mon-YYYY HH:mm:ss +HHMM,
where the last part is the timezone offset.
I've tried to do it with the following function. This works for me,
I get +0200 for the timezone part, which makes sense, because we're
on daylight savings time at the moment here in the Netherlands.
However, another user of the same code is located in Australia, he
gets +1100 as timezone offset. It's winter out there now, and at the
moment he's really at +1000. All his other software does it in the
right way. So... what am I doing wrong?
char *date_sql2imap(const char *sqldate)
{
char *last_char;
struct tm tm_localtime, tm_sqldate;
time_t td;
/* we need to get the localtime to get the current timezone */
if (time(&td) == -1) {
trace(TRACE_ERROR, "%s,%s: error getting time()",
__FILE__, __func__);
return IMAP_STANDARD_DATE;
}
tm_localtime = *localtime(&td);
/* parse sqldate */
last_char = strptime(sqldate, "%Y-%m-%d %T", &tm_sqldate);
if (*last_char != '\0') {
trace(TRACE_DEBUG, "%s,%s, error parsing date [%s]",
__FILE__, __func__, sqldate);
strcpy(_imapdate, IMAP_STANDARD_DATE);
return _imapdate;
}
tm_sqldate.tm_gmtoff = tm_localtime.tm_gmtoff;
(void) strftime(_imapdate, IMAP_INTERNALDATE_LEN,
"%d-%b-%Y %T %z", &tm_sqldate);
return _imapdate;
}
Thanks for your time,
Ilja Booij