Skip to content

Document naive-datetime host time zone behaviour; use aware datetimes in examples - #55

Merged
hardbyte merged 1 commit into
mainfrom
brian/naive-datetime-docs
Sep 15, 2026
Merged

hardbyte merged 1 commit into
mainfrom
brian/naive-datetime-docs

Conversation

@hardbyte

Copy link
Copy Markdown
Owner

Refs #50, option 1 (document, no behaviour change).

  • Python API reference: the Python-to-CEL table notes that naive datetimes are read in the host's local time zone, with a warning box explaining why that matters for a policy engine and recommending datetime.now(timezone.utc).
  • Quick start, extending-cel tutorial and the Context.add_variable docstring switch from naive datetime.now() to timezone-aware values. Snippets that only pass .hour integers into CEL are unchanged since no datetime crosses the boundary there.
  • CHANGELOG entry under Unreleased.

Verified: doc snippets execute (tests/test_docs.py, tests/test_documentation.py), cargo fmt --check. Empirical demonstration of the problem with TZ=Pacific/Auckland: cel.evaluate('now', {'now': datetime(2026,1,1,14)}) returns 2026-01-01 14:00:00+13:00, i.e. 01:00Z, where a UTC host gives 14:00Z.

…re datetimes in examples

Refs #50. Option 1 from the issue: no behaviour change, the API reference
warns about the host-TZ dependence, and every example that hands a datetime
to CEL now uses datetime.now(timezone.utc).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-15T08:04:34.760828Z c8a25aa PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: c8a25aa1e2

ℹ️ 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 on lines +256 to +257
now = datetime.now(timezone.utc)
delta = expiry - now

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve support for offset-less expiry strings

When expiry_date_str is a valid ISO-8601 value without an offset, datetime.fromisoformat() returns a naive datetime, so subtracting the newly aware now raises TypeError; the broad handler then silently returns 0 and treats even a future subscription as expired. Either require and validate an offset explicitly or attach the intended timezone before performing the subtraction.

Useful? React with 👍 / 👎.

def is_business_hours():
# For testing purposes, always return True
# In production, use: datetime.now().hour to check 9 <= hour <= 17
# In production, use: datetime.now(timezone.utc).hour to check 9 <= hour <= 17

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check business hours in the business timezone

For organizations whose business hours are not defined in UTC, this production recommendation checks the wrong clock—for example, 09:00 in Auckland is 20:00 or 21:00 UTC on the preceding day. Since only the integer hour is used and no datetime crosses into CEL here, switching to UTC does not address the naive-datetime conversion issue; the example should use the organization's explicit ZoneInfo timezone instead.

Useful? React with 👍 / 👎.

@hardbyte
hardbyte merged commit 2c71b41 into main Sep 15, 2026
21 checks passed
@hardbyte
hardbyte deleted the brian/naive-datetime-docs branch September 15, 2026 08:09
@hardbyte hardbyte mentioned this pull request Sep 15, 2026
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