This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

How to correctly parse a long series of Timestamps and account for DST
#2
I'll answer my own question... After experimentation, the answer is to just force ISDST to be FALSE for all timestamps in the first function.., which then always matches the content of the JSON feed, because they are only ever provided in UTC... I was mixing up DST and timezone offsets, which are different things...

This works for me now:

Code:
local time_string_before_DST = "2021-03-27T06:00:00Z"
-- DST comes into effect in the hours between these two timestamps..
local time_string_after_DST  = "2021-03-28T06:00:00Z"
 
function conv_to_timestamp(string_to_convert) 
  pattern="(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:(%d+)(%u)"
  -- execute a match
  m_year,m_month,m_day,m_hour,m_min,m_sec,m_zone = string_to_convert:match(pattern) 
  --log(m_day,m_month,m_year,m_hour,m_min,m_sec,m_zone) 
  local calculated_timestamp=(os.time{year=m_year, month=m_month, day=m_day, hour=m_hour, min=m_min , sec=m_sec, isdst=false})  -- add isdst=false here
  return calculated_timestamp
end


local time_stamp_before_DST = conv_to_timestamp(time_string_before_DST)
local time_stamp_after_DST  = conv_to_timestamp(time_string_after_DST)

log("time_stamp_before_DST is: " .. time_stamp_before_DST) -- This outputs 1616824800, which is epoch for 27-03-2021 06:00:00, so is fine
log("time_stamp_after_DST is: " .. time_stamp_after_DST)   -- This outputs 1616911200, which is epoch for 28-03-2021 06:00:00, so is fine
Reply


Messages In This Thread
RE: How to correctly parse a long series of Timestamps and account for DST - by Paddyb - 25.03.2021, 01:54

Forum Jump: