Skip to content

Record FAT file timestamps in UTC - #33

Merged
deadprogram merged 1 commit into
tinygo-org:releasefrom
davecheney:dfc/fatfs-utc-optimization
Oct 13, 2026
Merged

deadprogram merged 1 commit into
tinygo-org:releasefrom
davecheney:dfc/fatfs-utc-optimization

Conversation

@davecheney

@davecheney davecheney commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

go_fatfs_get_fattime called Date() on the result of time.Now(), which is in the local time zone. To calculate the local date, Date() must load the local time zone. This caused the time zone loader (time.loadTzinfo, time.tzset and related functions) to be included in the binary. In the examples/console/fatfs/machine example on pico2, this increased the binary size by 4,408 bytes of flash.

Write all FAT timestamps in UTC. Most microcontrollers do not have a real-time clock, so these timestamps are seldom correct, and a time zone adds no value.

@davecheney
davecheney force-pushed the dfc/fatfs-utc-optimization branch 4 times, most recently from 64be2de to 552197c Compare October 13, 2026 12:10
go_fatfs_get_fattime called Date() on the result of time.Now(), which is in the local time zone. To calculate the local date, Date() must load the local time zone. This caused the time zone loader (time.loadTzinfo, time.tzset and related functions) to be included in the binary. In the examples/console/fatfs/machine example on pico2, this increased the binary size by 4,408 bytes of flash.

Write all FAT timestamps in UTC. Most microcontrollers do not have a real-time clock, so these timestamps are seldom correct, and a time zone adds no value.
@davecheney
davecheney force-pushed the dfc/fatfs-utc-optimization branch from 552197c to 11fbcd7 Compare October 13, 2026 12:11
@davecheney

davecheney commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@deadprogram PTAL. This does change the timezone of the timestamp that is written, or more specifically the TZ offset that is used to compute the fat timestamp, but I argue that as most micro's don't have an RTC, the timestamp they were writing wasn't correct, and using the "local" timezone for that timestamp is equally flawed for a system without an RTC.

I argue, without strong supporting evidence, that systems writing files to FAT formatted systems would prefer the 4kb of programs space back -- and probably some heap -- more than they prefer a bike shed about timestamps.

@deadprogram deadprogram left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @davecheney now merging.

@deadprogram
deadprogram merged commit 917df84 into tinygo-org:release Oct 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants