Skip to content
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

Add seconds to timestamp #452

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
16 changes: 16 additions & 0 deletions src/ExFatLib/ExFatFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ bool ExFatFile::getCreateDateTime(uint16_t* pdate, uint16_t* ptime) {
*ptime = getLe16(df->createTime);
return true;

fail:
return false;
}
//------------------------------------------------------------------------------
bool ExFatFile::getCreateDateTimeSeconds(uint16_t* pdate, uint16_t* ptime, uint8_t* pseconds) {
DirFile_t* df = reinterpret_cast<DirFile_t*>(
m_vol->dirCache(&m_dirPos, FsCache::CACHE_FOR_READ));
if (!df) {
DBG_FAIL_MACRO;
goto fail;
}
*pdate = getLe16(df->createDate);
*ptime = getLe16(df->createTime);
*pseconds = df->createTimeMs;
return true;

fail:
return false;
}
Expand Down
16 changes: 16 additions & 0 deletions src/ExFatLib/ExFatFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ class ExFatFile {
* \return true for success or false for failure.
*/
bool getCreateDateTime(uint16_t* pdate, uint16_t* ptime);
/** Get a file's create date and time (with seconds).
*
* \param[out] pdate Packed date for directory entry.
* \param[out] ptime Packed time for directory entry.
* \param[out] pseconds Packed seconds for directory entry.
*
* \return true for success or false for failure.
*/
bool getCreateDateTimeSeconds(uint16_t* pdate, uint16_t* ptime, uint8_t* pseconds);
/** \return All error bits. */
uint8_t getError() const { return isOpen() ? m_error : 0XFF; }
/** Get a file's modify date and time.
Expand Down Expand Up @@ -462,6 +471,13 @@ class ExFatFile {
* \return true for success or false for failure.
*/
size_t printCreateDateTime(print_t* pr);
/** Print a file's creation date and time (with seconds)
*
* \param[in] pr Print stream for output.
*
* \return true for success or false for failure.
*/
size_t printCreateDateTimeSeconds(print_t* pr);
/** Print a number followed by a field terminator.
* \param[in] value The number to be printed.
* \param[in] term The field terminator. Use '\\n' for CR LF.
Expand Down
13 changes: 13 additions & 0 deletions src/ExFatLib/ExFatFilePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ size_t ExFatFile::printCreateDateTime(print_t* pr) {
return 0;
}
//------------------------------------------------------------------------------
size_t ExFatFile::printCreateDateTimeSeconds(print_t* pr) {
uint32_t datetime;
uint16_t date;
uint16_t time;
uint8_t seconds;
int8_t tz = 8;

if (getCreateDateTimeSeconds(&date, &time, &seconds)) {
return (fsPrintDate(pr, date) && fsPrintTime(pr, time, seconds));
}
return 0;
}
//------------------------------------------------------------------------------
size_t ExFatFile::printFileSize(print_t* pr) {
uint64_t n = m_validLength;
char buf[21];
Expand Down
15 changes: 15 additions & 0 deletions src/FatLib/FatFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,21 @@ bool FatFile::getCreateDateTime(uint16_t* pdate, uint16_t* ptime) {
*ptime = getLe16(dir.createTime);
return true;

fail:
return false;
}
//------------------------------------------------------------------------------
bool FatFile::getCreateDateTimeSeconds(uint16_t* pdate, uint16_t* ptime, uint8_t* pseconds) {
DirFat_t dir;
if (!dirEntry(&dir)) {
DBG_FAIL_MACRO;
goto fail;
}
*pdate = getLe16(dir.createDate);
*ptime = getLe16(dir.createTime);
*pseconds = dir.createTimeMs;
return true;

fail:
return false;
}
Expand Down
16 changes: 16 additions & 0 deletions src/FatLib/FatFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ class FatFile {
* \return true for success or false for failure.
*/
bool getCreateDateTime(uint16_t* pdate, uint16_t* ptime);
/** Get a file's create date and time (with seconds).
*
* \param[out] pdate Packed date for directory entry.
* \param[out] ptime Packed time for directory entry.
* \param[out] pseconds Packed time for directory entry.
*
* \return true for success or false for failure.
*/
bool getCreateDateTimeSeconds(uint16_t* pdate, uint16_t* ptime, uint8_t* pseconds);
/** \return All error bits. */
uint8_t getError() const { return m_error; }
/** Get a file's modify date and time.
Expand Down Expand Up @@ -590,6 +599,13 @@ class FatFile {
* \return The number of bytes printed.
*/
size_t printCreateDateTime(print_t* pr);
/** Print a file's creation date and time (with seconds)
*
* \param[in] pr Print stream for output.
*
* \return The number of bytes printed.
*/
size_t printCreateDateTimeSeconds(print_t* pr);
/** %Print a directory date field.
*
* Format is yyyy-mm-dd.
Expand Down
14 changes: 14 additions & 0 deletions src/FatLib/FatFilePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ size_t FatFile::printCreateDateTime(print_t* pr) {
return 0;
}
//------------------------------------------------------------------------------
size_t FatFile::printCreateDateTimeSeconds(print_t* pr) {
uint32_t datetime;
uint16_t date;
uint16_t time;
uint8_t seconds;
int8_t tz = 8;

if (getCreateDateTimeSeconds(&date, &time, &seconds)) {
datetime = date+time;
return fsPrintDateTime(pr, datetime, seconds, tz);
}
return 0;
}
//------------------------------------------------------------------------------
size_t FatFile::printModifyDateTime(print_t* pr) {
uint16_t date;
uint16_t time;
Expand Down
11 changes: 11 additions & 0 deletions src/FsLib/FsFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,17 @@ class FsBaseFile {
: m_xFile ? m_xFile->printCreateDateTime(pr)
: 0;
}
/** Print a file's creation date and time
*
* \param[in] pr Print stream for output.
*
* \return true for success or false for failure.
*/
size_t printCreateDateTimeSeconds(print_t* pr) {
return m_fFile ? m_fFile->printCreateDateTimeSeconds(pr)
: m_xFile ? m_xFile->printCreateDateTimeSeconds(pr)
: 0;
}
/** Print a number followed by a field terminator.
* \param[in] value The number to be printed.
* \param[in] term The field terminator. Use '\\n' for CR LF.
Expand Down
3 changes: 2 additions & 1 deletion src/common/FsDateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ size_t fsPrintTime(print_t* pr, uint16_t time) {
//------------------------------------------------------------------------------
size_t fsPrintTime(print_t* pr, uint16_t time, uint8_t sec100) {
// Allow hh:mm:ss
char buf[sizeof("hh:mm:ss") - 1];
char buf[sizeof(" hh:mm:ss") - 1];
char* str = buf + sizeof(buf);
str = fsFmtTime(str, time, sec100);
*--str = ' ';
return pr->write(reinterpret_cast<uint8_t*>(str), buf + sizeof(buf) - str);
}
//------------------------------------------------------------------------------
Expand Down