interval.floor()

interval.floor(date)

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 preceeding 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:

// Returns true if the specified date is a day boundary.
function isDay(date) {
  return +d3.timeDay.floor(date) === +date;
}

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.

doc_D3_Js
2016-11-24 10:27:54
Comments
Leave a Comment

Please login to continue.