explaingit

jinzhu/now

4,687GoAudience · developerComplexity · 1/5LicenseSetup · easy

TLDR

A tiny Go library that makes it easy to get the start or end of any time period, day, week, month, quarter, or year, from any given moment, plus a flexible parser for partial date strings.

Mindmap

mindmap
  root((now))
    What it does
      Time period boundaries
      Date string parsing
    Time periods
      Day start and end
      Week with config
      Month quarter year
    Features
      Custom week start day
      Custom parse formats
    Use cases
      Date range queries
      Reports and analytics
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Get the first or last second of the current month to build date-range filters for database queries.

USE CASE 2

Find the start of the current week with a configurable weekday (Sunday or Monday).

USE CASE 3

Parse partial date strings like '2024' or '2024-03' into full timestamps to handle user date input.

USE CASE 4

Calculate time period boundaries for analytics dashboards or scheduled reports in Go.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
Using the jinzhu/now Go library, write a function that returns all database records from the current month by computing the start and end timestamps.
Prompt 2
Show me how to configure jinzhu/now to treat Monday as the start of the week instead of Sunday.
Prompt 3
How do I use jinzhu/now to parse a partial date string like '2024-03' into a full time.Time value in Go?
Prompt 4
Write a Go function using jinzhu/now that returns the first and last second of the current quarter.
Open on GitHub → Explain another repo

← jinzhu on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.