Rtc icon indicating copy to clipboard operation
Rtc copied to clipboard

- add setYear,setMonth,setDay,...

Open uzi18 opened this issue 6 years ago • 6 comments

Ability to chandge date/time in RtcDateTime

uzi18 avatar Jul 24 '17 09:07 uzi18

The original intent was that this structure contains constant values, if you want to set one one, you create one not modify it. This model allows for the compiler to create more optimized code. Why do you need to have these setter methods?

Makuna avatar Jul 24 '17 15:07 Makuna

If You need only to adjust time or date, You can try this: RtcDateTime rtc_now = Rtc.GetDateTime(); rtc_now.setHour(10); rtc_now.setMinute(11); rtc_now.setSecond(12); Rtc.SetDateTime(rtc_now);

Isn't it more optimized, then construct another object with part of old data?

2017-07-24 17:45 GMT+02:00 Michael Miller [email protected]:

The original intent was that this structure contains constant values, if you want to set one one, you create one not modify it. This model allows for the compiler to create more optimized code. Why do you need to have these setter methods?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Makuna/Rtc/pull/38#issuecomment-317464917, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHOUx1VdITEVd1tKTDiDeHO8B8Y-_Fqks5sRLwEgaJpZM4Og8L5 .

uzi18 avatar Jul 24 '17 15:07 uzi18

But what REAL scenario do you have? The example you give isn't a real scenario.
Why would you get the time and then adjust it to a specific date/time?

You might get the time, and compare to another time to see if its out of date (like getting the time from a NTP server); but then you would just use the accurate time to set.

Their are scenarios where you adjust the datetime, but then you usually work only in differences of seconds, and it supports this

rtc_now += 5; // due to some error, I know the rtc_now is five seconds slow, adjust it.

And there are scenarios where timezones adjust the date/time (I always suggest use Zulu date/time in the actual device); but in these cases you should make that adjustment right before you display it ONLY!

Makuna avatar Jul 24 '17 17:07 Makuna

This is real scenario, user send setDate or setTime by Serial and AVR must adjust this like shown before.

I don\t understand why I can add seconds to rtc_now and can't set it directly. can pass unixtime into new object and receive hour,minute or day of week, but cant change only day and check what is a day of week. Someone could use RtcDateTime class alone to calculate unixtime. On other hand gcc will cut out these methods if not used.

I will keep it in my fork, as I need it.

uzi18 avatar Jul 24 '17 18:07 uzi18

NOTE: When constructing an object the compiler can take shortcuts that it can't assume by property setters. This is why this model is used and enforced. Did you try it without your changes and compare the size/memory footprint of the code?

So the Real Scenario is that your Serial API allows setting the time separate from setting the date thus making this an issue for you. Did you have a reason for keeping them separate APIs?

Makuna avatar Jul 24 '17 19:07 Makuna

I'm keeping one RtcDateTime object in memory all the time, to have access to time during runtime.

uzi18 avatar Feb 12 '21 15:02 uzi18

Please say how to set date and time? For example: Apr 25 2023, 00:28:09 How to set this date and time? I have seen examples/DS1302_Simple. It doesn't help.

RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
Rtc.SetDateTime(compiled);

No other example using SetDateTime. But nobody wants to set date and time to __DATE__, __TIME__ in real scenario. Please help.

id1402 avatar Apr 27 '23 19:04 id1402

Apr 25 2023, 00:28:09

It is bad form to ask questions on anything other than the code in a pull request. See Discussion started for you

Makuna avatar Apr 27 '23 20:04 Makuna