1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-11-23 10:38:05 +11:00

added the realtime library, will be used properly soon

This commit is contained in:
Izaya 2019-10-24 20:19:50 +11:00
parent 1b53606fe4
commit c706ff367a
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,22 @@
local computer = require "computer"
local realtime = {}
realtime.epoch, realtime.uptime, realtime.offset = 0, computer.uptime(), 0
function realtime.update(epoch,uptime,offset)
if type(epoch) ~= "number" or type(uptime) ~= "number" then
return false
end
realtime.epoch, realtime.uptime, realtime.offset = epoch, uptime, offset or realtime.offset
return true
end
function realtime.time(utc)
local ofs = realtime.offset
if utc then
ofs = 0
end
local ut = computer.uptime()
return (realtime.epoch+(ut-realtime.uptime))+ofs
end
return realtime

View File

@ -0,0 +1,13 @@
# realtime
realtime is a library for OpenOS providing a reasonably accurate current real-world time, given the right input (see realtime-sync and realtime-relay).
## API
### realtime.time(*utc*)
Returns the current time, either respecting the current offset, or if *utc* is set, with no offset.
### realtime.update(*epoch*, *uptime*, *offset*)
Updates the currently known real time, with the time as *epoch*, measured at *uptime*. Optionally, an offset can be provided.