This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/date-time-input.js.es6
2019-07-18 17:29:41 +02:00

36 lines
912 B
JavaScript

export default Ember.Component.extend({
classNames: ["d-date-time-input"],
date: null,
showTime: true,
_hours: Ember.computed("date", function() {
return this.date ? this.date.getHours() : null;
}),
_minutes: Ember.computed("date", function() {
return this.date ? this.date.getMinutes() : null;
}),
actions: {
onChangeTime(time) {
if (this.onChange) {
const year = this.date.getFullYear();
const month = this.date.getMonth();
const day = this.date.getDate();
this.onChange(new Date(year, month, day, time.hours, time.minutes));
}
},
onChangeDate(date) {
if (this.onChange) {
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();
this.onChange(
new Date(year, month, day, this._hours || 0, this._minutes || 0)
);
}
}
}
});