Skip to content

Commit b24c288

Browse files
committed
fix: resolve whack-a-mole behavior of time/date pickers
1 parent 8fa3060 commit b24c288

File tree

9 files changed

+36
-20
lines changed

9 files changed

+36
-20
lines changed

app/components/widgets/forms/time-picker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ export default Component.extend({
3838
}
3939

4040
this.$().calendar(merge(defaultOptions, this.options));
41+
},
42+
actions: {
43+
onChange() {
44+
if (this.onChange) {
45+
this.sendAction('onChange', this.value);
46+
}
47+
}
4148
}
4249

4350
});

app/models/access-code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export default ModelBase.extend({
2828
* Computed properties
2929
*/
3030

31-
validFromDate : computedDateTimeSplit.bind(this)('validFrom', 'date'),
32-
validFromTime : computedDateTimeSplit.bind(this)('validFrom', 'time'),
31+
validFromDate : computedDateTimeSplit.bind(this)('validFrom', 'date', 'validTill'),
32+
validFromTime : computedDateTimeSplit.bind(this)('validFrom', 'time', 'validTill'),
3333
validTillDate : computedDateTimeSplit.bind(this)('validTill', 'date'),
3434
validTillTime : computedDateTimeSplit.bind(this)('validTill', 'time')
3535
});

app/models/discount-code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export default ModelBase.extend({
4242
}), // The events that this discount code has been applied to [Form (1)]
4343
marketer: belongsTo('user'),
4444

45-
validFromDate : computedDateTimeSplit.bind(this)('validFrom', 'date'),
46-
validFromTime : computedDateTimeSplit.bind(this)('validFrom', 'time'),
45+
validFromDate : computedDateTimeSplit.bind(this)('validFrom', 'date', 'validTill'),
46+
validFromTime : computedDateTimeSplit.bind(this)('validFrom', 'time', 'validTill'),
4747
validTillDate : computedDateTimeSplit.bind(this)('validTill', 'date'),
4848
validTillTime : computedDateTimeSplit.bind(this)('validTill', 'time')
4949
});

app/models/event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export default ModelBase.extend(CustomPrimaryKeyMixin, {
147147
* Computed properties
148148
*/
149149

150-
startsAtDate : computedDateTimeSplit.bind(this)('startsAt', 'date'),
151-
startsAtTime : computedDateTimeSplit.bind(this)('startsAt', 'time'),
150+
startsAtDate : computedDateTimeSplit.bind(this)('startsAt', 'date', 'endsAt'),
151+
startsAtTime : computedDateTimeSplit.bind(this)('startsAt', 'time', 'endsAt'),
152152
endsAtDate : computedDateTimeSplit.bind(this)('endsAt', 'date'),
153153
endsAtTime : computedDateTimeSplit.bind(this)('endsAt', 'time'),
154154

app/models/session.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export default ModelBase.extend({
4848
}
4949
}),
5050

51-
startAtDate : computedDateTimeSplit.bind(this)('startsAt', 'date'),
52-
startAtTime : computedDateTimeSplit.bind(this)('startsAt', 'time'),
51+
startAtDate : computedDateTimeSplit.bind(this)('startsAt', 'date', 'endsAt'),
52+
startAtTime : computedDateTimeSplit.bind(this)('startsAt', 'time', 'endsAt'),
5353
endsAtDate : computedDateTimeSplit.bind(this)('endsAt', 'date'),
5454
endsAtTime : computedDateTimeSplit.bind(this)('endsAt', 'time'),
5555

app/models/speakers-call.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export default ModelBase.extend({
1717

1818
event: belongsTo('event'),
1919

20-
startsAtDate : computedDateTimeSplit.bind(this)('startsAt', 'date'),
21-
startsAtTime : computedDateTimeSplit.bind(this)('startsAt', 'time'),
20+
startsAtDate : computedDateTimeSplit.bind(this)('startsAt', 'date', 'endsAt'),
21+
startsAtTime : computedDateTimeSplit.bind(this)('startsAt', 'time', 'endsAt'),
2222
endsAtDate : computedDateTimeSplit.bind(this)('endsAt', 'date'),
2323
endsAtTime : computedDateTimeSplit.bind(this)('endsAt', 'time'),
2424

app/models/ticket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export default ModelBase.extend({
3939
/**
4040
* Computed properties
4141
*/
42-
salesStartAtDate : computedDateTimeSplit.bind(this)('salesStartsAt', 'date'),
43-
salesStartAtTime : computedDateTimeSplit.bind(this)('salesStartsAt', 'time'),
42+
salesStartAtDate : computedDateTimeSplit.bind(this)('salesStartsAt', 'date', 'salesEndsAt'),
43+
salesStartAtTime : computedDateTimeSplit.bind(this)('salesStartsAt', 'time', 'salesEndsAt'),
4444
salesEndsAtDate : computedDateTimeSplit.bind(this)('salesEndsAt', 'date'),
4545
salesEndsAtTime : computedDateTimeSplit.bind(this)('salesEndsAt', 'time'),
4646

app/utils/computed-helpers.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,27 @@ export const computedSegmentedLink = function(property) {
3838
};
3939

4040
/**
41-
* Get set splitted date time from/to a Full datetime object
41+
* Get, set split date time from/to a Full datetime object
4242
* @param property The full date time object
4343
* @param segmentFormat The part of the date to be returned. (time/date or a custom format)
44+
* @param endProperty Optional end field name for date or time.
4445
* @returns {*}
4546
*/
46-
export const computedDateTimeSplit = function(property, segmentFormat) {
47+
export const computedDateTimeSplit = function(property, segmentFormat, endProperty) {
48+
console.log(property);
4749
return computed(property, {
4850
get() {
49-
// if (property === 'endsAt' && segmentFormat === 'date') {
50-
// return moment(this.get(property)).add(1, 'days').format(getFormat(segmentFormat));
51-
// } The following line was adding one extra day to the endsAt Attribute . Commenting it to fix the issue .
5251
return moment(this.get(property)).format(getFormat(segmentFormat));
5352
},
5453
set(key, value) {
54+
console.log(key, value, this);
5555
const newDate = moment(value, getFormat(segmentFormat));
56-
let oldDate = moment(this.get(property));
56+
let oldDate = newDate;
57+
if (this.get(property)) {
58+
oldDate = moment(this.get(property), segmentFormat === 'date' ? FORM_DATE_FORMAT : FORM_TIME_FORMAT);
59+
} else {
60+
oldDate = newDate;
61+
}
5762
if (segmentFormat === 'time') {
5863
oldDate.hour(newDate.hour());
5964
oldDate.minute(newDate.minute());
@@ -65,7 +70,11 @@ export const computedDateTimeSplit = function(property, segmentFormat) {
6570
oldDate = newDate;
6671
}
6772
this.set(property, oldDate);
68-
this.set('endsAt', oldDate);
73+
if (endProperty) {
74+
if (segmentFormat === 'date' && this.get(endProperty) < oldDate) {
75+
this.set(endProperty, oldDate);
76+
}
77+
}
6978
return value;
7079
}
7180
});

app/utils/dictionary/date-time.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import moment from 'moment';
22

33
export const timezones = moment.tz.names();
44

5-
export const FORM_DATE_FORMAT = 'MM/DD/YYYY';
5+
export const FORM_DATE_FORMAT = 'MM-DD-YYYY';
66
export const FORM_TIME_FORMAT = 'HH:mm';
77

88
export const FORM_DATE_TIME_FORMAT = `${FORM_DATE_FORMAT} ${FORM_TIME_FORMAT}`;

0 commit comments

Comments
 (0)