Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
clear: function( options ) {
return P.set( 'clear', null, options )
}, //clear


/**
* Sets calendar view to current day
*/
today: function() {
return P.set( 'view', new Date() )
}, //today


/**
Expand Down
22 changes: 22 additions & 0 deletions tests/units/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,28 @@ test( '`clear`', function() {
strictEqual( picker.get('select'), null, 'Clears out selection' )
})

test( '`today`', function() {

var picker = this.picker
var dateToday = new Date()

dateToday.setHours(0,0,0,0)
dateToday.setDate(1)

var dateYearAgo = new Date(dateToday.valueOf())

dateYearAgo = new Date(dateYearAgo.setFullYear(new Date().getFullYear() - 1))
dateYearAgo.setHours(0,0,0,0)

strictEqual( picker.get('select'), null, 'Starts off without a selection' )

picker.set('select', dateYearAgo)
strictEqual( picker.get('view').obj.toString(), dateYearAgo.toString(), 'Set date to last year' )

picker.today()
notStrictEqual( picker.get('view').obj, dateToday, 'Today date is back' )
})

test( '`select`', function() {

var picker = this.picker,
Expand Down