set individual values of the RtcDateTime object #181
-
Is it possible to set individual values in the RtcDateTime object. As far as I understand this library it is possible to increment or decrement the amount of seconds but is it possible to increment or decrement the month or days value directly? Adding a fixed value of seconds to the object wouldn't increment the months reliably due to the different lengths during the year. And the _month value of the Object is protected |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Nope, this is on purpose. Its an optimization. Just construct a temp. When the compiler knows its members are not directly accessible it can do some optimizations. Further, there are details for incrementing that can cause invalid dates if you use daylight shifting (which I do not recommend except where you display or take input). But adding seconds will never do this. Take this example which does compile successfully and works for most cases, as it assumes you want the last day of the next month if the day is beyond a valid day of the month.
|
Beta Was this translation helpful? Give feedback.
-
I am not looking for a alarm function but thanks for the heads up. So the easiest method is use a placeholder for year, months. For days, minutes and seconds I can just add seconds via the mathematical operator and the object handles the rest for me right? |
Beta Was this translation helpful? Give feedback.
Nope, this is on purpose. Its an optimization. Just construct a temp. When the compiler knows its members are not directly accessible it can do some optimizations. Further, there are details for incrementing that can cause invalid dates if you use daylight shifting (which I do not recommend except where you display or take input). But adding seconds will never do this.
Take this example which does compile successfully and works for most cases, as it assumes you want the last day of the next month if the day is beyond a valid day of the month.
NOTE: DaysInMonth is coming shortly to wrap the access to progmem c_daysInMonth for easier readability