Timex: getting next Monday (or any other day)

I’m using Timex and exq and need a way to enqueue certain jobs at a specific day of week, for example: on a Monday at 9:00 a.m. I can use enqueue_at for this but I would need to specify the proper time.

I can implement a manual solution, but would like to know if there’s an easy alternative that I’ve missed

Thanks!

Can’t speak for Timex, but I have a small library called kday (no dependencies) that calculates the nth day of the week on, after, before, on or after, on or before a given date. In conjunction with Timex it might get you what you’re looking for.

You could have something like this

def get_next_week_day(dow) do
  Timex.today()
  |> Timex.shift(days: 7)
  |> Timex.beginning_of_week(:mon)
  |> Timex.shift(days: dow)
end

You could do it the crontab way. :slight_smile:

# Each monday 9:00
0 9 * * 1

I don’t know about exq, but Oban supports crontab syntax