Skip to content

gaslamp


Function: resampleDate()

resampleDate(time, freq, round?): number

Resamples a timestamp to a time bucket boundary.

Parameters

time

Cell

Timestamp to resample (Date object or milliseconds since epoch)

freq

string

Frequency string in format "Ns", "Nm", "Nh", "Nd", or "Nw"

round?

"floor" | "ceil" | "round"

Rounding method. Default: "floor"

Returns

number

Numeric timestamp (milliseconds since epoch) of the bucket boundary

Remarks

Converts a timestamp (Date or milliseconds) to a time bucket start using the specified frequency and rounding method. The result is returned as a numeric timestamp (milliseconds since epoch) for grouping in DataFrames.

Uses UTC (no timezone conversion). In Google Apps Script, if you need timezone-aware bucketing, use Utilities.formatDate() to convert the Date to a string in the desired timezone first, then parse back to determine the bucket.

Frequency format: "Ns", "Nm", "Nh", "Nd", "Nw" where N is a positive integer specifying the number of seconds, minutes, hours, days, or weeks.

Supported frequency examples: - "1s", "60s": 1 or 60 seconds - "1m", "15m": 1 or 15 minutes - "1h", "2h": 1 or 2 hours - "1d", "7d": 1 or 7 days - "1w", "2w": 1 or 2 weeks

Rounding methods: - "floor" (default): round down to bucket boundary - "ceil": round up to next bucket boundary - "round": round to nearest bucket boundary

Throws

Error when frequency string format is not recognized or N is not positive

Example

TypeScript
const time = new Date("2026-04-03T11:23:45Z");

resampleDate(time, "1h");
// 1743811200000 (2026-04-03T11:00:00Z)

resampleDate(time, "15m", "ceil");
// 1743811500000 (2026-04-03T11:30:00Z)

resampleDate(time, "1d");
// 1743724800000 (2026-04-03T00:00:00Z)

resampleDate(time, "30s", "round");
// 1743811230000 (2026-04-03T11:23:30Z)

// Use in resampleBy for time-based grouping
const df = gaslamp.BareFrame.fromSheet(sheet);
const summary = df.resampleBy("timestamp", "1h").sum(["amount"]);

Since

0.61.0