Jump to content

How to Count Days to The Third Wed of The Month


apostolakisl

Recommended Posts

Posted

I was asked if there was a way to have the ISY know that it was the third Wed of the month and if it could keep track of how many days away the next third Wed was. The first part was easy using the day/month/year etc programs I had written but the second part stressed my brain a little bit. I came up with a solution and thought you might like to see it (and hopefully not find any errors). I am not sure that many people will have a direct need for this, but the logic may apply to other applications. It consists of three programs, two of which are very simple and the third is a bit more complex. The concept is that it is always going to be either 4 or 5 weeks between 3rd wed of the month depending on how long of a month you are currently in and when in that month the wed falls. I wrote the program to look at what month you were in (and thus how long it is, remembering leap year), and look at what day of the month your 3rd wed is falling on, and then reset the counter to either 34 or 27 on the day after the third wed.

 

31 30 29 day month days to third wed

If
       (
            (
                 $iMonth is 1
              Or $iMonth is 3
              Or $iMonth is 5
              Or $iMonth is 7
              Or $iMonth is 8
              Or $iMonth is 10
              Or $iMonth is 12
            )
        And $iDay.of.Month <= 18
       )
    Or (
            (
                 $iMonth is 4
              Or $iMonth is 6
              Or $iMonth is 9
              Or $iMonth is 11
            )
        And $iDay.of.Month <= 17
       )
    Or (
            $iMonth is 2
        And $iLeap.Year is 0
        And $iDay.of.Month <= 16
       )

Then
       $iDays.To.Third.Wed  = 34
       $iDays.To.Third.Wed Init To 34

Else
       $iDays.To.Third.Wed  = 27
       $iDays.To.Third.Wed Init To 27


 

Days to Third Wed Countdown

If
       Time is 12:00:10AM

Then
       $iDays.To.Third.Wed -= 1
       $iDays.To.Third.Wed Init To $iDays.To.Third.Wed
       Run Program 'Test for -1' (If)

Else
  - No Actions - (To add one, press 'Action')


 

 

Test for -1

If
       $iDays.To.Third.Wed is -1

Then
       Run Program '31 30 29 day month days to 3rd wed' (If)

Else
  - No Actions - (To add one, press 'Action')


 

You'll notice there is no provision for 28 day Feb's since they will always be 28 days apart and will just automatically fall to the "else" clause.

 

Let me know what you think.

Posted

Thank you for posting this, it will be very helpful to me and others.

 

This and the others are of great work.

 

Thanks again !

Guest
This topic is now closed to further replies.

×
×
  • Create New...