UNPKG

@barinbritva/add-to-calendar

Version:

[![Dependencies counter](https://img.shields.io/badge/dependencies-none-green?style=flat-square)](https://github.com/barinbritva/add-to-calendar/blob/master/package.json) [![License](https://img.shields.io/npm/l/micromatch?style=flat-square)](https://gith

24 lines (23 loc) 1.05 kB
export class DateHelper { static dateToDateString(date) { const year = date.getFullYear(); const month = DateHelper.addLeadingZeroIfNeeded(date.getMonth() + 1); const day = DateHelper.addLeadingZeroIfNeeded(date.getDate()); return `${year}-${month}-${day}`; } static dateToDateTimeString(date) { const year = date.getUTCFullYear(); const month = DateHelper.addLeadingZeroIfNeeded(date.getUTCMonth() + 1); const day = DateHelper.addLeadingZeroIfNeeded(date.getUTCDate()); const hours = DateHelper.addLeadingZeroIfNeeded(date.getUTCHours()); const minutes = DateHelper.addLeadingZeroIfNeeded(date.getUTCMinutes()); const seconds = DateHelper.addLeadingZeroIfNeeded(date.getUTCSeconds()); return `${year}-${month}-${day}` + `T${hours}:${minutes}:${seconds}Z`; } static cloneDate(date) { return new Date(date.getTime()); } static addLeadingZeroIfNeeded(value) { return value > 9 ? String(value) : '0' + value; } }