Temporal conditions and TimeDSL
A temporal condition lets an edge depend on the time at which ExecKernel evaluates it. Your application can use it to offer a choice during opening hours, after a date or while a session is within an allowed age. The engine compares the condition with the evaluation instant; your application uses the resulting availability to display its options.
TimeDSL is a notation for writing those temporal conditions. It compiles into the same rules that you can declare directly in a graph. Understanding the resulting rule is useful because it tells you whether a restriction repeats every day, names a fixed date or depends on elapsed session time.
Choose the condition from the requirement
Section titled “Choose the condition from the requirement”Start with the time-related requirement your application needs to express:
| Requirement | Suitable condition | What the engine compares |
|---|---|---|
| Offer a choice during a recurring opening schedule | time_window with clock limits and weekdays |
The current local hour and weekday. This is the example developed below. |
| Allow a choice only on certain weekdays | weekday with weekdays |
The local weekday, without adding an opening hour. |
| Limit a choice to a calendar period | date_range with start_date and end_date |
Local calendar dates; both endpoint days are included. Equal dates select one day. |
| Compare the current instant with a precise deadline | time, with source: now, a before or after operator and an absolute target |
Instants, using strict before/after comparisons. An explicit offset identifies the deadline. |
| Allow a choice only within an age range of its session | session_age with min and/or max |
Seconds elapsed since createdAt, including the specified bounds. |
| Match a recurring calendar pattern, such as every fifteen minutes | cron with expression: "*/15 * * * *" |
Whether the evaluated local minute matches the expression. |
A session-age condition controls the availability of its edge; it does not configure session expiration. Likewise, a cron condition answers a question at the observed minute; your application still has to request the evaluation. When several calendar restrictions belong together, time_window can combine dates, hours, weekdays and session-age bounds. The built-in rule reference gives their complete parameter contracts.
Define the window your application needs
Section titled “Define the window your application needs”We will reuse the learning-path graph introduced in Anatomy of a graph. From node 10, edge 101 opens a guide and edge 102 opens browser practice. The practice choice already requires practiceEnabled: true in the session context.
The temporal-learning-window.json variant keeps those nodes, edges, presentation and outputs. It changes the graph code to learning-window and adds a temporal condition to practice: Monday to Friday, from 09:00 through the 17:00 minute, in Europe/Madrid. Both the existing context condition and this new window must pass. The guide remains available outside the window.
This is the additional entry in the graph’s conditions array:
{ "edge_id": 102, "rule": "time_window", "params": { "start_time": "09:00", "end_time": "17:00", "weekdays": ["monday", "tuesday", "wednesday", "thursday", "friday"] }}time_window combines the restrictions in its parameters. Here, it checks the local clock time and the local weekday. Because there is no start_date or end_date, the window recurs on those weekdays; it does not name one particular week.
The clock limits use inclusive minutes. On an allowed weekday, 09:00:00 and 17:00:59 are inside this window; 17:01:00 is outside. If your application needs an exact instant as a deadline, use a time rule with source: "now", operator: "before" and an absolute date-time target. This comparison allows only instants before the deadline; equality no longer passes. Do not interpret end_time as closing at the start of its minute.
Set the evaluation instant and the timezone
Section titled “Set the evaluation instant and the timezone”The instant and the timezone have different jobs. A TimeProvider supplies the instant used by the engine. A DateTimeEvaluator supplies the timezone in which temporal rules interpret clock hours, weekdays and calendar dates. The default evaluation zone is UTC.
For this example, construct the engine with a fixed instant and the Madrid evaluation zone:
use ExecKernel\Domain\Engine\DateTimeEvaluator;use ExecKernel\Domain\Engine\FixedTimeProvider;use ExecKernel\Infrastructure\Engine\ExecKernelFactory;
$clock = new FixedTimeProvider( new DateTimeImmutable('2026-12-07T08:59:00+01:00'),);
$engine = (new ExecKernelFactory())->build( timeProvider: $clock, dateTimeEvaluator: new DateTimeEvaluator('Europe/Madrid'),);FixedTimeProvider makes the example repeatable: asking it for the current time always returns the supplied instant. In a running application, the factory’s default SystemTimeProvider supplies the current time. Setting DateTimeEvaluator('Europe/Madrid') makes a window labelled 09:00–17:00 refer to that zone, regardless of PHP’s default timezone or the timezone used to display the provider’s date object.
The engine samples the instant once for each operation and passes it through the evaluation. The public operations also accept an explicit timestamp, in Unix seconds; supplying it overrides the provider for that operation. This is useful for a controlled check. Advancing that timestamp does not itself append history or move the session to another node.
For absolute date-times, an explicit offset such as 2026-12-07T09:00:00+01:00 identifies an instant. A date-time without an offset is interpreted in the evaluation zone and must identify one unambiguous instant. Around a daylight-saving change, use an explicit offset when a local time is repeated or does not exist.
Express the same window with TimeDSL
Section titled “Express the same window with TimeDSL”In FlowDSL, conditions are attached inside an edge declaration with when. Reusing that notation, the practice edge can contain this temporal clause alongside its existing context_value condition:
when time { hours 09:00-17:00 weekdays mon,tue,wed,thu,fri}hours supplies the two clock limits. weekdays expands its abbreviations into the full weekday names used by the rule. Importing the complete FlowDSL graph creates a Condition with rule: time_window and the same parameters shown above.
You can also inspect the compilation directly without importing a whole graph:
use ExecKernel\Infrastructure\Importer\TimeDslParser;
$rules = (new TimeDslParser())->compileInline( 'time { hours 09:00-17:00; weekdays mon,tue,wed,thu,fri }',);The parser returns this rule data:
[ { "type": "time_window", "start_time": "09:00", "end_time": "17:00", "weekdays": ["monday", "tuesday", "wednesday", "thursday", "friday"] }]This is the parser’s intermediate representation: type identifies the rule, and the remaining fields become its parameters. The importer attaches it to the containing edge. It is not a replacement for the complete flat-graph entry, which also needs edge_id, rule and params.
Check before, during and after without waiting
Section titled “Check before, during and after without waiting”Use the graph variant above with practiceEnabled: true, so that time is the only changing input. The following fragment assumes $graph is that imported graph and $engine is the fixed-clock engine just configured:
use ExecKernel\Domain\Session\Context;
$state = $engine->start( $graph, 'en', new Context(['practiceEnabled' => true]),)->state;
$checks = [ '2026-12-07T08:59:00+01:00', '2026-12-07T09:00:00+01:00', '2026-12-07T12:00:00+01:00', '2026-12-07T17:00:59+01:00', '2026-12-07T17:01:00+01:00',];
foreach ($checks as $instant) { $payload = $engine->getPayload( $graph, $state, 'en', timestamp: (new DateTimeImmutable($instant))->getTimestamp(), ); $choices = array_column($payload['edges'], null, 'id'); $practice = $choices[102];
// Render the practice choice using this freshly calculated availability. $availability = $practice['availability']; $enabled = $practice['enabled'];}Each call reuses the same $state: current node 10, the same context and the same history. getPayload() calculates a view for the supplied instant and returns it; it does not take edge 102. No sleep or real-time wait is involved.
| Madrid time on Monday 7 December 2026 | Practice availability |
enabled |
What your application can show |
|---|---|---|---|
| 08:59:00 | blocked |
false |
Practice is not open yet. |
| 09:00:00 | available |
true |
Practice can be selected. |
| 12:00:00 | available |
true |
Practice can be selected. |
| 17:00:59 | available |
true |
The inclusive end minute still passes. |
| 17:01:00 | blocked |
false |
Practice has closed for today. |
The messages in the last column are examples of application wording. The engine supplies availability, rather than those user-facing sentences. With debug information enabled, the failed temporal condition identifies time_window_blocked and EK-TIME-001.
The complete temporal-window.php example loads the JSON variant, performs these checks and verifies that the state has not changed. It expects the JSON file and your project’s vendor/ directory beside it.
When someone selects practice, choose() evaluates the condition again at the selection instant. A view obtained at 17:00 does not reserve the edge for a later request. Condition evaluation and edge availability develops this distinction: a query describes the current options, while a choice must pass the checks for the actual transition.
Understand what only.today fixes during compilation
Section titled “Understand what only.today fixes during compilation”only.today is relative to an explicit compilation reference date. It compiles to a fixed start_date and end_date; it does not remain a request to look up “today” on every evaluation.
$pinned = (new TimeDslParser('2026-12-07'))->compileInline( 'time { only.today; hours 09:00-17:00 }',);The resulting time_window contains:
{ "type": "time_window", "start_date": "2026-12-07", "end_date": "2026-12-07", "start_time": "09:00", "end_time": "17:00"}If your application evaluates that graph on 8 December, this condition fails. To express daily opening hours, omit only.today; to publish a window for one calendar day, keep the resolved date as part of the graph definition.
When compiling a complete FlowDSL graph, SchemaImporter can derive the reference date from a supplied DateTimeImmutable and import timezone. For example, an import clock of 2026-12-06T23:30:00Z with timezoneId: 'Europe/Madrid' fixes the date to 2026-12-07. That import timezone does not configure the runtime evaluator: set the intended zone in both places. Without an explicit reference date or import clock, only.today raises TimeDslException with EK-DSL-015 and reason missing_reference_date.
Compiling and evaluating are separate operations. A temporal rule, including a cron predicate, is checked when your application asks the engine to evaluate it. It does not arrange a future call or automatically traverse an edge when the window opens. Your application decides when to refresh its view or request a transition. See the TimeDSL reference for the complete notation.