UNPKG

@uwdata/mosaic-sql

Version:

SQL query construction and analysis.

45 lines 1.55 kB
import { asNode } from '../util/ast.js'; import { fn } from '../util/function.js'; import { interval } from './interval.js'; /** * Given a date/time value, return the milliseconds since the UNIX epoch. * @param {ExprValue} expr The date/time expression. */ export function epoch_ms(expr) { return fn('epoch_ms', expr); } /** * Perform data binning according to the provided interval unit and steps. * @param expr The date/time expression to bin. * @param unit The datetime interval unit to bin by. * @param steps The number of interval steps. */ export function dateBin(expr, unit, steps = 1) { return fn('time_bucket', interval(unit, steps), expr); } /** * Map date/times to a month value, all within the same year for comparison. * The resulting value is still date-typed. * @param expr The date/time expression. */ export function dateMonth(expr) { return fn('make_date', 2012, fn('month', expr), 1); } /** * Map date/times to a month and day value, all within the same year for * comparison. The resulting value is still date-typed. * @param expr The date/time expression. */ export function dateMonthDay(expr) { const d = asNode(expr); return fn('make_date', 2012, fn('month', d), fn('day', d)); } /** * Map date/times to a day of the month value, all within the same year and month * for comparison. The resulting value is still date-typed. * @param expr The date/time expression. */ export function dateDay(expr) { return fn('make_date', 2012, 1, fn('day', expr)); } //# sourceMappingURL=datetime.js.map