# floordate

> Simple date flooring, floor a date to the start of a specified time window.

Latest version **3.0.0** (published 2016-08-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install floordate
pnpm add floordate
yarn add floordate
bun add floordate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2016-08-30 |
| First published | 2013-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Bryce B. Baril |
| Maintainers | bryce |
| Keywords | date, floor, time |

## Links

- npm: https://www.npmjs.com/package/floordate
- Repository: https://github.com/brycebaril/node-floordate
- Homepage: https://github.com/brycebaril/node-floordate#readme
- Issues: https://github.com/brycebaril/node-floordate/issues
- npm.io page: https://npm.io/package/floordate

## Dependencies (1)

- [isnumber](https://npm.io/package/isnumber.md) ~1.0.0

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2016-08-30
- 2.0.0 — 2014-09-23
- 1.0.2 — 2014-01-31
- 1.0.1 — 2013-08-16

## README

floordate
=========

[![NPM](https://nodei.co/npm/floordate.png)](https://nodei.co/npm/floordate/)

`floordate` is a simple function for setting a date to the beginning of a standard time threshold. E.g. the beginning of the month, year, week, etc.

```js
var floorDate = require("floordate")

var d = new Date()
// Thu Aug 15 2013 19:38:49 GMT-0700 (PDT)

floorDate(d, 5000) // floor to the nearest 5000 ms interval prior to now
// Thu Aug 15 2013 19:38:45 GMT-0700 (PDT)

floorDate(d, "second")
// Thu Aug 15 2013 19:38:45 GMT-0700 (PDT)
// or
floorDate.toSecond(d)
// Thu Aug 15 2013 19:38:45 GMT-0700 (PDT)

floorDate(d, "minute")
// Thu Aug 15 2013 19:38:00 GMT-0700 (PDT)

floorDate(d, "hour")
// Thu Aug 15 2013 19:00:00 GMT-0700 (PDT)

floorDate(d, "day")
// Thu Aug 15 2013 00:00:00 GMT-0700 (PDT)

floorDate(d, "week")
// Sun Aug 11 2013 00:00:00 GMT-0700 (PDT)

floorDate(d, "quarter")
// Mon Jul 01 2013 00:00:00 GMT-0700 (PDT)

floorDate(d, "year")
// Tue Jan 01 2013 00:00:00 GMT-0800 (PST)

floorDate(d, "day", "UTC")
// Thu Aug 15 2013 07:00:00 GMT-0700 (PDT)

```

API
===

`floorDate(date, threshold[, timezoneOffset])`
----------------------

Floor a date to the beginning of the specified threshold. If provided with a desired timezoneOffset, it will convert from the current **LOCALE** timezone to the offset specified.

  * date: date can be a Date or a millisecond epoch timestamp
  * threshold: threshold can be a number of milliseconds, or a time threshold matching the following:
    * s, sec, secs, second, seconds
    * m, min, mins, minute, minutes
    * h, hr, hrs, hour, hours
    * d, day, days
    * w, wk, wks, week, weeks
    * M, mon, mons, month, months
    * y, yr, yrs, year, years
    * q, qtr, qtrs, quarter, quarters
  * timezoneOffset: (in minutes, e.g. Date.getTimezoneOffset())
    * Also accepts "UTC" as an alias for offset 0

Note about DST:
---

Timezone conversion is applied on the resulting date -- e.g. it will look at the local offset of the resulting floored date, then apply the offset to return a Date object with the offset applied.

This means it is the responsibility of the user to correctly specify the desired timezone offset including DST for the **resulting** date, which may be different.

Aliases
-------

  * `floorDate.toSecond(date[, timezoneOffset])`
  * `floorDate.toMinute(date[, timezoneOffset])`
  * `floorDate.toHour(date[, timezoneOffset])`
  * `floorDate.toDay(date[, timezoneOffset])`
  * `floorDate.toWeek(date[, timezoneOffset])`
  * `floorDate.toMonth(date[, timezoneOffset])`
  * `floorDate.toQuarter(date[, timezoneOffset])`
  * `floorDate.toYear(date[, timezoneOffset])`

LICENSE
=======
MIT

---
_Source: https://npm.io/package/floordate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
