Extracted time convertion into seperate file
This commit is contained in:
parent
57b96b3142
commit
7f77626c48
67
test.lua
67
test.lua
@ -1,72 +1,7 @@
|
|||||||
dofile("wlancfg.lua")
|
dofile("wlancfg.lua")
|
||||||
|
dofile("timecore.lua")
|
||||||
print("Initialize Wordclock")
|
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()
|
function startTimeupdate()
|
||||||
-- Found: http://thearduinoguy.org/using-an-esp8266-as-a-time-source-part-2/
|
-- Found: http://thearduinoguy.org/using-an-esp8266-as-a-time-source-part-2/
|
||||||
-- retrieve the current time from Google
|
-- retrieve the current time from Google
|
||||||
|
65
timecore.lua
Normal file
65
timecore.lua
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user