Yes, you are right. It is a pity that the month is given by three letters instead of a number in the DATE string. My solution was to add the ASCII codes of that letters and use a lookup table. I was lucky, as some sums are very close to each other. The startTime record wants strong types for Month, DayOfWeek, and SaveLight, so I used type-casting. This is my result:
#include <RTC.h>
void setup() {
Serial.begin(9600);
while (!Serial)
;
Serial.println(__FILE__);
Serial.println(__DATE__ " - " __TIME__);
char date[] = __DATE__, time[] = __TIME__;
//*
int day, month, year, hour, minute, second;
// time:
Serial.println(time);
hour = a2i(time, 0, 2);
Serial.print("Stunde ");
Serial.println(time);
minute = a2i(time, 3, 5);
Serial.print("Minute ");
Serial.println(time);
second = a2i(time, 6, 8);
Serial.print("Sekunde ");
Serial.println(time);
// date:
month = m2i(date, 0, 3);
day = a2i(date, 4, 6);
Serial.print("Tag ");
Serial.println(date);
year = a2i(date, 7, 11);
Serial.print("Jahr ");
Serial.println(date);
// RTC:
RTC.begin();
RTCTime startTime(day, (Month) month, year, hour, minute, second, (DayOfWeek) 1, (SaveLight) 1);
RTC.setTime(startTime);
}
int m2i(char *c, int from, int to) {
int mm[] = { 281, 269, 288, 291, 295, 301, 299, 285, 296, 294, 307, 268 };
int cc = c[0] + c[1] + c[2]; // add 3 characters
for (int i = 0; i < 12; i++) if (mm[i] == cc) return i + 1;
return 0;
}
int a2i(char *c, int from, int to) {
memset(c, ' ', from); // setzt die ersten from bytes auf ' '
char temp[12];
strncpy(temp, c, to); // kopiert die ersten to byte von c nach temp
return atoi(temp);
}
void loop() {
RTCTime currentTime;
RTC.getTime(currentTime); // Get current time from RTC
Serial.print("date time = ");
Serial.print(currentTime.getDayOfMonth());
Serial.print(".");
int m = (int)currentTime.getMonth();
Serial.print(m);
Serial.print(".");
Serial.print(currentTime.getYear());
Serial.print(" ");
Serial.print(currentTime.getHour());
Serial.print(":");
Serial.print(currentTime.getMinutes());
Serial.print(":");
Serial.println(currentTime.getSeconds());
delay(10000);
}
But the main problem is still unsolved: how does the Minima detect a power-cut and restarts with the time being set at the time of uploading?
No idea.