Skip to content
Merged
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
19 changes: 10 additions & 9 deletions libraries/FatFS/src/FatFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,18 @@ DWORD get_fattime() {
} else {
now = time(nullptr);
}
struct tm *stm = localtime(&now);
if (stm->tm_year < 80) {
struct tm stm;
localtime_r(&now, &stm);
if (stm.tm_year < 80) {
// FAT can't report years before 1980
stm->tm_year = 80;
stm.tm_year = 80;
}
return (DWORD)(stm->tm_year - 80) << 25 |
(DWORD)(stm->tm_mon + 1) << 21 |
(DWORD)stm->tm_mday << 16 |
(DWORD)stm->tm_hour << 11 |
(DWORD)stm->tm_min << 5 |
(DWORD)stm->tm_sec >> 1;
return (DWORD)(stm.tm_year - 80) << 25 |
(DWORD)(stm.tm_mon + 1) << 21 |
(DWORD)stm.tm_mday << 16 |
(DWORD)stm.tm_hour << 11 |
(DWORD)stm.tm_min << 5 |
(DWORD)stm.tm_sec >> 1;
}

}
5 changes: 3 additions & 2 deletions libraries/FatFSUSB/examples/Listfiles-USB/Listfiles-USB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ void printDirectory(String dirName, int numTabs) {
Serial.print("\t\t");
Serial.print(dir.fileSize(), DEC);
time_t cr = dir.fileCreationTime();
struct tm* tmstruct = localtime(&cr);
Serial.printf("\t%d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
struct tm tmstruct;
localtime_r(&cr, &tmstruct);
Serial.printf("\t%d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
}
}
}
9 changes: 5 additions & 4 deletions libraries/SD/examples/CardInfo/CardInfo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ void printDirectory(File dir, int numTabs) {
Serial.print(entry.size(), DEC);
time_t cr = entry.getCreationTime();
time_t lw = entry.getLastWrite();
struct tm* tmstruct = localtime(&cr);
Serial.printf("\tCREATION: %d-%02d-%02d %02d:%02d:%02d", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
tmstruct = localtime(&lw);
Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
struct tm tmstruct;
localtime_r(&cr, &tmstruct);
Serial.printf("\tCREATION: %d-%02d-%02d %02d:%02d:%02d", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
localtime_r(&lw, &tmstruct);
Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
}
entry.close();
}
Expand Down
9 changes: 5 additions & 4 deletions libraries/SD/examples/listfiles/listfiles.ino
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ void printDirectory(File dir, int numTabs) {
Serial.print(entry.size(), DEC);
time_t cr = entry.getCreationTime();
time_t lw = entry.getLastWrite();
struct tm* tmstruct = localtime(&cr);
Serial.printf("\tCREATION: %d-%02d-%02d %02d:%02d:%02d", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
tmstruct = localtime(&lw);
Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
struct tm tmstruct;
localtime_r(&cr, &tmstruct);
Serial.printf("\tCREATION: %d-%02d-%02d %02d:%02d:%02d", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
localtime_r(&lw, &tmstruct);
Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
}
entry.close();
}
Expand Down
7 changes: 4 additions & 3 deletions libraries/SDFS/src/SDFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ class SDFSImpl : public FSImpl {
} else {
now = time(nullptr);
}
struct tm *tiempo = localtime(&now);
*dosYear = ((tiempo->tm_year - 80) << 9) | ((tiempo->tm_mon + 1) << 5) | tiempo->tm_mday;
*dosTime = (tiempo->tm_hour << 11) | (tiempo->tm_min << 5) | tiempo->tm_sec;
struct tm tiempo;
localtime_r(&now, &tiempo);
*dosYear = ((tiempo.tm_year - 80) << 9) | ((tiempo.tm_mon + 1) << 5) | tiempo.tm_mday;
*dosTime = (tiempo.tm_hour << 11) | (tiempo.tm_min << 5) | tiempo.tm_sec;
}

protected:
Expand Down
4 changes: 3 additions & 1 deletion libraries/rp2040/examples/Time/Time.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ void loop() {
char buff[80];

time(&now);
strftime(buff, sizeof(buff), "%c", localtime(&now));
struct tm tmstruct;
localtime_r(&now, &tmstruct);
strftime(buff, sizeof(buff), "%c", &tmstruct);
Serial.println(buff);
delay(1000);
}
Loading