Last active
September 21, 2022 01:38
-
-
Save farribeiro/f8bea58a334607561e9afca28626afd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interrupt(1) | |
| function newRelogio() | |
| local self = { | |
| dt = os.datetable() | |
| } | |
| local function setTZ(tz) | |
| self.tz = tz | |
| end | |
| local function setCapital(cidade) | |
| self.capital = cidade | |
| end | |
| local function getSegundos() | |
| return self.dt.sec | |
| end | |
| local function getHoraLocal() | |
| if self.dt.hour + self.tz <= 0 then | |
| return self.dt.hour + self.tz + 24 | |
| else | |
| return self.dt.hour + self.tz | |
| end | |
| -- if self.dt.hour + self.tz >= 24 then | |
| -- return self.dt.hour + self.tz - 24 | |
| -- end | |
| end | |
| local function imprimeData() | |
| -- if self.dt.hour == 0 then | |
| local o = string.format("Data do servidor eh %02i/%02i" .. "/" .. self.dt.year, self.dt.day, self.dt.month) | |
| digiline_send(self.channel, o) | |
| -- end | |
| end | |
| local function getPeriodo() | |
| if getHoraLocal() < 12 then | |
| return "Bom dia" | |
| end | |
| if getHoraLocal() >= 12 and getHoraLocal() <= 18 then | |
| return "Boa tarde" | |
| else | |
| return "Boa noite" | |
| end | |
| end | |
| local function imprimeHora() | |
| -- if self.dt.sec == 00 then | |
| local o = string.format(getPeriodo() .. ", hora certa de " .. self.capital .. " %02i:%02i:%02i", getHoraLocal(), self.dt.min, self.dt.sec) | |
| digiline_send(self.channel, o) | |
| -- end | |
| end | |
| local function setChannel(name) | |
| self.channel = name | |
| end | |
| return { | |
| imprimeHora = imprimeHora, | |
| imprimeData = imprimeData, | |
| setChannel = setChannel, | |
| setTZ = setTZ, | |
| setCapital = setCapital, | |
| getSegundos = getSegundos | |
| } | |
| end | |
| relogio = newRelogio() | |
| relogio.setTZ(0) | |
| relogio.setCapital("Londres") | |
| data = newRelogio() | |
| --[[ if relogio.getSegundos() % 15 == 0 then | |
| relogio.setChannel("tela2") | |
| data.setChannel("tela1") | |
| else | |
| -]] | |
| relogio.setChannel("tela1") | |
| data.setChannel("tela2") | |
| -- end | |
| relogio.imprimeHora() | |
| data.imprimeData() | |
| --[[ | |
| local function setNome(name) | |
| self.nome = name | |
| end | |
| -]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment