Skip to content

time: add the ability to parse yearDay #25689

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

Closed
bantl23 opened this issue Jun 1, 2018 · 13 comments
Closed

time: add the ability to parse yearDay #25689

bantl23 opened this issue Jun 1, 2018 · 13 comments
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. FeatureRequest Issues asking for a new feature that does not need a proposal. FrozenDueToAge help wanted Proposal Proposal-Accepted
Milestone

Comments

@bantl23
Copy link

bantl23 commented Jun 1, 2018

Consider adding in the ability to parse yearDay in time.parse.

Currently there is no way to parse a time with a yearDay value. Consider adding the ability to into the time.parse function.

YYYY = 4 digit year
MM = 2 digit month
DD = 2 digit day
HH = 2 digit hour
MM = 2 digit minute
SS = 2 digit second
DOY = 3 digit yearday

2006-01-02 15:04:05 which can parse YYYY-MM-DD HH:MM:SS

Consider adding in something like this

2006-888 15:04:05 which would be able to parse YYYY-DOY HH:MM:SS

What version of Go are you using (go version)?

go version go1.10.2 linux/amd64

Does this issue reproduce with the latest release?

Feature Request

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vagrant/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/vagrant/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build508236003=/tmp/go-build -gno-record-gcc-switches"

What did you do?

N/A

What did you expect to see?

N/A

What did you see instead?

N/A

@ianlancetaylor ianlancetaylor changed the title Add the ability to parse yearDay time: add the ability to parse yearDay Jun 1, 2018
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. FeatureRequest Issues asking for a new feature that does not need a proposal. labels Jun 1, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jun 1, 2018
@meirf
Copy link
Contributor

meirf commented Jun 2, 2018

Is there any standard (for example any RFC) which specifies a day of year? I couldn't find any.

time.Parse:

Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard and convenient representations of the reference time.

See the emphasis on RFCs in the time constants.

Based on your analysis that it would be the only 3 digit standard, it certainly would be possible and not too hard to parse day of year, but if it's not a standard then it would rarely be used and would needlessly complicate the time code.

@deanveloper
Copy link

deanveloper commented Jun 3, 2018

This is the closest thing I could find to some kind of "standard": https://cals.arizona.edu/azmet/doy.htm

edit: note that this is not a date format. DOY really is nonstandard and (imo) should need to be manually implemented by the programmer

@ulikunitz
Copy link
Contributor

ulikunitz commented Jun 3, 2018

ISO 8601 calls the format ordinal dates. It is reflected in the Appendix A ISO 8601 Collected ABNF of RFC3339 as datespec-yday.

The format may not be widely used, but it is a date format in the relevant international standard ISO 8601.

@meirf
Copy link
Contributor

meirf commented Jun 4, 2018

... if it's not a standard then it would rarely be used...

(I take back this causality comment. I think standardization/usage are orthogonal.)

@meirf
Copy link
Contributor

meirf commented Jun 4, 2018

/cc @rsc

@bantl23
Copy link
Author

bantl23 commented Jun 4, 2018

While there is a reference to yearDay in both ISO 8601 and RFC3339 as @ulikunitz stated, the original reason for requesting this feature has to do with yearDay pervasiveness in the space industry. Parsing of yearDay is lacking in the time package and I thought that would be something that might be needed/useful as this is built-in in other modern languages.

@ianlancetaylor
Copy link
Member

I'm going to turn this into a proposal. The proposal is that time.Parse recognize 888 as matching the day of the year. The number would be parsed and used as a day offset from the start of the year.

Presumably it would also work in time.Time.Format, where it would print time.Time.YearDay().

@ianlancetaylor ianlancetaylor changed the title time: add the ability to parse yearDay proposal: time: add the ability to parse yearDay Jun 4, 2018
@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Proposal Jun 4, 2018
@ianlancetaylor ianlancetaylor removed FeatureRequest Issues asking for a new feature that does not need a proposal. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 4, 2018
@rsc
Copy link
Contributor

rsc commented Jun 4, 2018

/cc @robpike

@robpike
Copy link
Contributor

robpike commented Jun 4, 2018

Ugh. But maybe.

@rsc
Copy link
Contributor

rsc commented Jun 5, 2018

I'm not sure this has to happen at all. But if it does, I don't see why it has to be 888. Seems like 002 is fine.

@ianlancetaylor
Copy link
Member

Using 002 would change the output of more-or-less meaningful date formats like Jan 002 which currently print a three digit day-of-month. While I don't know why someone would do that it doesn't seem impossible. Using 888 in a current date string seems less likely.

@rsc
Copy link
Contributor

rsc commented Jul 10, 2018

@robpike and I discussed this and agreed to try 002 early in the Go 1.12 cycle. I'll send a CL shortly. After adding this to Format and Parse the obvious hole in the API is some way to take a year+yday and turn it into a year/month/day, short of preparing a string and calling Parse.

@rsc rsc changed the title proposal: time: add the ability to parse yearDay time: add the ability to parse yearDay Jul 10, 2018
@rsc rsc modified the milestones: Proposal, Go1.12 Jul 10, 2018
@rsc rsc added the early-in-cycle A change that should be done early in the 3 month dev cycle. label Jul 10, 2018
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/122876 mentions this issue: time: add support for day-of-year in Format and Parse

@bradfitz bradfitz modified the milestones: Go1.12, Go1.13 Nov 3, 2018
@bradfitz bradfitz added help wanted FeatureRequest Issues asking for a new feature that does not need a proposal. labels Nov 3, 2018
@golang golang locked and limited conversation to collaborators Mar 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. FeatureRequest Issues asking for a new feature that does not need a proposal. FrozenDueToAge help wanted Proposal Proposal-Accepted
Projects
None yet
Development

No branches or pull requests

9 participants