2017-01-18 71 views
1

我一直在做使用Calendar一切日期时间的转换是为过去4个月工作正常,但所有的突然我开始在这一些奇怪的行为, 什么我做的是%Calendar.AmbiguousDateTime {possible_date_times日历药剂

1..total_days |> Enum.reduce(start_date, fn _i, acc -> 
    day_of_week = acc |> Calendar.Date.day_of_week_name 
    rec_head = get_head_tail(schedule[day_of_week]) 
    rec_head |> Enum.each(fn(x) -> 
    iterate(x, acc, timezone) |> t_download(interval, t_agent) 
    end) 
    acc |> Calendar.DateTime.to_erl |> IO.inspect |> Calendar.DateTime.from_erl!(timezone, {123456, 6}) |> IO.inspect |> Calendar.DateTime.add!(86400) 
end) 

而且

acc |> Calendar.DateTime.to_erl |> IO.inspect |> Calendar.DateTime.from_erl!(timezone, {123456, 6}) |> IO.inspect |> Calendar.DateTime.add!(86400) 

给输出

{{2016, 10, 27}, {1, 0, 0}} 
%Calendar.DateTime{abbr: "IST", day: 27, hour: 1, min: 0, month: 10, sec: 0, 
std_off: 3600, timezone: "Europe/Dublin", usec: {123456, 6}, utc_off: 0, 
year: 2016} 
{{2016, 10, 28}, {1, 0, 0}} 
%Calendar.DateTime{abbr: "IST", day: 28, hour: 1, min: 0, month: 10, sec: 0, 
std_off: 3600, timezone: "Europe/Dublin", usec: {123456, 6}, utc_off: 0, 
year: 2016} 
{{2016, 10, 29}, {1, 0, 0}} 
%Calendar.DateTime{abbr: "IST", day: 29, hour: 1, min: 0, month: 10, sec: 0, 
std_off: 3600, timezone: "Europe/Dublin", usec: {123456, 6}, utc_off: 0, 
year: 2016} 
{{2016, 10, 30}, {1, 0, 0}} 

但在最后的日期和时间,而不是给我的,因为它是上面给出正确的输出,这是给这个

{:ambiguous, %Calendar.AmbiguousDateTime{possible_date_times: [%Calendar.DateTime{abbr: "GMT", day: 30, hour: 1, min: 0, month: 10, sec: 0, std_off: 0, timezone: "Europe/Dublin", usec: {123456, 6}, utc_off: 0, year: 2016}, %Calendar.DateTime{abbr: "IST", day: 30, hour: 1, min: 0, month: 10, sec: 0, std_off: 3600, timezone: "Europe/Dublin", usec: {123456, 6}, utc_off: 0, year: 2016}]}} 

我完全不知道的这个原因,因为这是工作正常,但所有的突发其给我这些错误。任何帮助?

更新:正在使用https://github.com/lau/calendar日历。

+0

我假设你正在使用[lau/calendar](https://github.com/lau/calendar),可能值得在问题中指出。 – nietaki

+1

谢谢你这样做.. – ijunaidfarooq

+0

@nietaki Btw刚刚看到你是来自MainFrame,我的X同事同事也在Mainframe,Milos Mosic .. – ijunaidfarooq

回答

0

根据the docs,发生这种情况时,提供所输入的时间是不明确的:

AmbiguousDateTime提供表示一个模糊时间 和日期在特定时区中的结构体。当提供的时间不明确时,这些结构将从DateTime.from_erl/2函数中返回 。

AmbiguousDateTime包含两个DateTime结构。例如,他们可以 表示DST和非DST时间。 如果从夏天到冬天的时间从2:00开始,时钟将返回 小时,则1:00到2:00之间的“墙壁 ”时间会发生两次。其中之一是在DST和 其中之一不是。

这似乎是你的情况。时间输出为上午1点Europe/Dublin时间,上午1点在2016年10月30日发生两次:第二次是凌晨2点,当夏令时结束时,您将时钟调回。

看起来你可以使用disamb/2函数来消除你得到的结果。

+0

但是为什么它开始时发生在过去5个月工作正常 – ijunaidfarooq

+0

而哪个zone_abbr我应该选择? IST还是GMT?如果是这种情况,那么我可以从列表中选择一个值,这会有什么区别? – ijunaidfarooq

+0

我不知道你的代码运行在哪个日期范围内,我的猜测是,它从来没有碰到过这种边缘情况 - 每年只发生一个小时。 – nietaki