Skip to content

time: time_tz: Handle conversion rules of windows and IANA tzinfo#11903

Merged
edsiper merged 4 commits into
masterfrom
cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo
Jun 3, 2026
Merged

time: time_tz: Handle conversion rules of windows and IANA tzinfo#11903
edsiper merged 4 commits into
masterfrom
cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo

Conversation

@cosmo0920
Copy link
Copy Markdown
Contributor

@cosmo0920 cosmo0920 commented Jun 3, 2026

In the current Fluent Bit code base, there is no conversion rules between windows timezone and IANA provided timezone information.
So, we need to implement this conversion rule map as built-in capability in Fluent Bit.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • New Features

    • Time zone conversion utilities for mapping between Windows and IANA identifiers.
    • UTC offset lookup for both Windows and IANA time zone strings.
  • Improvements

    • Thread-safe initialization for reliable, efficient conversions.
  • Tests

    • Added unit tests covering mappings, UTC offset lookups, and failure cases.

@cosmo0920 cosmo0920 requested a review from edsiper as a code owner June 3, 2026 03:00
@cosmo0920 cosmo0920 changed the title time: time_tz: Handle conversion rules of windows and iana tzinfo time: time_tz: Handle conversion rules of windows and IANA tzinfo Jun 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds public APIs and implementations for Windows↔IANA timezone name conversions and fixed standard UTC offset lookups, backed by a static mapping table with thread-safe indexed initialization and binary-search lookups, plus unit tests and build integration.

Changes

Time Zone Conversion

Layer / File(s) Summary
Public API contract
include/fluent-bit/flb_time.h
Four new public declarations for Windows↔IANA zone conversion and UTC offset resolution via long *offset.
Timezone mapping table
src/flb_time_tz.c
Adds the static Windows↔IANA mapping table and the fixed-standard UTC offset values used by lookups.
Index initialization and sorting
src/flb_time_tz.c
Thread-safe pthread_once initialization that constructs pointer indexes, deduplicates Windows keys, and sorts arrays for binary search.
Windows → IANA lookup
src/flb_time_tz.c
flb_time_windows_zone_to_iana using bsearch with case-insensitive Windows-key matching; returns mapped IANA string or NULL.
IANA → Windows lookup
src/flb_time_tz.c
flb_time_iana_zone_to_windows using bsearch with case-sensitive IANA-key matching; returns mapped Windows string or NULL.
Windows → UTC offset
src/flb_time_tz.c
flb_time_windows_zone_to_utc_offset validates args, bsearches, writes *offset and returns 0 on match or -1 on error/no match.
IANA → UTC offset
src/flb_time_tz.c
flb_time_iana_zone_to_utc_offset validates args, bsearches, writes *offset and returns 0 on match or -1 on error/no match.
Build integration
src/flb_time.c
Includes flb_time_tz.c to compile/link the timezone helpers.
Unit tests
tests/internal/flb_time.c
Adds <string.h>, four tests for the conversions and offset lookups, and updates TEST_LIST to register them.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

backport to v4.2.x

Suggested reviewers

  • edsiper
  • fujimotos
  • koleini

Poem

🐰 Across the world, the time zones hum,
Windows meets IANA, now they come,
Offsets found and names aligned,
A rabbit's table, neatly signed,
Hopping time, one mapping drum.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and directly summarizes the main change: adding conversion rules to handle Windows and IANA timezone conversions in Fluent Bit's time handling component.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef28805e1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/flb_time_tz.c Outdated
@cosmo0920 cosmo0920 force-pushed the cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo branch from ef28805 to fd4c248 Compare June 3, 2026 03:03
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/flb_time_tz.c (2)

510-578: ⚖️ Poor tradeoff

Optional: linear scans over ~460 entries per call.

Each conversion does an O(n) walk of the table (~460 rows). If these helpers end up on a per-record path, consider a sorted table + binary search or a small hash to reduce lookup cost. Fine to defer if calls are infrequent (e.g., config-time resolution).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/flb_time_tz.c` around lines 510 - 578, The current lookup functions
(flb_time_windows_zone_to_iana, flb_time_iana_zone_to_windows,
flb_time_windows_zone_to_utc_offset, flb_time_iana_zone_to_utc_offset) perform
linear scans over the windows_iana_timezones table (~460 entries) which is O(n)
per call; replace these linear scans with a faster lookup by either (a) building
two lookup tables at module init (e.g., a hash map for Windows->entry and one
for IANA->entry) or (b) sorting the arrays and using binary_search; implement
case-insensitive key handling for Windows names (strcasecmp semantics) when
populating/looking up, keep the current function signatures and return
semantics, and ensure the initialization is thread-safe or performed at startup
before any lookups.

20-28: ⚡ Quick win

Include the public header instead of re-declaring the prototypes.

flb_time.h already declares these four functions, but this file forward-declares them locally (Lines 25-28) and never includes the header. If a public signature changes, the compiler won't catch a mismatch between the declaration and the definition here. Include <fluent-bit/flb_time.h> and drop the local prototypes.

♻️ Proposed change
 `#include` <fluent-bit/flb_compat.h>
+#include <fluent-bit/flb_time.h>
 
 `#include` <stddef.h>
 `#include` <string.h>
