@keen.io/time-utils
v1.3.0
Published
Keen time utilities
Downloads
170
Keywords
Readme
@keen.io/time-utils
Set of utilities and helper functions responsible for dates and time conversion.
API
getOffsetFromDate
Extracts UTC offset from provided date.
getOffsetFromDate('2021-03-14T16:00:00+03:00'); // 180
formatDate
Formats date based on provided pattern and timezone.
formatDate('2021-03-30T12:00:00+02:00', 'Europe/Warsaw', 'YYYY-MM-DD HH:mm'); // 2021-03-30 12:00
convertDate
Converts date based on provided offset in minutes or named timezone. Respects daylight saving time offsets.
convertDate('2021-03-14T16:00:00', 180); // 2021-03-14T19:00:00
convertDate('2021-03-14T16:00:00', -60); // 2021-03-14T15:00:00
convertDate('2021-03-14T16:00:00', 'Europe/Warsaw'); // 2021-03-14T17:00:00
setTimezoneOffset
Replaces timezone offset without modifying date.
setTimezoneOffset('2021-03-14T16:00:00-12:00', 'Europe/Warsaw'); // 2021-03-14T16:00:00+02:00
getDefaultAbsoluteTime
Creates default date range aligned with Keen API absolute Timeframe
interface.
// new Date() => 2021-03-31T00:00:00
getDefaultAbsoluteTime();
/* Object {
"start": "2021-03-30T00:00:00",
"end": "2021-03-31T00:00:00",
} */