Skip to content

Commit

Permalink
Added default unix timestamp format
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Gevers committed Jun 26, 2014
1 parent 4e47e69 commit 52d0b76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions ember-datepicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(function() {
Em.DatePickerComponent = Em.TextField.extend({
isUnix: true,
format: 'YYYY-MM-DD',
defaultDate: function() { // must be a moment value
return moment().format(this.get('format'));
Expand All @@ -22,8 +23,12 @@
that.set('date', moment(that.get('value')));
}
}),
dd = that.get('date') || that.get('defaultDate');
picker.setDate(moment(dd).format(that.get('format')));
dd = that.get('date');
if (this.get('isUnix') && !Em.isBlank(dd)) {
picker.setDate(moment.unix(dd).format(that.get('format')));
} else {
picker.setDate(moment(dd).format(that.get('format')));
}
this.set("_picker", picker);
}
});
Expand Down
10 changes: 8 additions & 2 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* the calendar widget.
*/
Em.DatePickerComponent = Em.TextField.extend({
isUnix: true, // unix timestamp format
format: 'YYYY-MM-DD',
defaultDate: function() { // must be a moment value
return moment().format(this.get('format'));
Expand All @@ -25,8 +26,13 @@ Em.DatePickerComponent = Em.TextField.extend({
that.set('date', moment(that.get('value')));
}
}),
dd = that.get('date') || that.get('defaultDate');
picker.setDate(moment(dd).format(that.get('format')));
dd = that.get('date');
if (this.get('isUnix') && !Em.isBlank(dd)) {
picker.setDate(moment.unix(dd).format(that.get('format')));
} else {
picker.setDate(moment(dd).format(that.get('format')));
}
this.set("_picker", picker);
this.set("_picker", picker);
}
});
Expand Down

0 comments on commit 52d0b76

Please sign in to comment.