Skip to content

Invalid floor invocation from isTimeInterval #2447

Description

@mwaibel-go

Somewhere during binning of temporal data this function is executed:

plot/src/options.js

Lines 428 to 430 in 356f579

export function isTimeInterval(t) {
return isInterval(t) && typeof t?.floor === "function" && t.floor() instanceof Date;
}

Notice that no argument is passed to floor when the function tries to figure out if the result type is a Date.

This is in conflict with the type definitions, which indicate that a parameter to floor is guaranteed:

plot/src/interval.d.ts

Lines 34 to 47 in 356f579

/** A custom interval implementation. */
export interface IntervalImplementation<T> {
/**
* Returns the value representing the greatest interval boundary less than or
* equal to the specified *value*. For example, day.floor(*date*) typically
* returns 12:00 AM on the given date.
*
* This method is idempotent: if the specified value is already floored to the
* current interval, the same value is returned. Furthermore, the returned
* value is the minimum expressible value of the associated interval, such
* that floor(floor(*value*) - *epsilon*) returns the preceding interval
* boundary value.
*/
floor(value: T): T;

I believe the simplest fix would be

-   */
-  floor(value: T): T
+   *
+   * If no value is passed, the function is expected to return *any* result
+   * matching its return type.
+   */
+  floor(value?: T): T

Related: #2423

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions