https://github.com/oeo/timebase
https://github.com/oeo/timebase
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/oeo/timebase
- Owner: oeo
- Created: 2024-10-23T22:34:59.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-10-24T01:21:41.000Z (7 months ago)
- Last Synced: 2025-04-13T05:09:18.111Z (about 1 month ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README

# timebase
get the start of a time period. uses just a singular runtime dependency, [moment-timezone](https://www.npmjs.com/package/moment-timezone).
## install
```bash
npm install timebase --save
```## use
```javascript
const timebase = require('timebase');
timebase.DEFAULT_TIMEZONE = 'UTC';// return the 00:00:00 unix timestamp of the current day
console.log(timebase());// return the 00:00:00 unix timestamp of yesterday
let yesterday = timebase(timebase() - 1);
console.log(timebase(yesterday));// give me the start of the day as a timestamp for the given unix timestamp
console.log(timebase(1684108800, {startPoint: 'day', timezone: 'America/New_York'}));// start of current hour for now
console.log(timebase({startPoint: 'hour'}));// start of month for now
console.log(timebase({startPoint: 'month'}));// start of year as a date object
console.log(timebase({startPoint: 'year', format: 'date'}));// start of the day for this date
console.log(timebase('2023-05-15T14:30:00Z'));// start of minute for now
console.log(timebase({startPoint: 'minute'}));
```## options
- startPoint: 'minute', 'hour', 'day', 'month', 'year' (default: 'day')
- format: 'unixSeconds', 'unixMilliseconds', 'date' (default: 'unixSeconds')
- timezone: 'America/New_York', 'UTC', etc (default: timebase.DEFAULT_TIMEZONE)## license
mit