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: Reliable way to obtain start, end days of a month #31142

Closed
mcandre opened this issue Mar 29, 2019 · 3 comments
Closed

time: Reliable way to obtain start, end days of a month #31142

mcandre opened this issue Mar 29, 2019 · 3 comments
Labels
FeatureRequest FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@mcandre
Copy link

mcandre commented Mar 29, 2019

Hey, I noticed that the stdlib time package does not offer direct, reliable methods for obtaining the start and end days of a timestamp's month. There are a number of Stack Overflow suggestions, as well as a (reportedly inaccurate) third party package for this.

Would be good to have a standard method to call for this common use case, rather than relying on the community to get complex date and time rules right.

@dmitshur dmitshur changed the title Reliable way to obtain start, end days of a month time: Reliable way to obtain start, end days of a month Mar 29, 2019
@ianlancetaylor
Copy link
Contributor

The first day of a month seems straightforward:

    monthStart := time.Date(d.Year(), d.Month(), 1, 0, 0, 0, 0, d.Location())

and the last day of the month is only slightly more complicated:

    monthEnd := time.Date(d.Year(), d.Month() + 1, 0, 0, 0, 0, 0, d.Location())

@agnivade
Copy link
Contributor

agnivade commented Apr 2, 2019

@mcandre - Does this suffice your needs or you would still prefer to have a helper for this ? IMO, this method just leverages the standard date normalization behavior and lets users get their desired output.

If you would like this to be added in standard library, some usages of this in the real world will be helpful for us to make a decision. We would need to understand why such a helper needs to be in the standard library and not exist as a third party package.

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 2, 2019
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants