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

time: ISO 8601 template const #36650

Closed
rbUUbr opened this issue Jan 20, 2020 · 11 comments
Closed

time: ISO 8601 template const #36650

rbUUbr opened this issue Jan 20, 2020 · 11 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rbUUbr
Copy link
Contributor

rbUUbr commented Jan 20, 2020

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

$ go version
1.12.9

Does this issue reproduce with the latest release?

yes

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

Mac OS, catalina

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/userx/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/userx/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/userx/myproject/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0z/xvrbhgwn6vx8kfhcgn60bzvw0000gn/T/go-build050042786=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Parsing date to time object in GoLang
https://play.golang.org/p/dWcJIGo9K7g

What did you expect to see?

Any predefined const for date in ISO 8601 format

What did you see instead?

I see no predefined const for date objects, only for datetime

I think, it is important to add it, because it's pretty common case when you have just date without time in ISO 8601 format

@ALTree
Copy link
Member

ALTree commented Jan 20, 2020

You don't need a predefined constant to parse that date, just write

d, err := time.Parse("2006-01-02", "2020-01-02")

For such a short format, I'm not sure a pre-defined constant would be very useful.

@rbUUbr
Copy link
Contributor Author

rbUUbr commented Jan 20, 2020

@ALTree
Yes, I do something like this, but it's very strange when we have const for ISO 8601 format for DateTime, but don't have such const for Date type. WDYT? I think, it's pretty common case to resolve and it can be good to add predefined template const

@ianlancetaylor
Copy link
Contributor

I'm not sure what the exact suggestion is. ISO 8601 defines several different formats: date, time, combined date and time, duration, interval, repeating interval, etc. What precisely do you think we should do?

@rbUUbr
Copy link
Contributor Author

rbUUbr commented Jan 20, 2020

I often need to parse date (for example: "2019-12-12") to ISO 8601 format. It's pretty unclear for me, why should I define template for it everywhere or create some util function to do this. I think, it will be good to add const that define template for dates in ISO 8601, just for date. WDYT about it?

@ianlancetaylor
Copy link
Contributor

Why should we add a constant just for ISO 8601 dates, and not for any other aspect of ISO 8601?

@rbUUbr
Copy link
Contributor Author

rbUUbr commented Jan 21, 2020

I think, it's pretty more common case to parse date, not interval. Anyway, it also can be good to add consts for all aspects

@beoran
Copy link

beoran commented Jan 21, 2020

https://github.com/beoran/iso8601/blob/master/iso8601.go perhaps?

However, I noticed that there seems to be no support in the time package for ISO8601 week dates such as 2006-W23, 2006-W23D1 or day dates 2000-234. In particular the week numbers are useful for certain types of planning software.

@rbUUbr
Copy link
Contributor Author

rbUUbr commented Jan 21, 2020

@beoran thanks, interesting, but here the main sense is to add it to stdlib like it's made in Ruby. it gives a possibility to not load some additional modules just for a 1 const.

@beoran
Copy link

beoran commented Jan 21, 2020

As @ianlancetaylor said there's more to this topic than just adding 1 or 2 constants to the 'time' package. Currently, the time package lacks several features to be ISO8601 compatible, and if they add the constants, that would not be sufficient for real ISO8601 support. A separate package may be the best way to get started on designing what this functionality should be.

@rbUUbr
Copy link
Contributor Author

rbUUbr commented Jan 21, 2020

ok then, can we can discuss here some structure of separate package for date? and need for this package at all? @ianlancetaylor @beoran

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 21, 2020
@toothrot toothrot changed the title ISO 8601 template const time: ISO 8601 template const Jan 21, 2020
@toothrot toothrot modified the milestones: Backlog, Unplanned Jan 21, 2020
@ALTree
Copy link
Member

ALTree commented Feb 3, 2020

@rbUUbr such package should be a third-party package, I don't think anyone was proposing it for inclusion in the standard library. For this reason, this is probably not the right place to discuss it.

Reading the discussion above, it seems that we are not going to add just a "2006-01-02" constant for ISO 8601 dates in the time package, and providing a bunch of constants for every aspect of ISO 8601 is something that should be implemented as an external package, so I think we can close this issue.

@ALTree ALTree closed this as completed Feb 3, 2020
@golang golang locked and limited conversation to collaborators Feb 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants