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

proposal: time: Parse time similar to fmt.Scanf and related functions #30373

Closed
Riven-Spell opened this issue Feb 24, 2019 · 3 comments
Closed

Comments

@Riven-Spell
Copy link

In reference to #29911, with being unable to require a 24-hour hour zero-padded.

Perhaps we could have time formats provided similarly to fmt.Printf()?

It'd require reworking some things, but just on a whim, how does this sound?
(_ specifies a missing digit)

%_h - _ length 12 hour zero-padded hour
%_H - _ length 24 hour zero-padded hour
%_m - _ length zero-padded minute
%_s - _ length zero-padded second

%_D - _ length zero-padded days
%_M - _ length zero-padded months
%_Y - _ length zero-padded years

now, this is where the naming convention started feeling shaky.
I figured W since it's an upside-down m, and could still say "word".
But, day, I struggled with. This is where I'd like suggestions, because C does not feel fitting at all, and was more of a placeholder if anything.

%w - 3-letter month word (Ex. Jan)
%W - full month word (Ex. January)
%c - 3-letter day word (Ex. Mon)
%C - full day word (Ex. Monday)

The missing digits could easily be optional, too. It'd allow for very flexible formatting of date and time, in comparison to what we currently have.

@gopherbot gopherbot added this to the Proposal milestone Feb 24, 2019
@Riven-Spell Riven-Spell changed the title proposal: Change how time is parsed to be more similar to fmt.Printf and related functions proposal: time: Change how time is parsed to be more similar to fmt.Printf and related functions Feb 24, 2019
@Riven-Spell Riven-Spell changed the title proposal: time: Change how time is parsed to be more similar to fmt.Printf and related functions proposal: time: Change how time is parsed to be more similar to fmt.Scanf and related functions Feb 24, 2019
@Riven-Spell Riven-Spell changed the title proposal: time: Change how time is parsed to be more similar to fmt.Scanf and related functions proposal: time: Parse time similar to fmt.Scanf and related functions Feb 24, 2019
@bcmills
Copy link
Contributor

bcmills commented Feb 25, 2019

CC @rsc for time (and @robpike and @martisch for any insights from the analogy to fmt.Printf).

@robpike
Copy link
Contributor

robpike commented Feb 25, 2019

External packages exist that recreate the behavior of C's strftime, which achieve what is asked for here. We deliberately chose to avoid that interface because of its unreadability and messiness, and are happy with that decision.

I suggest the requester use one of the community-provided packages. I also suggest giving the time package another chance: If you use the constants provided (time.UnixDate, time.Kitchen etc.) you rarely need to remember any details about how it works.

@rsc
Copy link
Contributor

rsc commented Feb 27, 2019

Agree with Rob.

@rsc rsc closed this as completed Feb 27, 2019
@golang golang locked and limited conversation to collaborators Feb 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants