Bradley Kirton's Blog

Published on Aug. 13, 2021

Go home

Introducing justnow

Most people have probably heard of Cron. Cron is a time based scheduling system which runs jobs based on Cron schedule expressions. A great resource for testing Cron schedule expressions is https://crontab.guru/. I assume that fewer people have used systemd for scheduling jobs and if you haven't you should definitely check it out. Anyway systemd has the concept of a timer unit which can be run on a time event. These time events can be evaluated in your console by using the systemd-analyse calendar command.

For example suppose we wanted to know when the next Saturday occurring on the 29th of February for some future year was, we could run:

systemd-analyze calendar "sat *-02-29"
  Original form: sat *-02-29                 
Normalized form: Sat *-02-29 00:00:00        
    Next elapse: Sat 2048-02-29 00:00:00 SAST
       (in UTC): Fri 2048-02-28 22:00:00 UTC 
       From now: 27 years 6 months left

justnow is a systemd.timer inspired event parser written in Python. The above example can be replicated using justnow as follows:

import datetime

from justnow.parser import EventParser

# "sat *-02-29" => Generate all Saturdays which occur on a leap year
reference_date = datetime.datetime(2020, 8, 13)
parser = EventParser("sat *-02-29", reference_date=reference_date)

next(parser)  # datetime.datetime(2048, 2, 29, 0, 0)

Why the name?

In South Africa we often use the term just now to refer to the immediate future. This is confusing because elsewhere in the world it is often used to refer to an event which has just happened. For example, Terrence asks Bob "How is the report coming along?" Bob replies "Yeah yeah I will get to it just now".

If this sounds remotely interesting feel free to check it out on gitlab or pypi.