Skip to content

Commit

Permalink
fix: resolve setAllDayPeriod logic(fix nhn#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
jungeun-cho committed Sep 22, 2020
1 parent 44ebf62 commit 5a524e2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function setConfig(defaultConfig, server) {
'IE9',
'IE10',
'IE11',
'Edge',
// 'Edge',
'Chrome-WebDriver',
'Firefox-WebDriver'
// 'Safari-WebDriver'
Expand Down
6 changes: 4 additions & 2 deletions src/js/common/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,15 @@ datetime = {
hasMultiDates: function(start, end) {
var diffDays = datetime.getDateDifference(start, end);
var diffHours = Math.abs(datetime.getHourDifference(start, end));
var withinDay = diffDays === -1 && diffHours < 24 && datetime.isStartOfDay(end);
var withinDay = Math.abs(diffDays) === 1 && diffHours < 24 && datetime.isStartOfDay(end);

return !datetime.isSameDate(start, end) && !withinDay;
},

renderEnd: function(start, end) {
return datetime.hasMultiDates(start, end) && datetime.isStartOfDay(end) ?
var diffDays = datetime.getDateDifference(start, end);

return Math.abs(diffDays) >= 1 && datetime.isStartOfDay(end) ?
datetime.convertStartDayToLastDay(end) :
datetime.end(end);
}
Expand Down
18 changes: 16 additions & 2 deletions src/js/model/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,22 @@ Schedule.prototype.init = function(options) {
};

Schedule.prototype.setAllDayPeriod = function(start, end) {
this.start = datetime.start(new TZDate(start || Date.now()));
this.end = datetime.end(new TZDate(end || this.start));
// If it is an all-day schedule, only the date information of the string is used.
if (util.isString(start) && start.length === 10) {
start = datetime.parse(start);
} else {
start = new TZDate(start || Date.now());
}

if (util.isString(end) && end.length === 10) {
end = datetime.parse(end);
end.setHours(23, 59, 59);
} else {
end = new TZDate(end || start);
}

this.start = datetime.start(start);
this.end = datetime.renderEnd(start, end);
};

Schedule.prototype.setTimePeriod = function(start, end) {
Expand Down
6 changes: 3 additions & 3 deletions test/app/view/weekdayInMonth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ describe('view:WeekdayInMonth', function() {
var viewModel = ScheduleViewModel.create(Schedule.create({
title: 'A',
isAllDay: true,
start: '2015-05-01T00:00:00',
end: '2015-05-03T23:59:59'
start: '2015-05-01T00:00:00+09:00',
end: '2015-05-03T23:59:59+09:00'
})),
eventsInDateRange = [[[viewModel]]],
ranges = [new TZDate('2015-05-01T00:00:00'), new TZDate('2015-05-02T00:00:00'), new TZDate('2015-05-03T00:00:00')],
ranges = [new TZDate('2015-05-01T00:00:00+09:00'), new TZDate('2015-05-02T00:00:00+09:00'), new TZDate('2015-05-03T00:00:00+09:00')],
cache = WeekdayInMonth.prototype.getExceedDate(0, eventsInDateRange, ranges);

expect(cache).toEqual({
Expand Down

0 comments on commit 5a524e2

Please sign in to comment.