espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.64k stars 7.41k forks source link

Wish the SD library supported the newer SDFat date and time methods. #6362

Closed KurtE closed 2 years ago

KurtE commented 2 years ago

Related area

SD

Hardware specification

no - but playing with Sparkfun ESP32 Micromod and Thing Plus

Is your feature request related to a problem?

I am playing around with porting some code from a Teensy 4.x that uses their SD library support and noticed that the ESP32 code does not have the newer date and time methods that were added to the SDFat github project. Which include:

  /** Get a file's access date and time.
   *
   * \param[out] pdate Packed date for directory entry.
   * \param[out] ptime Packed time for directory entry.
   *
   * \return true for success or false for failure.
   */
  bool getAccessDateTime(uint16_t* pdate, uint16_t* ptime) {
    return m_fFile ? m_fFile->getAccessDateTime(pdate, ptime) :
           m_xFile ? m_xFile->getAccessDateTime(pdate, ptime) : false;
  }
  /** Get a file's create date and time.
   *
   * \param[out] pdate Packed date for directory entry.
   * \param[out] ptime Packed time for directory entry.
   *
   * \return true for success or false for failure.
   */
  bool getCreateDateTime(uint16_t* pdate, uint16_t* ptime) {
    return m_fFile ? m_fFile->getCreateDateTime(pdate, ptime) :
           m_xFile ? m_xFile->getCreateDateTime(pdate, ptime) : false;
  }
  /** Get a file's Modify date and time.
   *
   * \param[out] pdate Packed date for directory entry.
   * \param[out] ptime Packed time for directory entry.
   *
   * \return true for success or false for failure.
   */
  bool getModifyDateTime(uint16_t* pdate, uint16_t* ptime) {
    return m_fFile ? m_fFile->getModifyDateTime(pdate, ptime) :
           m_xFile ? m_xFile->getModifyDateTime(pdate, ptime) : false;
  }

And likewise the method to update them

  /** Set a file's timestamps in its directory entry.
   *
   * \param[in] flags Values for \a flags are constructed by a bitwise-inclusive
   * OR of flags from the following list
   *
   * T_ACCESS - Set the file's last access date and time.
   *
   * T_CREATE - Set the file's creation date and time.
   *
   * T_WRITE - Set the file's last write/modification date and time.
   *
   * \param[in] year Valid range 1980 - 2107 inclusive.
   *
   * \param[in] month Valid range 1 - 12 inclusive.
   *
   * \param[in] day Valid range 1 - 31 inclusive.
   *
   * \param[in] hour Valid range 0 - 23 inclusive.
   *
   * \param[in] minute Valid range 0 - 59 inclusive.
   *
   * \param[in] second Valid range 0 - 59 inclusive
   *
   * \note It is possible to set an invalid date since there is no check for
   * the number of days in a month.
   *
   * \note
   * Modify and access timestamps may be overwritten if a date time callback
   * function has been set by dateTimeCallback().
   *
   * \return true for success or false for failure.
   */
  bool timestamp(uint8_t flags, uint16_t year, uint8_t month, uint8_t day,
                 uint8_t hour, uint8_t minute, uint8_t second) {
    return m_fFile ?
           m_fFile->timestamp(flags, year, month, day, hour, minute, second) :
           m_xFile ?
           m_xFile->timestamp(flags, year, month, day, hour, minute, second) :
           false;
  }

Describe the solution you'd like

Add in the newer mthods

Describe alternatives you've considered

No response

Additional context

No response

I have checked existing list of Feature requests and the Contribution Guide

me-no-dev commented 2 years ago

We do not use SDFat, bur FATFS from ESP-IDF: https://github.com/espressif/esp-idf/tree/master/components/fatfs

KurtE commented 2 years ago

Thanks @me-no-dev

Understand personally wish that you actually had the stuff as part of your FS.h such as we have done for the Teensy boards. where our File and FileImpl classes have new added methods:

    virtual bool getCreateTime(DateTimeFields &tm) { return false; }
    virtual bool getModifyTime(DateTimeFields &tm) { return false; }
    virtual bool setCreateTime(const DateTimeFields &tm) { return false; }
    virtual bool setModifyTime(const DateTimeFields &tm) { return false; }

And our SD library as well as our LittleFS were updated to support these...

Now back to playing