Namespace: tech.v3.datatype.datetime
Autogenerated wrapper namespace providing thorough, mostly vectorized bindings to java.time via dtype-next. It exposes:
java.time types and Duration.This file focuses on how these pieces matter for lifting functionality into tablecloth.time.
:epoch-microseconds:epoch-milliseconds:epoch-seconds:epoch-daysjava.time.ZoneId or nil, where nil means UTC). When no timezone is given, defaults are usually UTC or type-dependent sensible defaults.In tablecloth.time, these functions will typically be called on columns (or column readers) rather than on individual scalar values.
tech.v3.datatype.datetime.constants is re-exposed via vars in this namespace:
milliseconds-in-secondmilliseconds-in-minutemilliseconds-in-hourmilliseconds-in-daymilliseconds-in-weekseconds-in-minuteseconds-in-hourseconds-in-daynanoseconds-in-millisecondnanoseconds-in-secondnanoseconds-in-minutenanoseconds-in-hournanoseconds-in-daynanoseconds-in-weekThese constants are the canonical source for converting between metric time units. When lifting to tablecloth.time, we should use these instead of hardcoding factors like 1000, 60, etc., especially when computing bucket sizes in milliseconds.
These wrap various java.time constructors and parsing facilities. They are mostly scalar-oriented but type-hinted and consistent with dtype-next:
instant → java.time.Instantlocal-date → java.time.LocalDatelocal-time → java.time.LocalTimelocal-date-time → java.time.LocalDateTimezoned-date-time → java.time.ZonedDateTimeduration → java.time.DurationEach constructor usually has two arities:
([] ...) – construct "now" or a default value.([arg] ...) – construct from a provided value (string, numeric, etc., depending on the specific base function).For tablecloth.time, these are less central; we’ll primarily operate on existing datetime columns coming from users or parsed elsewhere. But they can be handy in tests or for generating synthetic time series.
These queries help distinguish datetime/duration columns from other numeric or object columns:
datetime-datatype?
duration-datatype?
These are important for column dispatch inside tablecloth.time (e.g. deciding when a column can be treated as a datetime axis versus a generic numeric column).
datetime->epoch
(datetime->epoch timezone epoch-datatype data)(datetime->epoch epoch-datatype data)(datetime->epoch data):epoch-microseconds:epoch-milliseconds:epoch-seconds:epoch-daystimezone (a ZoneId) is provided, it’s used for conversions.epoch->datetime
(epoch->datetime timezone epoch-datatype datetime-datatype data)(epoch->datetime timezone datetime-datatype data)(epoch->datetime datetime-datatype data)datetime->epoch:
epoch-datatype is omitted.These are the most general conversion primitives in the API.
Two functions are especially central for tablecloth.time because they implement the "millis pivot" model:
datetime->milliseconds
(datetime->milliseconds timezone data)(datetime->milliseconds data):int64 representation.milliseconds->datetime
(milliseconds->datetime datatype timezone milli-data)(milliseconds->datetime datatype milli-data)These are the main bridge between human-friendly datetime columns and the numeric millis axis we’ll use internally for bucketing, slicing, and rolling operations in tablecloth.time.
The namespace also exposes a large set of more specific helpers, for scalar or vector data:
Epoch <-> Instant:
instant->microseconds-since-epochinstant->milliseconds-since-epochinstant->seconds-since-epochmicroseconds-since-epoch->instantmilliseconds-since-epoch->instantseconds-since-epoch->instantDays/months since epoch:
days-since-epoch->local-datelocal-date->days-since-epochepoch-days->epoch-monthsepoch-months->epoch-daysepoch-months->local-datelocal-date->epoch-monthsLocal date/time -> epoch millis/seconds (and back):
local-date->milliseconds-since-epochlocal-date-time->milliseconds-since-epochmilliseconds-since-epoch->local-datemilliseconds-since-epoch->local-date-timemilliseconds-since-epoch->local-timemilliseconds-since-epoch->zoned-date-timeLocal time conversions:
local-time->millisecondslocal-time->secondsseconds->local-timeComposition between LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Instant:
local-date->instant, local-date->local-date-time, local-date->zoned-date-timelocal-date-time->instant, local-date-time->local-date, local-date-time->local-time, local-date-time->zoned-date-timelocal-time->instant, local-time->local-date-timeinstant->local-date-time, instant->zoned-date-timezoned-date-time->instant, zoned-date-time->milliseconds-since-epochFor tablecloth.time, we will rarely need these directly; instead we’ll standardize on millis and use datetime->milliseconds / milliseconds->datetime. However, these helpers are useful when we need calendar-aware operations (e.g. converting millis buckets to LocalDate ends).
Duration-related functions work with java.time.Duration and associated numeric encodings:
Construction and inspection:
duration → construct a Duration.duration->millisecondsduration->nanosecondsConversions from primitive counts:
milliseconds->durationnanoseconds->durationTogether with the unit constants, this lets us mix duration objects and numeric millisecond/nanosecond representations. Tablecloth’s time API will probably treat most user-facing durations as {:amount n :unit :minutes} or similar, but we can use these functions internally when we need true Duration objects.
plus-temporal-amount
(plus-temporal-amount datetime-data long-data tf)(plus-temporal-amount datetime-data long-data)minus-temporal-amount
(minus-temporal-amount datetime-data long-data tf)(minus-temporal-amount datetime-data long-data)Common characteristics:
datetime-data: scalar or vector of datetime values.long-data: scalar or vector of integer counts (e.g. number of days / hours to add).tf: temporal field / unit. Supported units (from the docstrings):
#{:months :days :seconds :hours :years :milliseconds :minutes :weeks}These functions handle the details of adding/subtracting amounts across the different supported datetime datatypes. They are natural building blocks for tablecloth.time operations like:
between
(between lhs rhs units)lhs and rhs must have the same datatype.units may be a ChronoUnit or a keyword in:
#{:milliseconds :seconds :minutes :hours :days :weeks :months :years}longs or long readers.between is the canonical way to compute durations between columns (or rows) without manually going through milliseconds. Units closely match those supported by plus-temporal-amount / minus-temporal-amount.
long-temporal-field
(long-temporal-field tf data):iso-day-of-week:iso-week-of-year:day-of-week:months:days:seconds:epoch-days:day-of-year:hours:years:milliseconds:minutes:week-of-yearThis is the main hook for derived calendar columns in tablecloth.time: year, month, day-of-week, week-of-year, etc., derived from a datetime column.
millisecond-descriptive-statistics
(millisecond-descriptive-statistics stats-seq options data)(millisecond-descriptive-statistics data)min, mean, max are returned as unpacked datetime objects.This function can be used to implement tablecloth.time helpers like "per-group datetime min/mean/max" while keeping millisecond semantics consistent.
The namespace re-exports a few simple helpers for working with zones and offsets:
system-zone-id → java.time.ZoneId for the system default.system-zone-offset → java.time.ZoneOffset for the system default.utc-zone-id → UTC ZoneId.utc-zone-offset → UTC ZoneOffset.In tablecloth.time, we may surface UTC as the default and allow options maps to override the zone using these helpers.
variable-rolling-window-ranges
(variable-rolling-window-ranges src-data window-length units options)(variable-rolling-window-ranges src-data window-length units)Behavior:
src-data must be a monotonically increasing datetime series (reader).tech.v3.datatype.rolling/variable-rolling-window-ranges, including :stepsize and others.This is the critical low-level primitive for time-based rolling operations in tablecloth.time (e.g. rolling means over a 5-minute window on a time axis).
When lifting functionality into tablecloth.time, we likely want to build a small, coherent subset of higher-level operations around these core pieces:
Millis pivot conversions
datetime->milliseconds / milliseconds->datetime as the primary bridge between logical datetime columns and numeric millis columns.milliseconds-in-*, seconds-in-*, etc.) to derive bucket sizes and windows.Column-wise temporal arithmetic
plus-temporal-amount / minus-temporal-amount to implement operations such as:
shift-time (add/subtract fixed offsets in various units).Differences and durations
between for column-wise differences (e.g. time since previous event, latency between two timestamps).Derived calendar features
long-temporal-field to build column helpers like:
year, month, day-of-month, day-of-week, week-of-year.tablecloth.column.time and dataset-level helpers in tablecloth.time.api.*.Descriptive statistics
millisecond-descriptive-statistics for summarizing datetime columns, especially when we want:
Rolling windows
variable-rolling-window-ranges as the basis for time-based rolling operations, combined with dataset-level aggregation:
Timezone semantics
:timezone in tablecloth.time options.datetime->milliseconds / milliseconds->datetime / epoch->datetime as needed.Overall, tech.v3.datatype.datetime provides the low-level, type-correct, vectorized building blocks for time handling. tablecloth.time should:
datetime->milliseconds, milliseconds->datetime, between, plus-temporal-amount, long-temporal-field, and variable-rolling-window-ranges) to implement higher-level column and dataset APIs with clear, documented semantics.Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |