Every document starts in "UTC". The timezone affects how Time.today(), Time.datetime(), and Time.time() compute their values. You can change it whenever you want:
@construct {
// Default timezone is UTC
string tz = Time.zone(); // "UTC"
// Change to Eastern time
bool ok = Time.setZone("America/New_York"); // true
// Invalid timezones are rejected
bool bad = Time.setZone("Not/A/Zone"); // false
}
Time.setZone() accepts any valid IANA timezone identifier (e.g., "America/Chicago", "Europe/London", "Asia/Tokyo") and returns true on success. The timezone is persisted as part of the document state and survives restarts.
For the full story on timezone management and other global objects, see Global Objects.
The distinction between extendWithinDay and cyclicAdd matters: one clamps at midnight (you can't go past 23:59), the other wraps around (23:00 + 2 hours = 01:00). Pick the one that matches your semantics.
time t = @time 23:00;
timespan oneHour = @timespan 1 hr;
// Clamps at midnight (23:59)
time extended = Time.extendWithinDay(t, oneHour);
// Wraps around (00:00)
time wrapped = Time.cyclicAdd(t, oneHour);
These are useful for building calendar UIs. The calendarViewOf() method on a date gives you the full surrounding month; the static functions give you different views.
Instance method on date values:
Method
Description
Returns
.calendarViewOf()
Get surrounding month
list<date>
Static functions:
Function
Description
Returns
Date.weekViewOf(d)
Get surrounding week
list<date>
Date.neighborViewOf(d, days)
Get neighborhood of dates
list<date>
Date.inclusiveRange(from, to)
Get all dates in range
list<date>
procedure foo() {
date today = @date 2025/1/15;
list<date> month = today.calendarViewOf();
list<date> week = Date.weekViewOf(today);
list<date> neighbors = Date.neighborViewOf(today, 3); // 3 days before and after
list<date> range = Date.inclusiveRange(@date 2025/1/1, @date 2025/1/31);
}
I needed a way to express "every Monday, Wednesday, and Friday" for scheduling, so I built weekly patterns. You create a bitmask from a boolean for each day, then test dates against it.
Function
Description
Returns
Date.patternOf(m, tu, w, th, fr, sa, su)
Convert week pattern to bitmask
int
Date.satisfiesWeeklyPattern(d, pattern)
Check if date matches pattern
bool
Date.inclusiveRangeSatisfiesWeeklyPattern(from, to, pattern)
Get matching dates in range
list<date>
// Create pattern for weekdays only
int weekdays = Date.patternOf(true, true, true, true, true, false, false);
date d = @date 2025/1/15; // A Wednesday
bool isWeekday = Date.satisfiesWeeklyPattern(d, weekdays); // true
// Get all weekdays in January
formula workdays = Date.inclusiveRangeSatisfiesWeeklyPattern(
@date 2025/1/1, @date 2025/1/31, weekdays
);
date d = @date 2025/1/15;
date nextMonth = d.offsetMonth(1); // 2025/2/15
date lastWeek = d.offsetDay(-7); // 2025/1/8
date start = @date 2020/1/1;
date end = @date 2025/1/1;
double years = Date.periodYearsFractional(start, end); // 5.0
int months = Date.periodMonths(start, end); // 60
// Instance method for age calculation
date birthday = @date 1990/5/20;
maybe<double> age = birthday.periodYearsFractional(Time.today());