Skip to content

Default date and time the the compile date/time #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/RTCZero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void RTCZero::begin(bool resetTime)
while (RTCisSyncing())
;

RTCsetCompileTime();
_configured = true;
}

Expand Down Expand Up @@ -520,3 +521,42 @@ void RTCZero::RTCresetRemove()
while (RTCisSyncing())
;
}

void RTCZero::RTCsetCompileTime()
{
String time = __DATE__; // get compile time
uint8_t hours = t.substring(0, 2).toInt();
uint8_t minutes = t.substring(3, 5).toInt();
uint8_t seconds = t.substring(6, 8).toInt();
setTime(hours,minutes, seconds);

String date = __DATE__; // get compile date
String monStr = t.substring(0,3);
uint8_t day = t.substring(4,6).toInt()
uint8_t year = t.substring(7).toInt()
setDate(day, monIndex(monStr), year);
}

uint8_t RTCZero::monIndex(String monStr)
{
uint8_t monInt = 0;
// check for the last char
// in Mar & Apr - Jan & Jun the last char is identical so check the second one
switch(monStr[2]){
case 'n':
monInt = (monStr[1] == 'a')? 1 : 6;
break;
case 'b': monInt = 2; break;
case 'r':
monInt = (monStr[1] == 'a')? 3 : 4;
break;
case 'y': monInt = 5; break;
case 'l': monInt = 7; break;
case 'g': monInt = 8; break;
case 'p': monInt = 9; break;
case 't': monInt = 10; break;
case 'v': monInt = 11; break;
case 'c': monInt = 12; break;
}
return monInt;
}
2 changes: 2 additions & 0 deletions src/RTCZero.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class RTCZero {
void RTCenable();
void RTCreset();
void RTCresetRemove();
void RTCsetCompileTime();
uint8_t monIndex(String monStr);
};

#endif // RTC_ZERO_H