We have moved at community.getvera.com

Author Topic: lua code for get the seasons  (Read 1611 times)

Offline B3rt

  • Full Member
  • ***
  • Posts: 232
  • Karma: +2/-8
lua code for get the seasons
« on: April 19, 2015, 09:57:07 am »
Is there a simple lua code i could use to deterime which seaon it is?
So if it is winter, spring, summer or autum (at my location)?

I want to use the season to set some lighting and temp control....

How can i do this simply?

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: lua code for get the seasons
« Reply #1 on: April 19, 2015, 10:23:44 am »

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7

Offline B3rt

  • Full Member
  • ***
  • Posts: 232
  • Karma: +2/-8
Re: lua code for get the seasons
« Reply #3 on: April 19, 2015, 10:28:43 am »
thx but not really, i still have to make rules to determine which season it is...

I meant more like a app or code like: isSummer() isWinter() isAutum() isSpring() which return me a true or false
Or a code like WhichSeason() which returns the actual season 'spring'...
 


Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-13
Re: lua code for get the seasons
« Reply #4 on: April 19, 2015, 11:57:57 am »
Code: [Select]
function WhichSeason()
     local tNow = os.date("*t")
     local dayofyear = tNow.yday
     local season
     if (dayofyear >= 79) and (dayofyear < 172) then season = "Spring"
     elseif (dayofyear >= 172) and (dayofyear < 266) then season = "Summer"
     elseif (dayofyear >= 266) and (dayofyear < 355) then season = "Autumn"
     else season = "Winter"
     end
     return season
end

Note: This assumes that you are in the Northern hemisphere!
 
« Last Edit: April 19, 2015, 06:05:33 pm by RexBeckett »

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-13
Re: lua code for get the seasons
« Reply #5 on: April 19, 2015, 12:09:46 pm »
Or:

Code: [Select]
function isSpring()
     local tNow = os.date("*t")
     local dayofyear = tNow.yday
     return (dayofyear >= 79) and (dayofyear < 172)
end

function isSummer()
     local tNow = os.date("*t")
     local dayofyear = tNow.yday
     return (dayofyear >= 172) and (dayofyear < 266)
end

function isAutumn()
     local tNow = os.date("*t")
     local dayofyear = tNow.yday
     return (dayofyear >= 266) and (dayofyear < 355)
end

function isWinter()
     local tNow = os.date("*t")
     local dayofyear = tNow.yday
     return (dayofyear >= 355) or (dayofyear < 79)
end

Note: The dayofyear conditions are only appropriate for the Northern hemisphere.
 
« Last Edit: April 19, 2015, 06:06:24 pm by RexBeckett »