Skip to content

Commit

Permalink
DatePicker: fix format week, fixed ElemeFE#2774 (ElemeFE#3687)
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li authored and baiyaaaaa committed Mar 24, 2017
1 parent 0409c63 commit 43bb065
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
10 changes: 2 additions & 8 deletions packages/date-picker/src/panel/date.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,8 @@
this.date.setMonth(value.getMonth());
this.date.setDate(value.getDate());
} else if (this.selectionMode === 'week') {
let date = formatDate(value.date, this.format || 'yyyywWW');
const week = this.week = value.week;
date = /WW/.test(date)
? date.replace(/WW/, week < 10 ? '0' + week : week)
: date.replace(/W/, week);
this.$emit('pick', date);
this.week = value.week;
this.$emit('pick', value.date);
}
this.resetDate();
Expand Down
15 changes: 9 additions & 6 deletions packages/date-picker/src/picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const DEFAULT_FORMATS = {
month: 'yyyy-MM',
datetime: 'yyyy-MM-dd HH:mm:ss',
time: 'HH:mm:ss',
week: 'yyyywWW',
timerange: 'HH:mm:ss',
daterange: 'yyyy-MM-dd',
datetimerange: 'yyyy-MM-dd HH:mm:ss',
Expand Down Expand Up @@ -105,12 +106,14 @@ const TYPE_VALUE_RESOLVER_MAP = {
}
},
week: {
formatter(value) {
if (value instanceof Date) {
const weekNumber = getWeekNumber(value);
return value.getFullYear() + 'w' + (weekNumber > 9 ? weekNumber : '0' + weekNumber);
}
return value;
formatter(value, format) {
let date = formatDate(value, format);
const week = getWeekNumber(value);
date = /WW/.test(date)
? date.replace(/WW/, week < 10 ? '0' + week : week)
: date.replace(/W/, week);
return date;
},
parser(text) {
const array = (text || '').split('w');
Expand Down

0 comments on commit 43bb065

Please sign in to comment.