-
-const char *flb_time_windows_zone_to_iana(const char *windows_zone);
-const char *flb_time_iana_zone_to_windows(const char *iana_zone);
-int flb_time_windows_zone_to_utc_offset(const char *windows_zone, long *offset);
-int flb_time_iana_zone_to_utc_offset(const char *iana_zone, long *offset);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/flb_time_tz.c` around lines 20 - 28, Remove the four redundant local
forward declarations for flb_time_windows_zone_to_iana,
flb_time_iana_zone_to_windows, flb_time_windows_zone_to_utc_offset, and
flb_time_iana_zone_to_utc_offset and instead include the public header
flb_time.h (e.g. add `#include` <fluent-bit/flb_time.h>) so the compilation uses
the canonical prototypes; this ensures any signature changes are caught by the
compiler and avoids duplicate declarations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/flb_time_tz.c`:
- Around line 510-578: The current lookup functions
(flb_time_windows_zone_to_iana, flb_time_iana_zone_to_windows,
flb_time_windows_zone_to_utc_offset, flb_time_iana_zone_to_utc_offset) perform
linear scans over the windows_iana_timezones table (~460 entries) which is O(n)
per call; replace these linear scans with a faster lookup by either (a) building
two lookup tables at module init (e.g., a hash map for Windows->entry and one
for IANA->entry) or (b) sorting the arrays and using binary_search; implement
case-insensitive key handling for Windows names (strcasecmp semantics) when
populating/looking up, keep the current function signatures and return
semantics, and ensure the initialization is thread-safe or performed at startup
before any lookups.
- Around line 20-28: Remove the four redundant local forward declarations for
flb_time_windows_zone_to_iana, flb_time_iana_zone_to_windows,
flb_time_windows_zone_to_utc_offset, and flb_time_iana_zone_to_utc_offset and
instead include the public header flb_time.h (e.g. add `#include`
<fluent-bit/flb_time.h>) so the compilation uses the canonical prototypes; this
ensures any signature changes are caught by the compiler and avoids duplicate
declarations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 93345a33-5ed7-48d2-bfc0-238106f3ab5a

📥 Commits

Reviewing files that changed from the base of the PR and between 992a4e5 and ef28805.

📒 Files selected for processing (4)
  • include/fluent-bit/flb_time.h
  • src/CMakeLists.txt
  • src/flb_time_tz.c
  • tests/internal/flb_time.c

@cosmo0920 cosmo0920 force-pushed the cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo branch from fd4c248 to b03eb52 Compare June 3, 2026 03:05
@cosmo0920 cosmo0920 force-pushed the cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo branch from b03eb52 to 9657cb8 Compare June 3, 2026 03:12
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/flb_time.c (1)

446-446: ⚖️ Poor tradeoff

Prefer compiling flb_time_tz.c as its own translation unit over #include-ing a .c file.

Including a .c file that contains externally-visible definitions is a code smell: it couples the two units, can confuse tooling/coverage, and risks ODR/duplicate-symbol issues if the file is ever picked up by the build glob. Since these are public APIs declared in flb_time.h, the cleaner approach is to add flb_time_tz.c to the build sources and drop this include.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/flb_time.c` at line 446, Remove the line that `#include`"s" flb_time_tz.c
from flb_time.c and instead compile flb_time_tz.c as a separate translation unit
by adding flb_time_tz.c to the project's build sources (e.g., the
Makefile/CMakeLists/meson build list). Ensure the public APIs declared in
flb_time.h and implemented in flb_time_tz.c remain unique (no duplicate
definitions) and update the build so linking picks up flb_time_tz.o; do not
leave any remaining `#include` of the .c file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/flb_time.c`:
- Line 446: Remove the line that `#include`"s" flb_time_tz.c from flb_time.c and
instead compile flb_time_tz.c as a separate translation unit by adding
flb_time_tz.c to the project's build sources (e.g., the
Makefile/CMakeLists/meson build list). Ensure the public APIs declared in
flb_time.h and implemented in flb_time_tz.c remain unique (no duplicate
definitions) and update the build so linking picks up flb_time_tz.o; do not
leave any remaining `#include` of the .c file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d15c7956-9dde-40b7-a083-93c1ffaabea3

📥 Commits

Reviewing files that changed from the base of the PR and between b03eb52 and 9657cb8.

📒 Files selected for processing (4)
  • include/fluent-bit/flb_time.h
  • src/flb_time.c
  • src/flb_time_tz.c
  • tests/internal/flb_time.c
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/internal/flb_time.c
  • include/fluent-bit/flb_time.h
  • src/flb_time_tz.c

@cosmo0920 cosmo0920 force-pushed the cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo branch from 9657cb8 to 8ef2b40 Compare June 3, 2026 03:17
@cosmo0920 cosmo0920 force-pushed the cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo branch from 8ef2b40 to a932a5e Compare June 3, 2026 03:20
@cosmo0920 cosmo0920 force-pushed the cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo branch from a932a5e to 423ae51 Compare June 3, 2026 03:21
cosmo0920 added 4 commits June 3, 2026 12:22
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@cosmo0920 cosmo0920 force-pushed the cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo branch from 423ae51 to 46dfaaf Compare June 3, 2026 03:24
@cosmo0920 cosmo0920 added this to the Fluent Bit v5.1 milestone Jun 3, 2026
@edsiper edsiper merged commit 4d1e206 into master Jun 3, 2026
60 of 61 checks passed
@edsiper edsiper deleted the cosmo0920-handle-conversion-rules-of-windows-and-iana-tzinfo branch June 3, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants