From c706ff367a5b85033a5b442c252293f555b8f0b7 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 24 Oct 2019 20:19:50 +1100 Subject: [PATCH] added the realtime library, will be used properly soon --- realtime/OpenOS/usr/lib/realtime.lua | 22 ++++++++++++++++++++++ realtime/OpenOS/usr/man/realtime | 13 +++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 realtime/OpenOS/usr/lib/realtime.lua create mode 100644 realtime/OpenOS/usr/man/realtime diff --git a/realtime/OpenOS/usr/lib/realtime.lua b/realtime/OpenOS/usr/lib/realtime.lua new file mode 100644 index 0000000..033c9ad --- /dev/null +++ b/realtime/OpenOS/usr/lib/realtime.lua @@ -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 diff --git a/realtime/OpenOS/usr/man/realtime b/realtime/OpenOS/usr/man/realtime new file mode 100644 index 0000000..2e65182 --- /dev/null +++ b/realtime/OpenOS/usr/man/realtime @@ -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.