https://github.com/arshadkazmi42/datetime-round
Round off datetime to fixed time interval
https://github.com/arshadkazmi42/datetime-round
ceil date datetime datetime-round floor math moment round time
Last synced: 3 months ago
JSON representation
Round off datetime to fixed time interval
- Host: GitHub
- URL: https://github.com/arshadkazmi42/datetime-round
- Owner: arshadkazmi42
- License: mit
- Created: 2019-08-30T16:54:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-07-14T06:10:07.000Z (about 3 years ago)
- Last Synced: 2025-05-08T03:16:48.761Z (5 months ago)
- Topics: ceil, date, datetime, datetime-round, floor, math, moment, round, time
- Language: JavaScript
- Size: 61.5 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# datetime-round
[](https://github.com/arshadkazmi42/datetime-round/actions/workflows/nodejs.yml)
[](https://www.npmjs.com/package/datetime-round)
[](https://www.npmjs.com/package/datetime-round)
[](https://github.com/arshadkazmi42/datetime-round)
[](https://github.com/arshadkazmi42/datetime-round/blob/master/LICENSE)
[](https://github.com/arshadkazmi42/datetime-round/graphs/contributors)
[](https://github.com/arshadkazmi42/datetime-round/commits/master)Rounds off datetime to nearest interval
## Install
```
npm i datetime-round
```## Usage
```javascript
const DatetimeRound = require('datetime-round');
DatetimeRound(moment('2019-08-30 10:11:25'), 30, 'minutes', 'ceil')
.format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:30:00DatetimeRound(moment('2019-08-30 10:11:25'), 30, 'minutes', 'floor')
.format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:00:00DatetimeRound(moment('2019-08-30 10:11:25'), 10, 'minutes', 'ceil')
.format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:20:00DatetimeRound(moment('2019-08-30 10:11:25'), 10, 'minutes', 'floor')
.format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:10:00DatetimeRound(moment('2019-08-30 10:11:25'), 5, 'minutes', 'ceil')
.format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:15:00DatetimeRound(moment('2019-08-30 10:11:25'), 5, 'minutes', 'floor')
.format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:10:00```
## Params
DatetimeRound will accept following parameters as input
- **date**: String datetime / moment object
- **interval**: Time interval till which time needs to be rounded to (integer)
- **intervalType**: Type of interval (`minutes`, `hours`, `seconds`)
> Refer to moment.duration docs for all available formats.
- **method**: Rounding method, `floor`, `ceil` .... (It supports all the round methods available in NodeJS `Math` package)## Contributing
Interested in contributing to this project?
You can log any issues or suggestion related to this library [here](https://github.com/arshadkazmi42/datetime-round/issues/new)Read our contributing [guide](CONTRIBUTING.md) on getting started with contributing to the codebase