lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Rena <hyperhacker@gmail.com> wrote:

> It looks like in 5.1, os.date() can be told to give times in GMT, but
> os.time(), given a table, always returns the result in the local
> timezone.

This is because of a limitation in the standard C library. There are
struct tm *localtime(time_t) and struct tm *gmtime(time_t) for unpacking
times, but only time_t mktime(struct tm *) for repacking them. The missing
function time_t timegm(struct tm *) is provided by good unixes but is not
part of the standard C library nor even in POSIX!

> It also appears there's no easy way to check what the current timezone
> offset is.

Good unixes extend struct tm with a tm_gmtoff field, but again this
feature is not in the standards.

Steve Donovan has described a suitable workaround for you.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Fair Isle, Faeroes: Northeasterly backing northerly 5 or 6, occasionally 7 at
first in southeast Fair Isle. Moderate or rough. Wintry showers. Good,
occasionally poor.