Skip to content

Support for configurable time formats - #101

Open
alexejk wants to merge 4 commits into
masterfrom
time-formats
Open

Support for configurable time formats#101
alexejk wants to merge 4 commits into
masterfrom
time-formats

Conversation

@alexejk

@alexejk alexejk commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Closes #100.

<dateTime.iso8601> was hardcoded to time.RFC3339 in both directions, which doesn't match what servers actually emit — the spec shows a compact example, mandates no layout, and leaves timezone assumptions to server documentation.

A new TimeFormat option makes encoding and decoding configurable:

c, err := xmlrpc.NewClient(endpoint, xmlrpc.TimeFormat(&xmlrpc.LayoutTimeFormatter{
    FormatLayout:   xmlrpc.LayoutISO8601Compact, // 19980717T14:08:55
    FormatLocation: time.UTC,                    // zone-less layout needs a pinned zone
    ParseLayouts:   xmlrpc.CommonParseLayouts(), // accept the common variants
}))

Fields come in two pairs: Format* controls what goes on the wire, Parse* what is accepted off it. Servers doing something stranger can implement the TimeFormatter interface directly.

Defaults are unchanged. With no option set, values encode and decode exactly as before, including time.Parse's handling of offsets that match the local
zone. The one observable difference is that a failed default parse now returns a wrapped error rather than a bare *time.ParseError — errors.As still works, a direct type assertion does not.

Thanks to @stricker-devmode for raising this and for the analysis in #100.


Stack created with GitHub Stacks CLIGive Feedback 💬

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@alexejk
alexejk force-pushed the time-formats branch 2 times, most recently from 7063a9e to 4cf51fa Compare August 31, 2026 15:16
@alexejk
alexejk changed the base branch from master to ci-hardening August 31, 2026 15:20
Base automatically changed from ci-hardening to master August 31, 2026 15:35
@sonarqubecloud

Copy link
Copy Markdown

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.

Support custom time format strings

1 participant