I have created an entry in my Sitemap to enter a date and time. There are four Number Selections: Month, Day, Hour, Minute.
Is there a way to make the Selection list for Day of the month to be dependent on the month selected? For example, If I choose June, the days that can be selected are 1-30, July: 1-31, February: (non-leap year) 1-28, February: (leap year) 1-29?
Thanks for this. Truly! I have taken your idea and converted it to my specifics where I’m using Selections rather than Setpoints. All pretty much working like a charm. I have each “type” of month working with limits to the Selection days of the month… except I’m trying to implement February with a check for leap year so I can set 28 or 29 days.
I’m trying to have the 'puter tell me the last day in February using something like this:
(I know that syntax and data typing is all wrong… because it’s erroring out). I’ve read @rlkoshak Rich Koshak’s Time of Day Design Pattern and a ton of other posts regarding date and time manipulation… but I’m no less baffled.
Conceptually, I want to have the system generate a value for March 1 of the desired year (e.g., current) right at midnight and go back one millisecond to yesterday (i.e., last day of February). Then I’ll parse that DateTime value to grab the day of month element… and use that to set the Days of Month list visibility flag.
I’m probably overthinking this and there’s probably a much more straightforward way to get the last day of the month of February for a given year. As I said in a separate track, I’m not proud. I’ll take code donations… especially after spending three hours trying to make that simple concept work!
val int lastDayOfFeb = new DateTime(now.getYear, 3, 1, 0, 0, 0, 0).minusMinutes(1).getDayOfMonth
So we create a new DateTime for the the current Year, March 1 at midnight, subtract a minute (it doesn’t matter how much we subtractso long as it’s no more than a day, then get the day of the month from that.
Unfortunately, this does not work any more for OH3.
It throws the error
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'home-79' failed: An error occurred during the script execution: null in home
To be honest, I found out that my Ephemeris solution did not work.
Now I simply always use 28 days for Feb - it is only used for solar inverter revenue calculation here.
Sorry to not be able to help further…