# Pure function to determine next and last ping?

**URL:** <https://forum.beeminder.com/t/pure-function-to-determine-next-and-last-ping/7047>\
**Category:** TagTime\
**Created:** [July 25, 2020, 11:36am UTC](https://forum.beeminder.com/t/pure-function-to-determine-next-and-last-ping/7047 "2020-07-25T11:36:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smitop](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/smitop/32/4164_2.png) [@smitop](https://forum.beeminder.com/u/smitop)\
**Post date:** [July 25, 2020, 11:36am UTC](https://forum.beeminder.com/t/pure-function-to-determine-next-and-last-ping/7047/1 "2020-07-25T11:36:21Z")

</div>

Hi there! I’m working on a web-based version of TagTime, and I while it will default to a time-hashing based algorithm (more details soon), I want to support the original algorithm as an option for compatibility. Is there a way to determine, from a given timestamp, what the next and last ping are? The JS reference implementation has side-effects, and it would simplify implementation if it were side-effect-free. Is there a more efficient way to do this than starting at the beginning of time and stepping through until getting to now. Thanks!

---

<div class="post-metadata">

**Author:** ![narthur](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/narthur/32/5113_2.png) [@narthur](https://forum.beeminder.com/u/narthur)\
**Post date:** [July 25, 2020, 11:31pm UTC](https://forum.beeminder.com/t/pure-function-to-determine-next-and-last-ping/7047/2 "2020-07-25T23:31:18Z")

</div>

This is super interesting. Can you describe the reference implementation in more detail?

---

<div class="post-metadata">

**Author:** ![dreev](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/dreev/32/4311_2.png) [@dreev](https://forum.beeminder.com/u/dreev)\
**Post date:** [July 26, 2020, 2:06pm UTC](https://forum.beeminder.com/t/pure-function-to-determine-next-and-last-ping/7047/3 "2020-07-26T14:06:09Z")

</div>

Ooh, I can’t wait to see your version of TagTime!

@narthur: [Official Reference Implementation of the TagTime Universal Ping Schedule](https://forum.beeminder.com/t/official-reference-implementation-of-the-tagtime-universal-ping-schedule/4282)

(Googling “tagtime reference implementation” turns that up and you can also find that and other handy links at [tagtime.com](http://tagtime.com) (let me know when I can add your version to that list, @smitop!)

@smitop: As for the question about a stateless function to get the next and last ping without walking forward from the beginning of time, I don’t think so. Now I’m curious what language/framework you’re implementing this in!

---

<div class="post-metadata">

**Author:** ![narthur](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/narthur/32/5113_2.png) [@narthur](https://forum.beeminder.com/u/narthur)\
**Post date:** [July 26, 2020, 3:21pm UTC](https://forum.beeminder.com/t/pure-function-to-determine-next-and-last-ping/7047/4 "2020-07-26T15:21:16Z")

</div>

A while back I made a TagTime-like system in Android Automate. Here’s some pseudo-code that represents the scheduling strategy I used:

```auto
begin
start = 6
end = 19
length = end-start
rand = random()
run = rand <= 0.1 && hour >= start && hour < end
if run:
  ping user
wait 5 minutes
goto begin

```

There are probably good arguments for why this approach is naive, though I couldn’t articulate them, and the strategy worked well enough for what I was doing. I did have [a big discussion](https://forum.beeminder.com/t/questions-about-stochastic-time-tracking/6559) with some other users here on the forum regarding the nuances of stochastic time tracking and the practical issues I ran into trying to use it.

Also, if you’re interested in looking at my Automate flow, I’m happy to share more information / an export of the flow.
