Skip to content

chore(examples): adopt merged stdlib time APIs (unix_now / write_http_header / update_http_header)#98

Merged
enghitalo merged 1 commit into
mainfrom
chore/examples-adopt-stdlib-time
Jul 6, 2026
Merged

chore(examples): adopt merged stdlib time APIs (unix_now / write_http_header / update_http_header)#98
enghitalo merged 1 commit into
mainfrom
chore/examples-adopt-stdlib-time

Conversation

@enghitalo

Copy link
Copy Markdown
Owner

Summary

vlang/v#27641 (time.unix_now) and vlang/v#27639 (time.write_http_header / time.update_http_header) have merged. Both were motivated by this repo's cached Date: header examples (vlang/v#27638), so the examples can now drop their hand-rolled implementations and call the stdlib directly.

No change on the wire; net −20 lines (the timerfd example alone sheds ~35 lines of hand-rolled formatting).

What changed

File Change
examples/async_date_timerfd/main.v Deleted hand-rolled put2 / rebuild_at internals / wkday_names / month_names / fn C.time. rebuild_at(now) is now a thin time.update_http_header(&line[6], 31, last, now) wrapper; rebuild() reads the clock via time.unix_now().
examples/efficient_date/main.v C.time()time.unix_now() (drops #include <time.h> + the C decl). push_to_http_header retained — it's allocation-free upstream now.
examples/date_header/src/main.v Double-buffer refresh()time.utc().write_http_header(&buf[6], 31) into the inactive buffer; new seed() lays the static "Date: " / CRLF frame into both buffers once.
examples/auth/src/main.v Two time.utc().unix()time.unix_now() (JWT expiry check + minting — the exact TTL use case, ~1216 ns → ~2 ns).

Tests

  • async_date_timerfd/main_test.v — keeps driving the rebuild_at(now) seam (restored as the stdlib wrapper) through every rollover vs the vlib formatter oracle.
  • date_header/src/main_test.v — added the now-required seed() calls; replaced test_handler_includes_date_header, which called a non-existent handle() (broken at HEAD — this example uses an inline request_handler closure), with test_response_includes_date_header that composes the response via the shared status_head / resp_tail consts and date_line().

Verification

  • v fmt -verify: clean on all 6 files.
  • v test examples/auth/src1 passed; v test examples/date_header/src1 passed.
  • async_date_timerfd / efficient_date typecheck cleanly through main() on macOS; only the pre-existing Linux-only .epoll backend blocks a full Darwin build (needs Linux CI to run).
  • Portable oracle harness confirmed the write_http_header / update_http_header integration (offset 6, dst_len 31) is byte-for-byte correct vs a freshly-formatted line across second / minute / hour / day / leap-day (2000, 2024) / epoch / year-end / backward-jump cases, plus dst_len < 29 refusal and static-frame integrity.

Note

Reviewer heads-up: date_header's handler test was latently broken on main — it referenced a handle() the closure-based example never defined. This suggests those src/-layout example tests aren't currently exercised in CI (V's src/ virtual-module deprecation makes v test examples/date_header/ error unless you target .../src). Fixed here while in the neighborhood.

🤖 Generated with Claude Code

…_header / update_http_header)

vlang/v#27641 (time.unix_now) and vlang/v#27639 (time.write_http_header,
time.update_http_header) merged. Both were motivated by this repo's cached
`Date:` header examples (vlang/v#27638), so those examples can now drop their
hand-rolled implementations and call the stdlib directly:

- async_date_timerfd: rebuild_at() is now a thin time.update_http_header wrapper
  (was hand-rolled put2/rebuild_at + wkday_names/month_names + fn C.time);
  rebuild() reads the clock via time.unix_now().
- efficient_date: C.time() -> time.unix_now() (drops #include <time.h> and the C
  decl); push_to_http_header retained (now allocation-free upstream).
- date_header: double-buffer refresh() -> time.utc().write_http_header() into the
  inactive buffer; seed() lays the static "Date: "/CRLF frame into both buffers once.
- auth: two time.utc().unix() -> time.unix_now() (JWT expiry check + minting).

Tests:
- async_date_timerfd/main_test.v: still drives the rebuild_at(now) seam (restored
  as the stdlib wrapper) through every rollover vs the vlib formatter oracle.
- date_header/main_test.v: add the now-required seed() calls; replace the test
  that called a non-existent handle() (broken at HEAD -- this example uses an
  inline request_handler closure) with one that composes the response via the
  shared status_head/resp_tail consts and date_line().

No change on the wire; net -20 lines. The write_http_header / update_http_header
integration (offset 6, dst_len 31) was verified byte-for-byte against a freshly
formatted line across second/minute/hour/day/leap-day/backward-jump rollovers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@enghitalo enghitalo force-pushed the chore/examples-adopt-stdlib-time branch from 3e0cb3f to 908782e Compare July 5, 2026 14:23
@enghitalo enghitalo merged commit 2589c6e into main Jul 6, 2026
20 of 29 checks passed
@enghitalo enghitalo deleted the chore/examples-adopt-stdlib-time branch July 6, 2026 04:03
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