Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for alternative timestamp formats #310

Merged
merged 2 commits into from
Jan 8, 2018

Conversation

rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented Jan 8, 2018

[This is a duplicate of #273 but applied against the devel branch and
with a few other fixes applied]

yaml.org describes several alternative formats for timestamps not
covered by the default implementation of time.UnmarshalText(). A subset
of these is covered by this PR - future work can enable full
support for all formats.

Timestamps will only be collected if there is an explicit timestamp
tag (ie, not !!str) or if implicit type detection is enabled.

This PR builds on @anthonybishopric's foundations
(see PR #117).

abishopric and others added 2 commits January 8, 2018 15:50
yaml.org describes several alternative formats for timestamps not
covered by the default implementation of `time.UnmarshalText()`. These
are handled explicitly in this change in resolve.go

Timestamps will only be collected if there is an explicit timestamp
tag (ie, not `!!str`) or if implicit type detection is enabled.
Factor the timestamp parsing into its own function that
can easily be changed later to support the full range of
time stamps and add a quick early check to avoid
going through all the time.Parse calls in this common
path.

Also fix marshaling so that times are still printed unquoted.

For backwards compatibility, when timestamps are unmarshaled
into interface{} values, we unmarshal them as strings.

We also make it possible to unmarshal any value that implements
TextUnmarshaler, regardless of any explicit or implicit tag.
@rogpeppe rogpeppe merged commit 87e4a22 into go-yaml:devel Jan 8, 2018
@rogpeppe rogpeppe mentioned this pull request Mar 13, 2018
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