Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
harel committed Apr 17, 2017
1 parent 49e5c3b commit 7dd4b78
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/modules/Datetime/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/modules/Datetime/handlers/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions src/modules/Datetime/handlers/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 7dd4b78

Please sign in to comment.