Standard "fence post" math. :-)

On Mon, Sep 2, 2019 at 5:42 PM Pat <p...@obrienphoto.net> wrote:

> I don't know why, but I'm fascinated with this small bit of code. I always
> wondered how the archive interval runs on the 5th minute reliably (on a
> vanilla install). It doesn't matter when you start weewx, it'll run on that
> 5th minute interval. If I start weewx at 8:31, I'll get an archive (most
> times) at 8:35. That got me thinking it's not a sleep, but something else.
>
> So I dug and I found the magic timer a few months ago
> <https://github.com/weewx/weewx/blob/master/bin/weewx/engine.py#L531>,
> but I've been stuck on trying to understand the math behind it. Is someone
> able to explain this in laymans terms?
>
> Let's say these are the variables:
>
> int(self.engine._get_console_time() = 1567470965
> self.archive_interval = 300
>
> If I take a the console time (1567470965), divide it by 300, I get 5224903
> Then adding 1 is easy, I get 5224904
> Then multiplying this by 300 gives me the time ahead on the 5th minute,
> or 1567471200
>
> I have no idea how or why that +1 alters the end result. It's just adding
> a second to the timestamp.
>
> (int( 1567470965 / 300) + 1) * 300 = 1567471200
>
> I think it's pretty cool how this works!
>
> --
> You received this message because you are subscribed to the Google Groups
> "weewx-development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to weewx-development+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-development/9c929337-f1ae-4034-a18f-c7191472fb13%40googlegroups.com
> <https://groups.google.com/d/msgid/weewx-development/9c929337-f1ae-4034-a18f-c7191472fb13%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-development+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-development/CAPq0zEA9Fqof6Zs34%2B40%2B0QaGTAM4YfbfDrGoXo_kmdb1kryLw%40mail.gmail.com.

Reply via email to