Skip to content

libc/time: Fix POSIX timezone string parsing - #19516

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Zepp-Hanzj:fix/posix-timezone-19446
Jul 25, 2026
Merged

libc/time: Fix POSIX timezone string parsing#19516
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Zepp-Hanzj:fix/posix-timezone-19446

Conversation

@Zepp-Hanzj

Copy link
Copy Markdown
Contributor

Summary

  • fall back to parsing a POSIX TZ string when loading a zoneinfo file fails
  • keep the leading-colon form as file-only, as required by the existing semantics

This addresses the POSIX timezone parsing part of #19446. The reported ROMFS
archive build error is not changed here because it did not reproduce on the
current master branch.

Root cause

The conditions around tzparse() were inverted. The fallback was attempted
only for names beginning with :, and a parse failure was treated as success.
As a result, ordinary POSIX TZ strings such as ART3 and JST-9 fell back to
UTC instead of applying their offsets.

Validation

Tested with sim:nsh using:

CONFIG_LIBC_LOCALTIME=y
CONFIG_LIBC_TZDIR="/etc/zoneinfo"
# CONFIG_LIBC_ZONEINFO is not set

The simulator was rebuilt from make distclean before both runs.

Observed before this change:

TZ=UTC0   08:03:19
TZ=ART3   08:03:36
TZ=JST-9  08:03:56
TZ=:ART3  08:04:06

Observed after this change:

TZ=UTC0   08:09:52
TZ=ART3   05:10:05
TZ=JST-9  17:10:18
TZ=:ART3  08:10:24

ART3 now applies UTC-3, JST-9 applies UTC+9, and :ART3 remains
file-only and falls back to UTC when that file is unavailable.

Additional checks:

  • make -j$(nproc)
  • tools/checkpatch.sh -f libs/libc/time/lib_localtime.c

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Jul 24, 2026
@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

nuttx-tz-after.log
nuttx-tz-before.log
test log here

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

When loading a zoneinfo file fails, parse a non-colon-prefixed TZ value
as a POSIX timezone string. Treat a successful tzparse() result as
success while preserving the leading-colon file-only behavior.

Assisted-by: Codex:gpt-5.6 Sol
Signed-off-by: hanzhijian <hanzhijian@zepp.com>
@Zepp-Hanzj
Zepp-Hanzj force-pushed the fix/posix-timezone-19446 branch from 79a34c3 to a9a1149 Compare July 24, 2026 08:26
@acassis

acassis commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@acassis acassis mentioned this pull request Jul 24, 2026
1 task
@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

@Zepp-Hanzj did you test with https://nuttx.apache.org/docs/latest/components/libs/libc/zoneinfo.html ?

version.log
build.log
config-check.log
context.log
runtime.log

My previous validation did not enable CONFIG_LIBC_ZONEINFO. I have now retested the current PR with the documented sim:nsh ROMFS configuration:
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_LIBC_LOCALTIME=y
CONFIG_LIBC_TZDIR="/share/zoneinfo"
CONFIG_LIBC_TZ_MAX_TIMES=370
CONFIG_LIBC_TZ_MAX_TYPES=20
CONFIG_LIBC_ZONEINFO=y
CONFIG_LIBC_ZONEINFO_ROMFS=y
Both make context and the full build succeeded. The zoneinfo ROMFS was mounted successfully at /share/zoneinfo.
With the same runtime timestamp:
UTC0 2026-07-25T00:38:38
US/Mountain 2026-07-24T18:38:38
:US/Mountain 2026-07-24T18:38:38
ART3 2026-07-24T21:38:38
This confirms that file-backed zoneinfo, including the leading-colon file-only form, still works correctly, while the POSIX fallback now handles ART3 as UTC-3.

@acassis
acassis marked this pull request as ready for review July 25, 2026 10:16
@acassis
acassis requested a review from Donny9 as a code owner July 25, 2026 10:16
@xiaoxiang781216
xiaoxiang781216 merged commit 5f0c1c8 into apache:master Jul 25, 2026
53 checks passed
@Zepp-Hanzj
Zepp-Hanzj deleted the fix/posix-timezone-19446 branch July 25, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants