12.10.1 How it works
There are two parts:
- With a capability:
Clockreads the host's time (now,localNow) andTimerwaits for a while (wait). Every reading is recorded, so a repeated run returns the same instants. - Without a capability:
DateTimeis a value that keeps an instant and a UTC offset. It is created withdateTimeOf,dateTimeUtcorparseDateTime, and its parts and ISO 8601 text are taken from it.
DateTime keeps an instant and an offset. Its parts are computed on the local time obtained by adding them.A DateTime joins an instant in nanoseconds since 1970 and an offset of +3600 seconds. Together they give the local time 2026-11-07T18:30:00+01:00.
ProgramBuilding and showing dates
Algorithm Fechas
Switch dateTimeOf(2026, 11, 7, 18, 30, 0, 0, 3600) Do
Some(cita):
Write cita.isoFormat(), " ", cita.weekday();
None:
Write "fecha inválida";
EndSwitch
Switch dateTimeOf(2026, 2, 30, 0, 0, 0, 0, 0) Do
Some(otra): Write otra.isoFormat();
None: Write "el 30 de febrero no existe";
EndSwitch
Write dateTimeUtc(0).isoFormat();
EndAlgorithmOutput
2026-11-07T18:30:00+01:00 6 el 30 de febrero no existe 1970-01-01T00:00:00Z
The program finishes normally.
weekday follows ISO 8601: 1 is Monday and 7 Sunday. The calendar is the Gregorian one without leap seconds.
ProgramMeasuring a wait
Subroutine PausaCorta() As Result<Integer, IoError>
Define reloj As Clock <- Propagate requestClock();
Define temporizador As Timer <- Propagate requestTimer();
Define antes As Integer <- Propagate reloj.now();
Define despues As Integer <- Propagate temporizador.wait(2000000000);
Return Success(despues - antes);
EndSubroutine
Algorithm Pausa
Switch PausaCorta() Do
Success(nanosegundos): Write nanosegundos / 1000000000;
Failure(problema): Write problema.code;
EndSwitch
EndAlgorithmOutput
2.0
The program finishes normally.
In short
ClockandTimerare capabilities; their readings are recorded.DateTimeis a pure value with an instant and an offset.- Parts and ISO text are computed without depending on the machine.