calendarDuration — Create calendar duration values for month-aware datetime arithmetic.
calendarDuration represents calendar-relative elapsed time. RunMat supports construction from numeric calendar components, unit helpers, predicates, arithmetic with datetime values, and calendarDuration addition/subtraction.
Syntax
calendarDuration()How calendarDuration works
calendarDuration()creates a zero calendar duration.calendarDuration(Y, M, D)andcalendarDuration(Y, M, D, H, MN, S)create month/day-backed calendar durations with scalar expansion across component arrays.caldays,calweeks,calmonths,calquarters, andcalyearscreate calendar durations from a single numeric unit.- Calling a calendar unit helper on a calendarDuration converts it back to numeric counts in that unit.
iscalendarduration(x)returns true for calendarDuration objects.- Adding or subtracting a calendarDuration from a datetime performs month-aware calendar arithmetic and clamps invalid month-end days to the final day of the target month.
Does RunMat run calendarDuration on the GPU?
calendarDuration does not dispatch GPU kernels. Numeric inputs may be gathered before object construction.
GPU memory and residency
No. calendarDuration values are represented as host-side objects with internal numeric tensors.
Examples
Create a calendar duration from months
c = calmonths(2)Expected output:
c =
calendarDurationAdd a calendar month to a month-end datetime
t = datetime(2024, 1, 31, 'Format', 'yyyy-MM-dd');
t + calmonths(1)Expected output:
ans =
2024-02-29Construct from components
c = calendarDuration(1, 2, 3)Expected output:
c =
calendarDurationUsing calendarDuration with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how calendarDuration changes the result.
Run a small calendarDuration example, explain the result, then change one input and compare the output.
FAQ
How is calendarDuration different from duration?⌄
duration stores fixed elapsed time. calendarDuration stores calendar months and days, so adding one month to January 31 lands on the last day of February.
Does calendarDuration run on the GPU?⌄
No. It is a host-side object used for datetime arithmetic.
Related Datetime functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how calendarDuration is executed, line by line, in Rust.
- View the source for calendarDuration in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.