【问题标题】:Daylight savings time change affecting the outcome of saving and loading an icalendar file?夏令时更改会影响保存和加载 icalendar 文件的结果?
【发布时间】:2008-10-26 17:31:08
【问题描述】:

我有一些单元测试在夏令时切换后开始失败。

我们正在使用iCalendar python module 来加载和保存 ics 文件。

以下脚本是我们测试的简化版本。截至今天早上,该脚本在“夏天”运行良好,但在“冬天”运行失败。可以通过手动设置时钟来重现故障。这是脚本的输出:

[root@ana icalendar]# date 10250855
Sat Oct 25 08:55:00 CEST 2008
[root@ana icalendar]# python dst.py
DTSTART should represent datetime.datetime(2015, 4, 4, 8, 0, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Brussels')) Brussels time
DTSTART should represent datetime.datetime(2015, 4, 4, 6, 0, tzinfo=<icalendar.prop.UTC object at 0x956b5cc>) UTC
DTSTART represents datetime.datetime(2015, 4, 4, 6, 0, tzinfo=<icalendar.prop.UTC object at 0x956b5cc>) Brussels time
[root@ana icalendar]# date 10260855
Sun Oct 26 08:55:00 CET 2008
[root@ana icalendar]# python dst.py
DTSTART should represent datetime.datetime(2015, 4, 4, 8, 0, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Brussels')) Brussels time
DTSTART should represent datetime.datetime(2015, 4, 4, 6, 0, tzinfo=<icalendar.prop.UTC object at 0x96615cc>) UTC
DTSTART represents datetime.datetime(2015, 4, 4, 7, 0, tzinfo=<icalendar.prop.UTC object at 0x96615cc>) Brussels time
Traceback (most recent call last):
  File "dst.py", line 58, in <module>
    start.dt, startUTCExpected)
AssertionError: calendar's datetime.datetime(2015, 4, 4, 7, 0, tzinfo=<icalendar.prop.UTC object at 0x96615cc>) != expected datetime.datetime(2015, 4, 4, 6, 0, tzinfo=<icalendar.prop.UTC object at 0x96615cc>)

这里是whole script

所以,问题: - 为什么我的当前时间(以及我所在的夏令时的哪一部分)会影响时间戳的加载/保存/解析?我希望它不会。 - 如果它是一个错误,你将如何对这种错误进行单元测试?显然,我不希望我的单元测试重置我计算机上的时钟。

【问题讨论】:

  • 近 8 年来我已经看到了单元测试和时区 /TZ+DST 的这种麻烦。我真的很好奇这个问题将得到一个更通用的术语的答案(如何为 DST 更改的可靠单元测试做准备)
  • 整个脚本的链接失效。

标签: python unit-testing icalendar


【解决方案1】:

没有查看您的代码(以及引用的测试运行脚本,我的大脑现在无法理解) 我注意到您尝试获取与您所在的时区不同的时间。 (将 DST 视为另一个时区,而不是当前时区的 +-1 小时)。 这可能(取决于你如何做)导致时间的增加或减少。 (就像您在飞行时一样,您一次开始并在开始之前到达您的位置,所有时间都是当地时间)

【讨论】:

    猜你喜欢
    • 2018-11-02
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    • 2013-06-27
    • 2015-11-24
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多