From 7f77626c48b64887c946e2ddfd7bcc2a6bab50c6 Mon Sep 17 00:00:00 2001 From: ollo Date: Tue, 12 Apr 2016 19:42:35 +0200 Subject: [PATCH] Extracted time convertion into seperate file --- test.lua | 67 +--------------------------------------------------- timecore.lua | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 66 deletions(-) create mode 100644 timecore.lua diff --git a/test.lua b/test.lua index d6c8f8e..8250213 100644 --- a/test.lua +++ b/test.lua @@ -1,72 +1,7 @@ dofile("wlancfg.lua") +dofile("timecore.lua") print("Initialize Wordclock") --- As we are located in central europe, we have GMT+1 -local TIMEZONE_OFFSET_WINTER = 1 - ---Summer winter time convertion ---See: https://arduinodiy.wordpress.com/2015/10/13/the-arduino-and-daylight-saving-time/ --- ---As October has 31 days, we know that the last Sunday will always fall from the 25th to the 31st ---So our check at the end of daylight saving will be as follows: ---if (dow == 7 && mo == 10 && d >= 25 && d <=31 && h == 3 && DST==1) ---{ ---setclockto 2 am; ---DST=0; ---} --- ---To start summertime/daylightsaving time on the last Sunday in March is mutatis mutandis the same: ---if (dow == 7 && mo == 3 && d >= 25 && d <=31 && h ==2 && DST==0) ---{ ---setclockto 3 am; ---DST=1; ---} -function getLocalTime(year, month, day, hour, minutes, seconds,dow) - -- Always adapte the timezoneoffset: - hour = hour + (TIMEZONE_OFFSET_WINTER) - - -- we are in 100% in the summer time - if (month > 3 and month < 10) then - hour = hour + 1 - -- October is not 100% Summer time - --FIXME elseif (month == 10 and - end - - return year, month, day, hour, minutes, seconds -end - --- Convert a given month in english abr. to number from 1 to 12. --- On unknown arguments, zero is returned. -function convertMonth(str) - if (str=="Jan") then - return 1 - elseif (str == "Feb") then - return 2 - elseif (str == "Mar") then - return 3 - elseif (str == "Apr") then - return 4 - elseif (str == "May") then - return 5 - elseif (str == "Jun") then - return 6 - elseif (str == "Jul") then - return 7 - elseif (str == "Aug") then - return 8 - elseif (str == "Sep") then - return 9 - elseif (str == "Oct") then - return 10 - elseif (str == "Nov") then - return 11 - elseif (str == "Dec") then - return 12 - else - return 0 - end -end - function startTimeupdate() -- Found: http://thearduinoguy.org/using-an-esp8266-as-a-time-source-part-2/ -- retrieve the current time from Google diff --git a/timecore.lua b/timecore.lua new file mode 100644 index 0000000..f3124d3 --- /dev/null +++ b/timecore.lua @@ -0,0 +1,65 @@ +-- As we are located in central europe, we have GMT+1 +local TIMEZONE_OFFSET_WINTER = 1 + +--Summer winter time convertion +--See: https://arduinodiy.wordpress.com/2015/10/13/the-arduino-and-daylight-saving-time/ +-- +--As October has 31 days, we know that the last Sunday will always fall from the 25th to the 31st +--So our check at the end of daylight saving will be as follows: +--if (dow == 7 && mo == 10 && d >= 25 && d <=31 && h == 3 && DST==1) +--{ +--setclockto 2 am; +--DST=0; +--} +-- +--To start summertime/daylightsaving time on the last Sunday in March is mutatis mutandis the same: +--if (dow == 7 && mo == 3 && d >= 25 && d <=31 && h ==2 && DST==0) +--{ +--setclockto 3 am; +--DST=1; +--} +function getLocalTime(year, month, day, hour, minutes, seconds,dow) + -- Always adapte the timezoneoffset: + hour = hour + (TIMEZONE_OFFSET_WINTER) + + -- we are in 100% in the summer time + if (month > 3 and month < 10) then + hour = hour + 1 + -- October is not 100% Summer time + --FIXME elseif (month == 10 and + end + + return year, month, day, hour, minutes, seconds +end + +-- Convert a given month in english abr. to number from 1 to 12. +-- On unknown arguments, zero is returned. +function convertMonth(str) + if (str=="Jan") then + return 1 + elseif (str == "Feb") then + return 2 + elseif (str == "Mar") then + return 3 + elseif (str == "Apr") then + return 4 + elseif (str == "May") then + return 5 + elseif (str == "Jun") then + return 6 + elseif (str == "Jul") then + return 7 + elseif (str == "Aug") then + return 8 + elseif (str == "Sep") then + return 9 + elseif (str == "Oct") then + return 10 + elseif (str == "Nov") then + return 11 + elseif (str == "Dec") then + return 12 + else + return 0 + end +end \ No newline at end of file