Skip to content

feat: add ability to force 32bit epoch time#4

Open
milkpirate wants to merge 1 commit intoESPToolKit:mainfrom
milkpirate:feat/add-ESPDATE_FORCE_32BIT_EPOCH-option
Open

feat: add ability to force 32bit epoch time#4
milkpirate wants to merge 1 commit intoESPToolKit:mainfrom
milkpirate:feat/add-ESPDATE_FORCE_32BIT_EPOCH-option

Conversation

@milkpirate
Copy link

@milkpirate milkpirate commented Mar 15, 2026

Summary

My ESP core seems to fill only the lower 32 bits of it 64bit time_t with the correct epoch value. But does not clear the upper bits leave garbage, which causes issues when the value is cast back to int64_t.

NOTE: Enableing ESPDATE_FORCE_32BIT_EPOCH will reintroduces the year 2038 problem.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactor (code change that neither fixes a bug nor adds a feature)
  • Documentation update
  • Build/CI

Details

  • What does this PR change? Why? See description.
  • Any context for reviewers to understand decisions and tradeoffs. No.

Testing

  • Builds locally
  • Unit tests added/updated
  • Tested on target hardware/device (if applicable)

Describe how you tested the changes. Include commands, logs, or screenshots if helpful.

[vars]
serial_speed = 115200

[platformio]
core_dir = .platformio_core/
default_envs = pico32

[env:pico32]
platform = espressif32 @ ^6.13.0
board = pico32
framework = arduino
upload_speed = 921600
monitor_speed = ${vars.serial_speed}
platform_packages =
	espressif/toolchain-xtensa-esp32 @ ~12
build_flags =
	-std=gnu2x
	-std=gnu++23
	-DSERIAL_BAUD_RATE=${vars.serial_speed}
	-DESPDATE_FORCE_32BIT_EPOCH
build_unflags =
	-std=gnu11
	-std=gnu++11
lib_deps =
	https://github.com/milkpirate/esp-date.git#feat/add-ESPDATE_FORCE_32BIT_EPOCH-option
debug_tool = esp-prog
void loop() {
    auto now = date.now();
    Serial.println(now.epochSeconds);
    Serial.println(now.localString().c_str());
    delay(1000);
}

Without -DESPDATE_FORCE_32BIT_EPOCH:

1862973903003830
241157-08-02 11:23:50
1862982492938423
241429-10-16 00:20:23
1862973903003832
241157-08-02 11:23:52
1862969608036537
241021-06-26 04:55:37
1862969608036538
241021-06-26 04:55:38
1862973903003835
241157-08-02 11:23:55
1862973903003836
241157-08-02 11:23:56
1862973903003837
241157-08-02 11:23:57
1862973903003838
241157-08-02 11:23:58
1862973903003839
241157-08-02 11:23:59
1862973903003840
241157-08-02 11:24:00
1862969608036545
241021-06-26 04:55:45

with -DESPDATE_FORCE_32BIT_EPOCH:

1773592930
2026-03-15 17:42:10
1773592931
2026-03-15 17:42:11
1773592932
2026-03-15 17:42:12
1773592933
2026-03-15 17:42:13
1773592934
2026-03-15 17:42:14
1773592935
2026-03-15 17:42:15

Compatibility / Breaking Changes

  • Describe any API, ABI, or behavior changes. None.
  • Migration steps for users (if any). None

Risks and Mitigations

  • Potential risks introduced by this change and how they’re mitigated.
    Warning was given via preprocessor if enabled.

Checklist

  • [?] Code follows project style and conventions
  • All tests pass locally
  • Documentation updated (README, examples, comments)
  • No secrets, credentials, or sensitive data committed
  • Linked issue(s) and relevant context provided

Environment

  • Toolchain/SDK versions: (e.g., ESP-IDF/PlatformIO/GCC)
  • OS and version: see above
  • Other relevant environment details: none

Signed-off-by: Paul Schroeder <milkpirate@users.noreply.github.com>
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.

1 participant