The time synchronization client is based on Simple Network Time Protocol (SNTP) Version 4, RFC 4330.
On each synchronization, the Time module does up to 8 exchanges request/response with NTP server (Any potential NTP packet sanity check failures or UDP errors are included in this number exchanges)
For each successful exchange, the Time module computes the roundtrip time of the exchange, and the offset to apply to local clock to set time the more accurately.
Finally, the offset computed from the packet with the minimum roundtrip time, is used to change the local clock.
Notes
synchronize()
Run NTP time synchronization asynchronously.
Lua Event : emitter="TIME", event="TIME_UPDATED", params=applied_offset(LuaNumber)
INFO
The local clock update that can occur during time synchronization can have some impacts on timers and other time-related actions.
This can be quite important when the clock is updated with a big positive offset (i.e clock was way in the past), as scheduled events will be delayed by this big offset.
Example:
function test_ntp_timer ()
local sys = require"system"
local timer = require"timer"
local string = require "string"
local now = os.time()
local t1 = timer.new(10, function() print(string.format("now = %d, one shot 10, should arrive %d", os.time(), now+10)) end)
local t2 = timer.new(-10, function()print(string.format("now = %d, period 10, should arrive first %d", os.time(), now+10)) end)
sys.settime(os.time()+ TIME_OFFSET)
end
Time zone and Daylight Saving Time parameters are defined in the Agent's Config table.
WARNING
Those parameters are here just to provide a way to read those values for applicative logic purpose and to be set/read by server commands.
All timestamps exchanged with the server, or used internally, are in UTC.
SNTP RFC: http://www.faqs.org/rfcs/rfc4330.html
NTP papers, best practices, ... : http://www.ece.udel.edu/~mills/ntp.html