mirror of
https://github.com/ShadowKatStudios/OC-Minitel.git
synced 2024-11-23 02:28:05 +11:00
added the realtime library, will be used properly soon
This commit is contained in:
parent
1b53606fe4
commit
c706ff367a
22
realtime/OpenOS/usr/lib/realtime.lua
Normal file
22
realtime/OpenOS/usr/lib/realtime.lua
Normal 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
|
13
realtime/OpenOS/usr/man/realtime
Normal file
13
realtime/OpenOS/usr/man/realtime
Normal 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.
|
Loading…
Reference in New Issue
Block a user