#(jumpsplat120) Struggling on creating my own implementation of Epoch Time

15 messages · Page 1 of 1 (latest)

quaint obsidian
#

I'm currently trying to get the amount of seconds to epoch time, but for some reason my calculation is exactly 17 hours off in seconds. I can't tell why, so I'm hoping and extra pair of eyes on this will help.

function Date:get_seconds_until_epoch()
    local p, result
    
    p = private[self]

    if p.year >= 1970 then
        result = p.second +
                (p.minute * seconds_in.minute) +
                (p.hour   * seconds_in.hour)   +
                elapsedDaysInYear(p) * seconds_in.day

        for i = 1970, p.year - 1, 1 do
            result = result + (isLeapYear(i) and seconds_in.leap_year or seconds_in.year)
        end

        return result
end```

`seconds_in.minute/hour/day` all return the correct values, and `elapsedDaysInYear` is returning the current elapsed days this year (as of right now thats 183 days).

This is annoying because if it was off by a whole day, I might figure it's the leapYear thing, or some off-by-one error somewhere. But 17 hours? I don't know how that would happen. I was thinking it was my timezone maybe? But my timezone is +8, so that doesn't make any sense. I thought maybe it was daylight savings, but that's only an hour difference. So I can't figure out why it's off by exactly 17 hours.
lavish jettyBOT
#

(jumpsplat120) Struggling on creating my own implementation of Epoch Time

lavish jettyBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>

quaint obsidian
#

Oh, wait, elapsedDays counts today, but today hasn't fully happened yet.

#

okay, so 182 days, plus today is how many days have actually elapsed. I played myself. That gives me a result that is off by -7 hours, which sounds like timezone shenanigans maybe.

quaint obsidian
#

Yup, that's all it was. elapsedDays was counting today as a fully elapsed day. Guess I just needed a rubber duck.

heady cargoBOT
#
Resolved

Thread closed as resolved.

heady cargoBOT
#
Thread Reopened

Thread was manually reopened by @bleak ibex.