element icon indicating copy to clipboard operation
element copied to clipboard

[Bug Report] el-date-picker[type=week]: `value-format` invalidation of `format`

Open bowencool opened this issue 7 years ago • 18 comments

Element UI version

2.0.7

OS/Browsers version

windows10 chrome63.0.3239.84(正式版本) (64 位)

Vue version

2.5.2

Reproduction Link

https://jsfiddle.net/bowencool/ndkdwyka/1/

Steps to reproduce

见链接

What is Expected?

正常展示就行

What is actually happening?

不能正常展示数据

bowencool avatar Dec 12 '17 07:12 bowencool

Translation of this issue:

Element UI version

2.0.7

OS/Browsers version

Windows10 chrome63.0.3239.84 (official version) (64 bit)

Vue version

2.5.2

Reproduction Link

https://jsfiddle.net/bowencool/ndkdwyka/1/

Steps to reproduce

See links

What is Expected?

Normal display is all right

What is actually happening?

No normal display of data

element-bot avatar Dec 12 '17 07:12 element-bot

@wacky6 Hi, could you take a look at this? Thanks.

Leopoldthecoder avatar Dec 12 '17 11:12 Leopoldthecoder

Fecha does not support parsing / formatting of week. I guess element need to hack it somehow? Modify week's parser might solve the problem.

I might consider removing week in value-format, since it can not accurately indicate a time point (depends on the interpretation of start-of-week, etc).

wacky6 avatar Dec 12 '17 13:12 wacky6

I might consider removing week in value-format, since it can not accurately indicate a time point (depends on the interpretation of start-of-week, etc).

IMHO it is a valid value format. You are using ISO8601 week numbers and they are always starting with Monday.

https://github.com/ElemeFE/element/blob/af46f968ab8f56ddb87932eab35993782c4d5b2f/packages/date-picker/src/util/index.js#L97-L107


Anyways, the error (vue.js:1719 TypeError: e.getTime is not a function) also happens when you do not use WW in the value-format. E.g. in this fiddle I changed the value-format to yyyy-MM-dd and the error happens, too.

If you have a el-date-picker[type=week] and also set the value-format this error occurs. Looks like el-date-picker[type=week] cannot handle anything besides a JavaScript Date object as value.

This line https://github.com/ElemeFE/element/blob/aaf7a87848d33d3f07310f2865e4d3d14019c6f0/packages/date-picker/src/picker.vue#L167 should probably be

      let week = getWeekNumber(isDateObject(value) ? value : parseDate(value, format));

d--j avatar Jan 23 '18 15:01 d--j

Interesting.

Can you make a PR for it? I recommend integrate week format into our custom fecha (/src/utils/date.js)? So date-picker can treat week number as normal dates. (Thus removing custom week picker logic)

wacky6 avatar Jan 23 '18 17:01 wacky6

@Leopoldthecoder What's the reasoning of current implementation? Will this be a breaking change?

Make fecha support WW/W format, so element can drop custom week picker logic, see TYPE_VALUE_RESOLVER_MAP's week

wacky6 avatar Jan 23 '18 17:01 wacky6

Any updates on this issue ?

joachimVT avatar Mar 07 '18 12:03 joachimVT

when i set {type="week",value-format="yyyy-W"} ,will meet the same bug! " Error in render: "TypeError: src.getTime is not a function"" please help

bill-mark avatar Mar 27 '18 06:03 bill-mark

Right now, W is not supported in value-format. Use MM/dd instead. The definition of W / WW format needs consensus. ISO-8601 week date may be considered in the future.

wacky6 avatar Mar 29 '18 03:03 wacky6

呜呜呜,终于知道为什么了,花了我半天时间,这磨人的week

xch1029 avatar May 22 '18 08:05 xch1029

why this issue not solved after one year??

kenziD avatar Sep 29 '18 08:09 kenziD

el-date-picker 像下面这样设置时,输入框的格式一直不正确

<el-date-picker
v-model="value1"
      type="week"
      format="yyyy 第 W 周"
      value-format="yyyy-W"
      placeholder="选择周">
</el-date-picker>

预览链接

dengpan0513 avatar May 30 '19 06:05 dengpan0513

same problem here

JasonBoy avatar Mar 23 '20 03:03 JasonBoy

Hi, can someone add this feature? image value-format still not support WW...

marissagroves avatar May 25 '20 08:05 marissagroves

I use the computed attribute to parse week. But it's not very convinient. computed: { week() { return moment(this.date.W).format('YYYY [wk]WW'); } }

marissagroves avatar May 25 '20 08:05 marissagroves

Still no update? :(

joshmacaraig avatar Oct 06 '20 16:10 joshmacaraig

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 18 '22 08:04 stale[bot]

Still no update? :(

ginkosen avatar Jan 10 '24 09:01 ginkosen