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
Virepri opened this issue Feb 24, 2019 · 3 comments

Comments

Projects
None yet
5 participants
@Virepri
Copy link

commented Feb 24, 2019

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

@gopherbot gopherbot added the Proposal label Feb 24, 2019

@Virepri Virepri 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

@Virepri Virepri 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

@Virepri Virepri 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

This comment has been minimized.

Copy link
Member

commented Feb 25, 2019

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

@robpike

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Feb 27, 2019

Agree with Rob.

@rsc rsc closed this Feb 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.