File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 3
3
4
4
#include < ctime>
5
5
#include " r_rtc_api.h"
6
+ #include < api/String.h>
6
7
7
8
struct timeval {
8
9
time_t tv_sec;
@@ -107,6 +108,12 @@ class RTCTime {
107
108
time_t getUnixTime ();
108
109
struct tm getTmTime ();
109
110
111
+ /* *
112
+ * @brief Returns the ISO 8601 string representation of the date and time.
113
+ *
114
+ * @return String The date and time in the format YYYY-MM-DDTHH:MM:SS.
115
+ */
116
+ arduino::String toString () const ;
110
117
111
118
enum class Period {
112
119
ONCE_EVERY_2_SEC,
Original file line number Diff line number Diff line change @@ -361,6 +361,48 @@ DayOfWeek RTCTime::getDayOfWeek() const { return day_of_week; }
361
361
time_t RTCTime::getUnixTime () { return mktime ( (struct tm *)&stime ); }
362
362
struct tm RTCTime::getTmTime () { return (struct tm )stime; }
363
363
364
+ arduino::String RTCTime::toString () const {
365
+ String formattedTime = " " ;
366
+
367
+ // Year
368
+ formattedTime += String (getYear ());
369
+ formattedTime += " -" ;
370
+
371
+ // Month
372
+ uint8_t month = static_cast <uint8_t >(getMonth ()) + 1 ;
373
+ if (month < 10 )
374
+ formattedTime += ' 0' ;
375
+ formattedTime += String (month);
376
+ formattedTime += " -" ;
377
+
378
+ // Day of month
379
+ if (getDayOfMonth () < 10 )
380
+ formattedTime += ' 0' ;
381
+ formattedTime += String (getDayOfMonth ());
382
+
383
+ // T separator
384
+ formattedTime += " T" ;
385
+
386
+ // Hours
387
+ if (getHour () < 10 )
388
+ formattedTime += ' 0' ;
389
+ formattedTime += String (getHour ());
390
+ formattedTime += " :" ;
391
+
392
+ // Minutes
393
+ if (getMinutes () < 10 )
394
+ formattedTime += ' 0' ;
395
+ formattedTime += String (getMinutes ());
396
+ formattedTime += " :" ;
397
+
398
+ // Seconds
399
+ if (getSeconds () < 10 )
400
+ formattedTime += ' 0' ;
401
+ formattedTime += String (getSeconds ());
402
+
403
+ return formattedTime;
404
+ }
405
+
364
406
/* -------------------------------------------------------------------------- */
365
407
/* RTClass */
366
408
/* -------------------------------------------------------------------------- */
You can’t perform that action at this time.
0 commit comments