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

fix(Calendar): fix timezone #4742

Merged
merged 2 commits into from
Jan 12, 2022

Conversation

shenjingnan
Copy link
Collaborator

@@ -6,7 +6,6 @@ function getMonths(minDate, maxDate) {
var cursor = getDate(minDate);

cursor.setDate(1);
cursor.setMinutes(cursor.getMinutes() - cursor.getTimezoneOffset());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这行代码在逻辑上是无用的嘛?

Copy link
Collaborator Author

@shenjingnan shenjingnan Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原先这句是为了处理单测github action的timezone和中国时区不对导致不通过的问题,但是发现会导致 #4718 这样的问题。

2022-1-1实际是 周六 ,但是由于这里 cursor.getTimezoneOffset() 在中国区是 -480,实际变成了 cursor.setMinutes(cursor.getMinutes() + 480); 导致增加了8小时到了 周日

单测的时区问题,更合理的做法应该是通过 Set Timezone Action 设置正确的时区

所以这个错误的写法应该是要被修正的

Copy link
Collaborator Author

@shenjingnan shenjingnan Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关于时区导致 Calendar 单测不通过的问题

原因是因为在 <month /> 上设置了 data-date 属性,这个属性是一个具体的时间戳
本地 yarn test 的时候是基于中国区的时间,而跑 Github Action 的时候应该是基于国外的时区,这导致每次这个具体的时间戳都会对不上
所以只能在跑 Github Action 的时候锁定中国区
这样设置后,国外开发者PR可能会遇到时区问题,但是vant-weapp应该极少有国外开发者PR
其实理论上来说任何时区都应该是正常的才对,但是小程序只能通过 data-date 这样的方式传值,就有点无解

还有用来测试的PR 这个分支我尝试了把 <month /> 写死也会出现禁用日期和快照不一致的情况(大致就是国外时间和国内不一样,所以disabled的日期也会不一样)

关于vant单测

vant的单测没有设置时区,但是单测还是能跑过。看了下快照上没有出现像 data-date这样写死一个时间戳的情况

@chenjiahan chenjiahan merged commit 9919e8b into youzan:dev Jan 12, 2022
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

Successfully merging this pull request may close these issues.

2 participants