nodemcu-firmware/lua_examples/timezone
galjonsfigur 6926c66b16 Polish Lua examples (#2846)
* Add missing globals from luacheck config

* Fix luacheck warnings in all lua files

* Re-enable luacheck in Travis

* Speed up Travis by using preinstalled LuaRocks

* Fix more luacheck warnings in httpserver lua module

* Fix DCC module and add appropriate definitions to luacheck config.

* Change inline comments from ignoring block to only ignore specific line

* Add Luacheck for Windows and enable it for both Windows and Linux

* Change luacheck exceptions and fix errors from 1st round of polishing

* Add retry and timeout params to wget
2020-06-09 22:26:52 +02:00
..
README.md trailing spaces cleanup (#2659) 2019-02-17 18:26:29 +00:00
alaska.zone Sample code for timezone handling (#1853) 2017-03-10 22:09:36 +01:00
central.zone Sample code for timezone handling (#1853) 2017-03-10 22:09:36 +01:00
eastern.zone Sample code for timezone handling (#1853) 2017-03-10 22:09:36 +01:00
mountain.zone Sample code for timezone handling (#1853) 2017-03-10 22:09:36 +01:00
pacific.zone Sample code for timezone handling (#1853) 2017-03-10 22:09:36 +01:00
tz.lua Polish Lua examples (#2846) 2020-06-09 22:26:52 +02:00

README.md

tz module

This is a simple module that parses timezone files as found on unix systems. It is oriented around converting the current time. It can convert other times, but it is rather less efficient as it maintains only a single cached entry in memory.

On my linux system, these files can be found in /usr/share/zoneinfo.

tz.setzone()

This sets the timezone to be used in subsequent conversions

Syntax

tz.setzone(timezone)

Parameters

  • timezone this is the timezone string. It must correspond to a file in the file system which is named timezone.zone.

Returns

true if the zone exists in the file system.

tz.getoffset()

This gets the offset (in seconds) of the time passed as the argument.

Syntax

tz.getoffset(time)

Parameters

  • time the number of seconds since the epoch. This is the same value as used by the sntp module.

Returns

  • The number of seconds of offset. West of Greenwich is negative.
  • The start time (in epoch seconds) of this offset.
  • The end time (in epoch seconds) of this offset.

Example

tz = require('tz')
tz.setzone('eastern')
sntp.sync(nil, function(now)
  local tm = rtctime.epoch2cal(now + tz.getoffset(now))
  print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
end)

tz.getzones()

This returns a list of the available timezones in the file system.

Syntax

tz.getzones()

Returns

A list of timezones.