UNPKG

react-dates

Version:

A responsive and accessible date range picker component built with React

11 lines (10 loc) 615 B
import moment from 'moment'; import toMomentObject from './toMomentObject'; export default function toISODateString(date, currentFormat) { var dateObj = moment.isMoment(date) ? date : toMomentObject(date, currentFormat); if (!dateObj) return null; // Template strings compiled in strict mode uses concat, which is slow. Since // this code is in a hot path and we want it to be as fast as possible, we // want to use old-fashioned +. // eslint-disable-next-line prefer-template return dateObj.year() + '-' + String(dateObj.month() + 1).padStart(2, '0') + '-' + String(dateObj.date()).padStart(2, '0'); }