ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cron_expression Class Referencefinal

Strongly-typed, validated cron expression. More...

#include <cron_expression.hpp>

Collaboration diagram for cron_expression:
Collaboration graph

Public Member Functions

 cron_expression ()
 Default constructor. Creates an expression that runs every minute.
 
const std::string & to_string () const noexcept
 The validated cron string, suitable for pg_cron's cron.schedule().
 
std::chrono::system_clock::time_point next_occurrence (std::chrono::system_clock::time_point after=std::chrono::system_clock::now()) const
 Compute the next occurrence after the given time point.
 
bool operator== (const cron_expression &other) const noexcept=default
 

Static Public Member Functions

static std::expected< cron_expression, std::string > from_string (std::string_view expr)
 Parse and validate a cron expression string.
 

Detailed Description

Strongly-typed, validated cron expression.

Wraps a cron expression string, validating it on construction via croncpp. Provides C++23 chrono-based next-occurrence computation and serialisation to the plain string required by pg_cron's cron.schedule() function.

Use the factory method from_string() to construct:

auto expr = cron_expression::from_string("0 0 * * *");
if (expr) {
auto next = expr->next_occurrence();
}
static std::expected< cron_expression, std::string > from_string(std::string_view expr)
Parse and validate a cron expression string.
Definition cron_expression.cpp:48

Constructor & Destructor Documentation

◆ cron_expression()

Default constructor. Creates an expression that runs every minute.

Provides a valid default state so that types containing cron_expression (e.g. job_definition) can be default-constructed for UI purposes. Equivalent to "* * * * *".

Here is the caller graph for this function:

Member Function Documentation

◆ from_string()

std::expected< cron_expression, std::string > from_string ( std::string_view  expr)
static

Parse and validate a cron expression string.

Accepts standard 5-field cron syntax (minute hour day month weekday). Returns an error string if the expression is malformed.

Here is the caller graph for this function:

◆ next_occurrence()

std::chrono::system_clock::time_point next_occurrence ( std::chrono::system_clock::time_point  after = std::chrono::system_clock::now()) const

Compute the next occurrence after the given time point.

Defaults to the current wall-clock time when no argument is supplied.