Skip to content

Rename baseservice.NowUTC to Now#1215

Merged
bgentry merged 3 commits intomasterfrom
bg/rename-nowutc-now
Apr 16, 2026
Merged

Rename baseservice.NowUTC to Now#1215
bgentry merged 3 commits intomasterfrom
bg/rename-nowutc-now

Conversation

@bgentry
Copy link
Copy Markdown
Contributor

@bgentry bgentry commented Apr 16, 2026

After opening #1213 I thought it'd be better to instead fix the underlying time API.

The shared baseservice clock exposed NowUTC, NowUTCOrNil, and StubNowUTC, but those names overstated what the production path was actually doing. The unstubbable implementation already returned time.Now() rather than normalizing through UTC(), so the API was implying a UTC guarantee that callers were not actually getting. This renames the clock APIs to Now, NowOrNil, and StubNow so the abstraction matches its real job: providing a process-local clock for deadline and duration math, plus an optional stubbed wall-clock value for database-facing test paths.

This also makes the monotonic-clock compatibility explicit in the documentation. If the production implementation were changed to normalize through UTC(), it would strip Go’s monotonic reading and make the API a bad fit for in-process elapsed-time calculations. The relevant Go documentation is here: Monotonic Clocks in the time package:

Because t.In, t.Local, and t.UTC are used for their effect on the interpretation of the wall time, they also strip any monotonic clock reading from their results. The canonical way to strip a monotonic clock reading is to use t = t.Round(0).

Fortunately we weren't actually relying on the UTC behavior since it wasn't being applied in prod, so it's an easy switch. Only two small test updates were needed beyond the simple bulk renames.

bgentry added 3 commits April 16, 2026 16:45
The shared base-service clock exposed `NowUTC`, `NowUTCOrNil`, and
`StubNowUTC`, but those names overstated what the production path was
actually doing. The unstubbable implementation already returned
`time.Now()` rather than normalizing through `UTC()`, so the API was
implying a UTC guarantee that callers were not actually getting.

Rename the clock APIs to `Now`, `NowOrNil`, and `StubNow` so the
abstraction matches its real job: providing a process-local clock for
deadline and duration math, plus an optional stubbed wall-clock value for
database-facing test paths.

This also makes the monotonic-clock constraint explicit in the
documentation. If the production implementation were changed to normalize
through `UTC()`, it would strip Go's monotonic reading and make the API a
bad fit for in-process elapsed-time calculations.
Make the unstubbed fallback path in `riversharedtest.TimeStub` return
`time.Now()` so tests exercise the same non-UTC, monotonic-preserving
semantics as the production clock. Update the matching base-service test
expectation accordingly.
@bgentry bgentry requested a review from brandur April 16, 2026 21:50
@bgentry
Copy link
Copy Markdown
Contributor Author

bgentry commented Apr 16, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ 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".

Copy link
Copy Markdown
Contributor

@brandur brandur left a comment

Choose a reason for hiding this comment

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

WFM!

@bgentry bgentry merged commit 6543473 into master Apr 16, 2026
15 checks passed
@bgentry bgentry deleted the bg/rename-nowutc-now branch April 16, 2026 22:36
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