Created
August 1, 2023 19:26
-
-
Save andrw/04d46195c971289f634f14ef8a48dd1f to your computer and use it in GitHub Desktop.
is first day of month with go time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func isFirstDayOfMonth(someRuntime time.Time) bool { | |
| currentYear, currentMonth, _ := time.Now().Date() | |
| currentLocation := time.Now().Location() | |
| firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation) | |
| secondOfMonth := firstOfMonth.Add(24* time.Hour) // multiple ways to get here... | |
| // within first day | |
| if someRuntime.After(firstOfMonth) && someRuntime.Before(secondOfMonth) { | |
| return true | |
| } | |
| return false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment