@terascope/data-mate / function-configs/date/sql-utils
function-configs/date/sql-utils
Functions
afterNow()
afterNow(
value):string
Defined in: data-mate/src/function-configs/date/sql-utils.ts:218
value is strictly after the plan-time instant.
Parameters
| Parameter | Type |
|---|---|
value | string |
Returns
string
beforeNow()
beforeNow(
value):string
Defined in: data-mate/src/function-configs/date/sql-utils.ts:223
value is strictly before the plan-time instant.
Parameters
| Parameter | Type |
|---|---|
value | string |
Returns
string
currentOffsetMinutes()
currentOffsetMinutes(
timezone):number|undefined
Defined in: data-mate/src/function-configs/date/sql-utils.ts:162
A timezone's current offset in minutes, resolved in JavaScript with timezoneToOffset as
setTimezone does. Returns undefined when core-utils cannot resolve the zone, so the UDF runs
and fails or returns null as it does in DataFrame.
Parameters
| Parameter | Type |
|---|---|
timezone | unknown |
Returns
number | undefined
dateWithOffset()
dateWithOffset(
instant,offsetMinutes):string
Defined in: data-mate/src/function-configs/date/sql-utils.ts:152
A date value with a display offset, { ms, tz_offset }: how TealFrame stores a DateTuple
([ms, offset], see teal-frame/date-value.ts). The member names are written out here
because function configs do not depend on TealFrame. instant is a TIMESTAMP; NULL gives NULL.
Parameters
| Parameter | Type |
|---|---|
instant | string |
offsetMinutes | string |
Returns
string
isDateArg()
isDateArg(
value):boolean
Defined in: data-mate/src/function-configs/date/sql-utils.ts:30
True when the argument resolves to a date, so a SQL expression can be built for it.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
boolean
isEpochInterval()
isEpochInterval(
args):boolean
Defined in: data-mate/src/function-configs/date/sql-utils.ts:122
True when getTimeBetween can run as SQL for these arguments.
Parameters
| Parameter | Type |
|---|---|
args | TimeBetweenArgs |
Returns
boolean
isTimeOnlyAdjustment()
isTimeOnlyAdjustment(
args):boolean
Defined in: data-mate/src/function-configs/date/sql-utils.ts:78
True when the arguments use only units SQL reproduces exactly. See TIME_UNITS.
Parameters
| Parameter | Type |
|---|---|
args | Record<string, any> |
Returns
boolean
onLocalDay()
onLocalDay(
value,offset):string
Defined in: data-mate/src/function-configs/date/sql-utils.ts:212
value falls on the local day offset days from today.
Parameters
| Parameter | Type |
|---|---|
value | string |
offset | number |
Returns
string
replaceField()
replaceField(
value,parent,unit,offset):string
Defined in: data-mate/src/function-configs/date/sql-utils.ts:48
Replaces one field of a timestamp, keeping the finer fields and rolling over the way JavaScript does.
In JavaScript, setUTCDate(31) on a February date gives March 3. DuckDB's
+ INTERVAL n MONTH clamps instead (Jan 31 plus a month is Feb 28), so adding to the original
timestamp would give a different answer. Starting from the enclosing unit's boundary avoids
the clamp: the day-of-month is then 1, and the offsets added after it are plain day and time
arithmetic that overflows the same way in both. Feb 1 + 30 days is March 3 in both.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | - |
parent | string | the unit that encloses the field being set, e.g. 'month' for a day-of-month |
unit | string | the field being set |
offset | string | how far past the parent boundary the new value sits, as SQL |
Returns
string
timeBetween()
timeBetween(
value,args):string
Defined in: data-mate/src/function-configs/date/sql-utils.ts:135
The elapsed time between the column and the fixed end, truncated to the interval.
The sign follows _getStartEndTime: with start the column is the later value, with end
it is the earlier one.
Parameters
| Parameter | Type |
|---|---|
value | string |
args | TimeBetweenArgs |
Returns
string
timeInterval()
timeInterval(
args):string|null
Defined in: data-mate/src/function-configs/date/sql-utils.ts:89
The adjustment as a SQL interval, or null when there is nothing to add.
A null means the value passes through unchanged, which is what an empty duration - or one made up
only of the ignored milliseconds - does in JavaScript.
Parameters
| Parameter | Type |
|---|---|
args | Record<string, any> |
Returns
string | null
timestampLiteral()
timestampLiteral(
value):string|null
Defined in: data-mate/src/function-configs/date/sql-utils.ts:22
A TIMESTAMP literal for a date argument, resolved when the query is planned.
It uses the UDF's own converter, getValidDateWithTimezone, so it accepts the same forms: a
string, epoch millis, a Date or a DateTuple. validate_arguments has already rejected
invalid input; the null return exists only because the converter's type allows it.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
string | null
timezoneOffsetMinutes()
timezoneOffsetMinutes(
value,zone):string
Defined in: data-mate/src/function-configs/date/sql-utils.ts:181
The offset of zone from UTC in minutes, per row, as toTimeZone attaches it.
It is the zone's offset at the local wall time equal to the UTC instant, not at the instant
itself, because that is what core-utils' getTimezoneOffset returns. The two differ only
within a few hours of a DST change. The result does not depend on the host timezone.
The order of the two AT TIME ZONE steps matters: reversed, every non-UTC zone gets the wrong
sign (America/New_York in January would be 300 instead of -300).
Parameters
| Parameter | Type |
|---|---|
value | string |
zone | string |
Returns
string