Skip to content

Configure date and time formatting independently#105

Merged
methodofaction merged 3 commits intomainfrom
date-time
Apr 27, 2026
Merged

Configure date and time formatting independently#105
methodofaction merged 3 commits intomainfrom
date-time

Conversation

@methodofaction
Copy link
Copy Markdown
Contributor

Fixes APP-472

Summary

  • Replaces CalFormatter.DateTime with a Time field. cal.DateTime rendering now composes <date format> · <time format>, so a user-supplied date_format always applies — even when the document has an issue time.
  • Adds a time_format query parameter to the CLI server, configured independently from date_format.

Public API change

The second parameter of goblhtml.WithCalFormatter(date, time, loc) is now a time-only template (e.g. 15:04, 3:04 PM) instead of a combined date-time template (e.g. 2006-01-02 · 15:04). The only in-repo caller (cmd/gobl.html) passed "", so it is unaffected. External callers (notably pdf.go) will need to pass a time format instead of a combined template.

Test plan

  • go build ./...
  • go test ./... (defaults still produce identical output: 2026-03-25 · 12:34)
  • Manual render with WithCalFormatter("02/01/2006", "", time.UTC) on co-dian-invoice.json (has issue_date + issue_time) now outputs 25/03/2026 · 12:34 — bug fixed
  • Manual render with WithCalFormatter("02/01/2006", "3:04 PM", time.UTC) outputs 25/03/2026 · 12:34 PM — independent time format confirmed

🤖 Generated with Claude Code

When a document has both an issue date and an issue time, rendering
went through a separate `CalFormatter.DateTime` template (default
ISO `2006-01-02 · 15:04`). A user-supplied `date_format` only
overrode `CalFormatter.Date`, so date+time fields silently kept the
ISO date format and the user's preference was lost.

Replace `CalFormatter.DateTime` with a `Time` field (default
`15:04`) and compose `cal.DateTime` rendering as
`<Date><sep><Time>`. This guarantees the user's date format always
applies, and lets time be configured independently. Add a new
`time_format` query param to the CLI server.

Public API change: the second parameter of `WithCalFormatter` is
now a time-only template (e.g. `15:04`) instead of a combined
date-time template. The only in-repo caller passed `""` so it is
unaffected; external callers passing a full datetime template will
need to update.

Fixes APP-472

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates calendar formatting so date and time can be configured independently, ensuring date_format is always honored even when documents include an issue time (APP-472).

Changes:

  • Replace CalFormatter.DateTime with a dedicated Time format and render cal.DateTime as <date> · <time>.
  • Update WithCalFormatter(date, time, loc) to accept a time-only format as its second parameter.
  • Add a time_format query parameter to the cmd/gobl.html server and wire it into rendering options.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/options.go Refactors CalFormatter to separate date vs time formats and defines a shared date-time separator.
goblhtml.go Updates the public option WithCalFormatter to accept a time-only format and apply it to internal options.
components/t/i18n.templ Changes cal.DateTime localization to compose formatted date + separator + formatted time.
components/t/i18n_templ.go Regenerates templ output to match the updated template/imports and new formatting logic.
cmd/gobl.html/serve.go Adds time_format query param and passes it through to WithCalFormatter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread goblhtml.go Outdated
Comment thread components/t/i18n.templ
Copy link
Copy Markdown
Contributor

@cavalle cavalle left a comment

Choose a reason for hiding this comment

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

LGTM!

@methodofaction methodofaction merged commit 1f152f7 into main Apr 27, 2026
4 checks passed
@methodofaction methodofaction deleted the date-time branch April 27, 2026 15:38
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.

4 participants