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) and calendarDuration(Y, M, D, H, MN, S) create month/day-backed calendar durations with scalar expansion across component arrays.
  • caldays, calweeks, calmonths, calquarters, and calyears create 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 =
  calendarDuration

Add 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-29

Construct from components

c = calendarDuration(1, 2, 3)

Expected output:

c =
  calendarDuration

Using 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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how calendarDuration is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.