Appearance
Time Functions
Time is a central aspect of control systems—whether for delays, counters, run‑times, or log entries. Coldwave Script supports multiple time types: TIME, DATE, TOD, DT. All computations are deterministic—time is always explicit.
TIME Functions
ADD_TIME(t1, t2): Adds two time spans.
vb
PROGRAM
PRINT ADD_TIME(T#2s, T#500ms)
END PROGRAM' Output: T#2500ms
SUB_TIME(t1, t2): Subtracts time spans.
vb
PROGRAM
PRINT SUB_TIME(T#10s, T#3s)
END PROGRAM' Output: T#7000ms
MUL_TIME(t, factor): Multiplies a time span by a factor.
vb
PROGRAM
PRINT MUL_TIME(T#500ms, 3)
END PROGRAM' Output: T#1500ms
Date and Time Functions (DATE, TOD, DT)
DATE_TO_DT(date, tod): Combines date and time-of-day into a DT value.
vb
PROGRAM
PRINT DATE_TO_DT(DATE#2025-01-01, TOD#12:00:00)
END PROGRAM' Output: DT#2025-01-01-12:00:00
DT_TO_DATE(dt): Extracts calendar date.
vb
PROGRAM
PRINT DT_TO_DATE(DT#2025-01-01-12:00:00)
END PROGRAM' Output: DATE#2025-01-01
DT_TO_TOD(dt): Extracts time-of-day.
vb
PROGRAM
PRINT DT_TO_TOD(DT#2025-01-01-12:00:00)
END PROGRAM' Output: TOD#12:00:00
Examples
TON with doubled duration:
vb
PROGRAM
DIM T AS TON
DIM base AS TIME = T#1000ms
T(IN = TRUE, PT = MUL_TIME(base,2))
PRINT T.Q
END PROGRAMDifference of two time spans:
vb
PROGRAM
DIM d1 AS TIME = T#10s
DIM d2 AS TIME = T#3s
PRINT SUB_TIME(d1,d2)
END PROGRAM' Output: T#7000ms
Check working‑hours window:
vb
PROGRAM
DIM now AS TOD = TOD#14:30:00
IF (now >= TOD#08:00:00) AND (now <= TOD#18:00:00) THEN
PRINT "Within working hours"
ELSE
PRINT "Outside working hours"
END IF
END PROGRAMExercises with Solutions
Task 1: Add 500 ms and 2 s.
vb
PROGRAM
PRINT ADD_TIME(T#500ms, T#2s)
END PROGRAM' Output: T#2500ms
Task 2: Difference between T#10s and T#3s.
vb
PROGRAM
PRINT SUB_TIME(T#10s, T#3s)
END PROGRAM' Output: T#7000ms
Task 3: Combine DATE#2025-01-01 and TOD#12:00:00 into DT.
vb
PROGRAM
PRINT DATE_TO_DT(DATE#2025-01-01, TOD#12:00:00)
END PROGRAM' Output: DT#2025-01-01-12:00:00
Summary
- TIME represents durations and supports addition, subtraction, multiplication, and division.
- DATE, TOD, DT enable calendar‑ and time‑of‑day computations.
- Common applications: timer control, working‑hour windows, log timestamps.