scriptdate

package
v1.131.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package scriptdate is the date arithmetic a managed script is given, as a Starlark module.

It is separate from the engine because it shares nothing with it: every function is a pure transformation of its arguments, there is no run, no caller and no state, and the engine's only use of it is to predeclare the module. Keeping it here is what lets the date contract be read, and tested, without the interpreter around it.

Index

Constants

View Source
const TimeLayout = time.RFC3339

TimeLayout is the wire form of an instant (the run's fire time). Dates use script.DateLayout, so a script that slices a date out of the fire time and a schedule that binds one are talking about the same strings. It is exported because the engine formats run.fire_time with it, and the two spellings must be one.

Variables

View Source
var Module = &starlarkstruct.Module{
	Name: "date",
	Members: starlark.StringDict{
		"of":         starlark.NewBuiltin("date.of", dateOf),
		"parse":      starlark.NewBuiltin("date.parse", dateParse),
		"format":     starlark.NewBuiltin("date.format", dateFormat),
		"add_days":   starlark.NewBuiltin("date.add_days", dateAddDays),
		"add_months": starlark.NewBuiltin("date.add_months", dateAddMonths),
		"diff_days":  starlark.NewBuiltin("date.diff_days", dateDiffDays),
		"start_of_month": starlark.NewBuiltin("date.start_of_month",
			dateStartOfMonth),
		"weekday": starlark.NewBuiltin("date.weekday", dateWeekday),
	},
}

Module is the curated date arithmetic a report script actually needs, and nothing else. Every function is a pure transformation of its arguments.

There is deliberately NO now() and no today(). A clock read is the single largest source of nondeterminism available to a script, and it is also unnecessary: the fire time is pinned onto run.fire_time when the run is created, so "yesterday" in a daily report is computed from a value recorded in the run record and the run reproduces exactly, months later, from that record. Adding now() would silently retire the determinism contract.

Dates are YYYY-MM-DD strings rather than an opaque object type. A date is crossing into SQL and into an output file either way, the string form is what an author reads in a log, and a string needs no marshaling contract of its own. Module is the date module the engine predeclares.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL