Get the first or last second of the current month to build date-range filters for database queries.
Find the start of the current week with a configurable weekday (Sunday or Monday).
Parse partial date strings like '2024' or '2024-03' into full timestamps to handle user date input.
Calculate time period boundaries for analytics dashboards or scheduled reports in Go.
Now is a small Go library for working with dates and times. Its main purpose is to make it easy to find the start or end of a time period relative to any given moment. Instead of calculating these boundaries by hand, a developer calls a single function and gets back the exact timestamp they need. The library answers questions like: what was the first moment of this day, week, month, quarter, or year, and what was the last moment of each? It works either from the current time or from any arbitrary time you supply. For week calculations, the start day defaults to Sunday but can be changed to Monday or any other day through a configuration setting. It also includes a flexible string parser that converts partial date strings into full timestamps. Passing in just a year returns the first second of that year, passing in a year and month returns the first second of that month, and passing in just a time like "14" returns that hour on the current day. The parser handles a range of common formats and can be extended with custom formats by adding to its list. The library is written by the same author as GORM, a widely used Go database library, and follows the same style of small, focused utility code. Adding it to a Go project is a one-line install command, and the API is a thin wrapper around Go's standard time package rather than a replacement for it. The README is brief and consists almost entirely of code examples showing inputs and outputs. The library is released under the MIT license.
← jinzhu on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.