diff --git a/src/modules/Datetime/Calendar.js b/src/modules/Datetime/Calendar.js index 3a21d05e5a..7b22353cf6 100644 --- a/src/modules/Datetime/Calendar.js +++ b/src/modules/Datetime/Calendar.js @@ -196,6 +196,8 @@ export default class Calendar extends Component { if (range) { rangeState.selectionStart = date } + // TODO: WHen using native date, trySetState seems to not work + // well (value is not set), while setState does. this.trySetState({ value: selectedDate, mode: nextMode, diff --git a/src/modules/Datetime/handlers/moment.js b/src/modules/Datetime/handlers/moment.js index 7332b1ee34..9c49662845 100644 --- a/src/modules/Datetime/handlers/moment.js +++ b/src/modules/Datetime/handlers/moment.js @@ -85,6 +85,11 @@ export function getMomentDateHandler(settings={}) { } } + /** + * Returns a date of the first of the current month. + * A new instance is created as moment mutates the date + * when calling manipulation methods. + */ getFirstOfMonth(date) { date = date || this.date const newDate = moment.tz(date, date.tz()) @@ -96,22 +101,38 @@ export function getMomentDateHandler(settings={}) { return date.day() } + /** + * Returns the number of days in the month + */ daysInMonth(date) { date = date || this.date return date.daysInMonth() } + /** + * Create a new date, one month ago from current date. + * A new instance is created as moment mutates the date + * when calling manipulation methods. + */ lastMonth(date) { date = date || this.date const newDate = moment.tz(date, date.tz()) return newDate.subtract(1, 'months') } + /** + * Returns a YYYYMMDD string representation of this date. + * Used to create date signatures to determine disabled dates in a + * calendar month + */ getDateString(date) { date = date || this.date return date.format('YYYYMMDD') } + /** + * Returns a list of YYYYMMMDD date signatures for a list of dates + */ getDateStrings(dates) { if (dates && dates.length) { return dates.map(date => this.getDateString(date)) diff --git a/src/modules/Datetime/handlers/native.js b/src/modules/Datetime/handlers/native.js index 38d225d3da..d965761801 100644 --- a/src/modules/Datetime/handlers/native.js +++ b/src/modules/Datetime/handlers/native.js @@ -99,11 +99,19 @@ export function getNativeDateHandler(settings={}) { return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate() } + /** + * Returns a YYYYMMDD string representation of this date. + * Used to create date signatures to determine disabled dates in a + * calendar month + */ getDateString(date) { date = date || this.date return `${date.getFullYear()}${date.getMonth()}${date.getDate()}` } + /** + * Returns a list of YYYYMMMDD date signatures for a list of dates + */ getDateStrings(dates) { if (dates && dates.length) { return dates.map(date => this.getDateString(date))