Skip to content

mtime incorrect in fatfs during daylight saving time (IDFGH-7467) #9039

@lbernstone

Description

@lbernstone

Environment

  • Development Kit: Custom, but N/A
  • Module or chip used: ESP32-C3, likely all
  • IDF version (run git describe --tags to find it): v4.4.1
  • Build System: Arduino
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it): riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64
  • Operating System: Linux
  • Using an IDE?: Yes , arduino just for convenience. No Arduino code included in example
  • Power Supply: USB

Problem Description

When a timezone is set with DST, and time is set inside DST, file modified time (mtime) is 3599 seconds off. Weird number, maybe something is supposed to be one hour diff, but isn't multiplied?

Expected Behavior

System time and file written time should be identical

Actual Behavior

22:29:11.888 -> systime: 1653638041
22:29:12.154 -> filetime: 1653641640

Steps to reproduce

#include <vfs_fat_internal.h>
static wl_handle_t hndWl = WL_INVALID_HANDLE;

void setup() {
  Serial.begin(115200);
  delay(2000);
  struct timeval tv = {1653638041, 0};
  settimeofday(&tv, NULL);
  setenv("TZ", "MST7MDT,M3.2.0,M11.1.0", 1);
  tzset();
  Serial.printf("systime: %d\n", time(NULL));
  const esp_vfs_fat_mount_config_t conf = {
      .format_if_mount_failed = true,
      .max_files = 4,
      .allocation_unit_size = CONFIG_WL_SECTOR_SIZE
  };
  esp_vfs_fat_spiflash_mount("/fatfs", "ffat", &conf, &hndWl);
  FILE *tfile = fopen("/fatfs/test", "w");
  fprintf(tfile, "hello");
  fclose(tfile);
  struct stat info;
  stat("/fatfs/test", &info);
  Serial.printf("filetime: %d\n", info.st_mtime);
}
void loop() {delay(-1);}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions