fix(time): infinite loop for ticks of Berlin time #208
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
修复时区带来的死循环
上面的 issue 经过简单排查是 time scale 计算 ticks 算法造成死循环。
存在问题
出现的问题第一眼看很难理解:
date.setTime(date + DURATION_WEEK)
和date.setDate(date.getDate() + 7)
的结果不一样!在原本代码中是使用的第一种:该表达式并没有增加一周的时间,少了一个小时,这也导致了死循环。问题原因
这问题只对特定的时间和时区有关,于是问了问 GPT 老师,发现欧洲会在10月在最后的一个周日左右会把时间调快一个小时,所以通过时间戳计算会比实际时间少一个小时。
解决办法
用
date.setDate(date.getDate() + 7)
计算偏移时间。