Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Timerfunction


Question

Posted (edited)

hello,

does annyone now how to make a month timerfunction

 

this one ia a function for a day

setTimeout(timerFunction, 24*60*60*1000)

 

but the months are different evrytime like 30 31 28 (leapyear 29)

 

thanks

 

also is there a way to make a local for the next month

i know how to change for example 30 min later

os.date("%H;%M, os.time()+30*60)

for month it is

os.date("%B")

but how for next month

 

thanks again

Edited by Kage

2 answers to this question

Recommended Posts

  • 0
Posted

The topic has been moved from "

Please login or register to see this link.

" to "

Please login or register to see this link.

".

 

Temat został przeniesiony z "

Please login or register to see this link.

" do "

Please login or register to see this link.

".

  • 0
Guest FredrikKarlsson
Posted

Ok, programming with dates and times are best left to the build in functions, I think. 

 

Have a look at the Lua documentation for os.date and os.time.

Please login or register to see this link.

os.time extract time information, possibly for manipulation, and os.date formats it to a new time specification.

 

Ok, so one quick solution to your problem is to do this:

 

Please login or register to see this code.

Please note the trick here:

 

Please login or register to see this code.

You convert the month to a number, add one to thet number, and then apply a modulo 12 on that number.

This is a common trick in programming that handles the case of december (month 12). If you add 1 to that, you get 13, but if you performa an integer (whole number) division with 12 on that number and keep only what remains, which is what the modulo action in maths does, then you get 1 back. Which is the month that follows 12.

 

Hope this helps. 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...