Skip to content

Commit 5f181c3

Browse files
suyi91wacky6
authored andcommitted
date-picker: fix week highlight on year boundary (#13883)
When the selected week spans across two years (e.g. 2018-12-30 2019-01-05), they should be highlighted in both month tables.
1 parent 9579d00 commit 5f181c3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/date-picker/src/basic/date-table.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</template>
3333

3434
<script>
35-
import { getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, nextDate, isDate, clearTime as _clearTime} from '../util';
35+
import { getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, prevDate, nextDate, isDate, clearTime as _clearTime} from '../util';
3636
import Locale from 'element-ui/src/mixins/locale';
3737
import { arrayFindIndex, arrayFind, coerceTruthyValueToArray } from 'element-ui/src/utils/util';
3838
@@ -321,8 +321,12 @@
321321
322322
newDate.setDate(parseInt(cell.text, 10));
323323
324-
const valueYear = isDate(this.value) ? this.value.getFullYear() : null;
325-
return year === valueYear && getWeekNumber(newDate) === getWeekNumber(this.value);
324+
if (isDate(this.value)) {
325+
const dayOffset = (this.value.getDay() - this.firstDayOfWeek + 7) % 7 - 1;
326+
const weekDate = prevDate(this.value, dayOffset);
327+
return weekDate.getTime() === newDate.getTime();
328+
}
329+
return false;
326330
},
327331
328332
markRange(minDate, maxDate) {

0 commit comments

Comments
 (0)