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.

Is it sunrise or sunset with an offset?
#1
Hi,

If you need to know if the current time is equal to an minute offset ( + or - ) of Sunset or Sunrise  place these scripts in the Common script.   For example, if its 40 minutes before sunrise,  you would create a resident script to run every minute.  


Code:
123
if( isSunrise(-40, 51.5072, 0.1275) == true) then   doSomething() end


example 2,  if its 30 minutes after then you would use

Code:
123
if( isSunset(30, 51.5072, 0.1275) == true) then   doSomething() end


And when you need to know if its Sunset or Sunrise then set the offset parameter to 0.



Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445
function isSunset(offset, latitude, longitude)   local sunrise, sunset = rscalc(latitude, longitude)   local now = os.date("*t")   local yr =now.year   local mth = now.month   local dy = now.day   local hr = math.floor(sunset / 60)   local minute = sunset % 60   local tm = os.time{year=yr, month=mth, day=dy, hour=hr, min=minute, sec=0}   local offsettm   if(offset >=1) then     offsettm= tm+(offset*60)   else     offsettm= tm-((offset*-1)*60)   end   local now = os.time()   if(offsettm>=(now-30) and offsettm<=(now+30))then     return true   else     return false   end end function isSunrise(offset, latitude, longitude)   local sunrise, sunset = rscalc(latitude, longitude)   local now = os.date("*t")   local yr =now.year   local mth = now.month   local dy = now.day   local hr = math.floor(sunrise / 60)   local minute = sunrise % 60   local tm = os.time{year=yr, month=mth, day=dy, hour=hr, min=minute, sec=0}   local offsettm   if(offset >=1) then     offsettm= tm+(offset*60)   else     offsettm= tm-((offset*-1)*60)   end   local now = os.time()   if(offsettm>=(now-30) and offsettm<=(now+30))then     return true   else     return false   end end



Hope this may help.

Thanks,


Roger
Reply


Messages In This Thread
Is it sunrise or sunset with an offset? - by rocfusion - 02.07.2015, 09:33

Forum Jump: