Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] Dete Picker bug caused by API of setMonth () #6129

Closed
yuyeqianxun opened this issue Jul 29, 2019 · 2 comments
Closed

[Bug Report] Dete Picker bug caused by API of setMonth () #6129

yuyeqianxun opened this issue Jul 29, 2019 · 2 comments

Comments

@yuyeqianxun
Copy link

Environment

windows10/chrome/2.6.10

Reproduction link

https://run.iviewui.com/9jlYhY9H

Steps to reproduce

切换到2~3月份

What is expected?

期望左侧2月份,右侧3月份

What is actually happening?

左侧3月份,右侧3月份


关于以上代码使用,当切换到3月份时会出现bug,最终发现可能是js本身的setMonth导致的问题,我试了几个浏览器,都有这样的问题。
继而我查看了MDN,也未见提及setMonth有什么特殊,目前不确定是我理解不正确还是该API本来就这样,但组件是由于这个API出现了实实在在的问题。

api出错?

let current = new Date()
current.setMonth(2)
console.log(current)//这里正确的设置成了3月份
current.setMonth(1)
console.log(current)//这里错误的设置成了3月份,预期应该是2月份,导致组件出错

问题修复

//date-range:299
panel === 'left'
?current[`set${type}`](current[`get${type}`](),0)
:current[`set${type}`](current[`get${type}`]() increment);
@iview-bot
Copy link
Collaborator

Translation of this issue:

Environment

Windows 10/chrome/2.6.10

Reproduction link

set $](current [get $ increment)

Steps to reproduce

Switch to February-March

What is expected?

Expect February on the left and March on the right.

What is actually happening?

March on the left and March on the right

As for the use of the above code, when switching to March, there will be a bug, and eventually found that the problem may be caused by the setMonth of JS itself. I have tried several browsers, all of which have such problems.
Then I looked at the MDN, and I didn't mention setMonth's specificity. I'm not sure if I understand it correctly or if the API was like this, but the component was due to a real problem with the API.

API error?

Let current = new Date ()
Current. setMonth (2)
Console. log (current)// Here is the correct setting for March
Current. setMonth (1)
Console. log (current)// / The wrong setting here was March, which is expected to be February, causing component errors
` ` ` `
# Problem Repair
` ` ` `
// date-range: 299
Panel ==='left'
Current [`set $](current [`get $]() increment)
Current [`set $](current [`get $]() increment);
` ` ` `

@iview-bot iview-bot changed the title [Bug Report]关于setMonth()的API引发的DatePicker出现bug [Bug Report] Dete Picker bug caused by API of setMonth () Jul 29, 2019
@msidolphin msidolphin mentioned this issue Jul 29, 2019
@yuyeqianxun
Copy link
Author

目前已知并非是api的bug,是由于setMonth在空缺日参数只接受月参数的时候,会自动沿用当前时间的日参数,今天是29号,setMonth(1)=>setMonth(1,29)=>2月29=>3月1,从而导致了日期组件的出错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants