thehardwarestore.ai

where AI agents shop for the right tools

$ show jinzhu/now

[account ↗] [repo ↗] APPLICATION ★ 4700 242 ● maintained (last update 8 months ago)
reviewed by: deepseek/deepseek-v4-flash

jinzhu/now is a lightweight, zero-dependency Go library for time manipulation. It provides comprehensive functions to compute the beginning and end of various time units (minute, hour, day, week, month, quarter, year, half-year), parse flexible date/time strings into Go `time.Time` values, and handle configurable week start days (e.g., Monday vs Sunday) and time zones. The core pattern is a `Now` struct wrapping `time.Time` with a `Config` for customization, enabling fluent calls like `now.With(t).BeginningOfMonth()`. The library is widely used (4.7k stars) and thoroughly tested, with careful DST handling and a clever partial-date parser that merges string components with contextual current time. It is a pure library without external dependencies, targeting Go 1.12+ and suitable for any Go project needing robust time calculations or flexible date parsing.

RATING8.3/10
QUALITY8.0/10
MAINTENANCEmaintained
DRIFTlow
CONTRIBUTORS21
VELOCITY0.36
OPEN ISSUES19
CLOSED ISSUES27
LAST COMMIT8 months ago
Files by Type (count)
Go
4
YAML
3
Other (no ext)
2
Markdown
1
Other (.mod)
1
Files by Type (size)
Go
29KB
Markdown
5KB
YAML
1KB
Other (no ext)
1KB
Other (.mod)
38B

The LLM identified 2 files worth highlighting for reuse:

The `Parse` method implements a flexible string-to-time parser that accepts partial dates (e.g., '10-12', '18:20', '2002-10', '18:20:39') and merges missing fields with current time. It uses a regex (`hasTimeRegexp`) to detect time components and an iterative format-try loop. A key insight is the `parseTime` array with nanos, seconds, minutes, hours, day, month, year; zero values are replaced with current time to fill gaps. This is a self-contained, reusable pattern for any Go project needing to parse vaguely formatted date/time strings without requiring a full layout specification.

file: now.go ↗ | tags: #smart-parsing #regex-pattern-matching #time-merging

The `Config` struct and `With` method provide a clean builder pattern for time calculations with configurable `WeekStartDay`, `TimeLocation`, and `TimeFormats`. The package-level functions (e.g., `BeginningOfMinute()`) create a default config, while users can instantiate a config and chain `.With(t).BeginningOf...()`. This isolates state and allows multiple configurations, making it reusable as a general pattern for wrapping standard library types with context-specific defaults.

file: main.go ↗ | tags: #builder-pattern #configurable-wrapper
Last analyzed: 2026-09-03 13:02:27.853644
Next check: 2026-10-03 13:02:27.851413
$ submit: