Interface CountableTimeInterval

A D3 Countable Time Interval

interface CountableTimeInterval {
    ceil(date): Date;
    count(start, end): number;
    every(step): TimeInterval;
    filter(test): TimeInterval;
    floor(date): Date;
    offset(date, step?): Date;
    range(start, stop, step?): Date[];
    round(date): Date;
    (date?): Date;
}

Hierarchy

  • Returns a new date representing the latest interval boundary date before or equal to date. Equivalent to interval.floor, except it date is not specified, it defaults to the current time. For example, d3.timeYear(date) and d3.timeYear.floor(date) are equivalent.

    For example, timeDay(date) typically returns 12:00 AM local time on the given date.

    This function is idempotent: if the specified date is already floored to the current interval, a new date with an identical time is returned. Furthermore, the returned date is the minimum expressible value of the associated interval, such that interval.floor(interval.floor(date) - 1) returns the preceding interval boundary date.

    Note that the == and === operators do not compare by value with Date objects, and thus you cannot use them to tell whether the specified date has already been floored. Instead, coerce to a number and then compare.

    This is more reliable than testing whether the time is 12:00 AM, as in some time zones midnight may not exist due to daylight saving.

    Parameters

    • Optional date: Date

      A date object.

    Returns Date

Methods

  • Returns a new date representing the earliest interval boundary date after or equal to date.

    For example, timeDay.ceil(date) typically returns 12:00 AM local time on the date following the given date.

    This method is idempotent: if the specified date is already ceilinged to the current interval, a new date with an identical time is returned. Furthermore, the returned date is the maximum expressible value of the associated interval, such that interval.ceil(interval.ceil(date) + 1) returns the following interval boundary date.

    Parameters

    • date: Date

      A date object.

    Returns Date

  • Returns the number of interval boundaries after start (exclusive) and before or equal to end (inclusive).

    Note that this behavior is slightly different than interval.range, because its purpose is to return the zero-based number of the specified end date relative to the specified start date.

    Parameters

    • start: Date

      A start date object.

    • end: Date

      An end date object.

    Returns number

  • Returns a filtered view of this interval representing every stepth date.

    The meaning of step is dependent on this interval’s parent interval as defined by the field function.

    For example, timeMinute.every(15) returns an interval representing every fifteen minutes, starting on the hour: :00, :15, :30, :45, etc. Note that for some intervals, the resulting dates may not be uniformly-spaced; timeDay’s parent interval is timeMonth, and thus the interval number resets at the start of each month.

    If step is not valid, returns null. If step is one, returns this interval.

    This method can be used in conjunction with interval.range to ensure that two overlapping ranges are consistent.

    The returned filtered interval does not support interval.count. See also interval.filter.

    Parameters

    • step: number

      Number of steps.

    Returns TimeInterval

  • Returns a new interval that is a filtered subset of this interval using the specified test function.

    Parameters

    • test: ((date) => boolean)

      A test function which is passed a date and should return true if and only if the specified date should be considered part of the interval.

        • (date): boolean
        • Parameters

          Returns boolean

    Returns TimeInterval

  • Returns a new date representing the latest interval boundary date before or equal to date.

    For example, timeDay.floor(date) typically returns 12:00 AM local time on the given date.

    This method is idempotent: if the specified date is already floored to the current interval, a new date with an identical time is returned. Furthermore, the returned date is the minimum expressible value of the associated interval, such that interval.floor(interval.floor(date) - 1) returns the preceding interval boundary date.

    Note that the == and === operators do not compare by value with Date objects, and thus you cannot use them to tell whether the specified date has already been floored. Instead, coerce to a number and then compare.

    This is more reliable than testing whether the time is 12:00 AM, as in some time zones midnight may not exist due to daylight saving.

    Parameters

    • date: Date

      A date object.

    Returns Date

  • Returns a new date equal to date plus step intervals.

    If step is not specified it defaults to 1.

    This method does not round the specified date to the interval. For example, if date is today at 5:34 PM, then timeDay.offset(date, 1) returns 5:34 PM tomorrow (even if daylight saving changes!).

    Parameters

    • date: Date

      A date object.

    • Optional step: number

      An optional number of steps to apply when calculating the offset date. If step is negative, then the returned date will be before the specified date; if step is zero, then a copy of the specified date is returned; if step is not an integer, it is floored.

    Returns Date

  • Returns an array of dates representing every interval boundary after or equal to start (inclusive) and before stop (exclusive).

    If step is specified, then every step-th boundary will be returned; for example, for the timeDay interval a step of 2 will return every other day. If step is not an integer, it is floored.

    The first date in the returned array is the earliest boundary after or equal to start; subsequent dates are offset by step intervals and floored. Thus, two overlapping ranges may be inconsistent.

    To make ranges consistent when a step is specified, use CountableInterval.every instead.

    Parameters

    • start: Date

      A start date object for the range.

    • stop: Date

      A stop date object for the range.

    • Optional step: number

      An optional number of steps to apply when calculating the dates in the range.

    Returns Date[]

  • Returns a new date representing the closest interval boundary date to date.

    For example, timeDay.round(date) typically returns 12:00 AM local time on the given date if it is on or before noon, and 12:00 AM of the following day if it is after noon.

    This method is idempotent: if the specified date is already rounded to the current interval, a new date with an identical time is returned.

    Parameters

    • date: Date

      A date object.

    Returns Date