aeon

package module
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 7 Imported by: 0

README

I can't recall the exact moment it began. Perhaps it stemmed from a dissatisfaction with time.Time and existing time libraries—I developed a near-absurd obsession: Why not write a Go time library myself?

In ancient philosophy, Aeon represents "eternity" and "layered dimensions."

I chose this name because I want to express a different logic of time—time is not a slender straight line; it is a flowing universe that can be nested and penetrated.

Aeon

zread

🇨🇳 中文 | 🇺🇸 English

Aeon is a Zero-Allocation time navigation library for Go based on Time Container theory. It replaces linear calculation with structured navigation, expressing complex time intentions in a way that aligns with human intuition.

🚀 Performance: A Dimensional Blow

Aeon achieves True Zero Allocation (Zero Alloc) and leverages a Cascading Addressing architecture. Whether you span multiple dimensions (from Millennium to Nanosecond), Aeon completes the operation in a single atomic step. The more complex the logic, the more staggering Aeon's lead becomes.

[!NOTE] The following baseline data were obtained under single-atom operations without using cascade parameters.

Benchmark       | ns/op | allocs/op x B/op | up

New             |
Aeon            | 18.6 | 0 | x74
Carbon          | ████████████████████████████████████████ 1376 | 13x1600

Now             |
Aeon            | 7.8 | 0 | x177
Carbon          | ████████████████████████████████████████ 1384 | 13x1600

From Unix       |
Aeon            | 3.6 | 0 | x383
Carbon          | ████████████████████████████████████████ 1380 | 13x1600

From Std        |
Aeon            | 5.0 | 0 | x323
Carbon          | ████████████████████████████████████████ 1619 | 13x1600

Parse (Compact) |
Aeon            | 23.3 | 0 | x195
Carbon          | ████████████████████████████████████████ 4561 | 85x3922

Parse (ISO)     |
Aeon            | 19.6 | 0 | x91
Carbon          | ████████████████████████████████████████ 1794 | 15x1697

Start/End       |
Aeon            | █ 56.4 | 0 | x20
Carbon          | ████████████████████ 1141 | 7x1440

Add (Offset)    |
Aeon            | █ 56.5 | 0 | x2.5
Carbon          | ██ 142 | 2x128

Set (Position)  |
Aeon            | █ 58.7 | 0 | x2.6
Carbon          | ███ 156 | 2x128

📦 Installation

go get github.com/baagod/aeon

🧊 Core Concept: Containers

The core of Aeon is Container Offset. All navigation is essentially indexing within the Parent Container of the current unit (starting from 0). For example:

  • GoYear(5): Not going to the year 5 AD, but indexing to the 5th year within the current Decade (the parent container) ➜ ···5.
  • GoDecade(2): Indexing to the 2nd Decade of the current Century··2·.
  • GoCentury(0): Indexing to the 0th Century of the current Millennium·0··.
[Millennium]
  └─ [0...9 Century]
       └─ [0...9 Decade]
            └─ [0...9 Year]
                 └─ [1...12 Month]

Example: GoYear(5) Addressing Logic
         [-9]       [-8]            [-5]        [-4]             [-1]
2020 ─┬─ 2021 ──┬── 2022 ··· ──┬── [2025] ──┬── 2026 ─┬─ ··· ─┬─ 2029
[0]      [1]        [2]             [5]         [6]              [9]

🧭 Navigation Matrix

Aeon's API design is completely Orthogonal. You only need to remember 4 Actions:

  • Go.. [·] Absolute Positioning: GoYear(5, 1) ➜ 5th Year, 1st Month of current decade.
  • By.. [➜] Relative Offset: ByYear(1, 5) ➜ Offset by 1 Year and 5 Months.
  • At.. [·, ➜] Position then Offset: AtYear(5, 1) ➜ Locate 5th Year, then offset 1 Month.
  • In.. [➜, ·] Offset then Position: InYear(1, 5) ➜ Next Year (Offset 1), then 5th Month.

[!IMPORTANT]

  1. By methods default to 1. Others default to 0.
  2. Invalid 0 time (e.g., 0th Month) remains unchanged in Positioning Mode (but works in Offset mode).
  3. Go positions only the target unit and preserves original time details as much as possible** (e.g., GoWeek automatically retains the weekday).
t := Parse("2021-07-21 07:14:15") // Wed
t.GoMonth(1)  // 2021-01-21 07:14:15 (Set to Jan, time preserved)
t.GoWeek(1)   // 2021-06-30 07:14:15 (1st Week, Weekday preserved as Wed)

Combined with Start/End prefixes to hit time boundaries:

  • StartYear(): Start of this year (01-01 00:00:00...)
  • EndYear(): End of this year (12-31 23:59:59...)

6 Top-Level methods allow the first parameter to enter Absolute Year mode:

  1. Go(2025, 2) ➜ 2025-02
  2. At(2025, 2) ➜ Position at 2025, then offset 2 months.
  3. Start(2025, 2) ➜ 2025-02-01 00:00:00
  4. StartAt(2025, 1) ➜ Position at 2025, offset 1 month, then Start of Month.
  5. End(2025, 2) ➜ 2025-02-28 23:59:59...
  6. EndAt(2025, 1) ➜ Position at 2025, offset 1 month, then End of Month.

♾️ Cascading Parameters

Method chaining? No, this is Atomic Operation! All methods support Variadic Parameters that cascade downwards. Parameters flow like water, completing complex positioning in one line of code.

Aeon automatically switches between 4 cascading sequences based on the Entry Unit:

  1. Year Sequence Default: Century ➜ Decade ➜ Year ➜ Month ➜ Day ➜ Hour.. ➜ Nanosecond

  2. Quarter Flow Quarter: Quarter ➜ Month (in Quarter) ➜ Day ➜ Hour.. ➜ Nanosecond

  3. Week Sequence Week🦬: Week (Smart Context) ➜ Weekday ➜ Hour.. ➜ Nanosecond

    This is a Transformer! It automatically shifts shape based on the passed Flags:

    • ISO: ISO Week. Starts from the 1st ISO week of the year.
    • Full: Full Week. Starts from the 1st Monday of the month.
    • Ord: Ordinal Week. Starts from the 1st day of the month.
    • Qtr: Quarter Week. Starts from the 1st day of the quarter's first month.
    • Default: Calendar/Natural Week. Follows the calendar visual row.
  4. Weekday Flow Weekday: Weekday ➜ Hour.. ➜ Nanosecond

// Relative offset: 1 Year, 3 Months, 5 Days
ByYear(1, 3, 5)

// 2nd Tuesday of the current Quarter
GoWeek(aeon.Qtr|aeon.Ord, 2, 2)

// Last Friday of the current Quarter
GoWeek(aeon.Qtr|aeon.Ord, -1, 5)

// 2025, Feb, Last Day, 23:00
Go(2025).StartMonth(2, -1, 23)

// End of the 3rd Quarter, minus 1 month, minus 2 days
EndQuarter(3, -1, -2)

// 10th ISO Monday of 2025
Go(2025).StartWeek(aeon.ISO, 10, 1)

// 3rd Friday of this month (Ordinal week starting from 1st)
StartWeek(aeon.Ord, 3, 5)

// Last Friday of this month
GoWeek(aeon.Ord, -1, 5)

// End of previous Quarter
EndByQuarter(-1)

// 1st day of the last month of this Quarter
StartQuarter(0, -1, 1)

// This Friday at 18:00 (Happy Hour)
StartWeekday(5, 18)

// 3rd to last day of this month
StartDay(-3)

// Next Wednesday at 2 PM
StartInWeek(1, 3, 14)

// Yearly Archive: Start/End boundaries
StartYear() / EndYear()

// Last day of next month
EndInMonth(1, -1)

Negative numbers are not just subtraction; they are Reverse Indexing, representing the "N-th from last" item in the container.

🛡️ Overflow Protection

Aeon's core philosophy is Intention First. By default, navigation protects against day overflow for units "Month and above".

base := NewDate(2025, 1, 31)
base.GoMonth(2) // 2025-02-28 (Protected)
base.ByMonth(Overflow, 1) // 2025-03-03 (Overflow allowed)
base.ByMonth(1, 2) // 🛡️🦬 2025-03-02 (Protect to 2-28, then add 2 days)

// Leap Year Handling
leap := NewDate(2024, 2, 29)
leap.ByYear(1) // 2025-02-28 (Protected)
leap.ByYear(Overflow, 1) // 2025-03-01 (Overflow: Crosses month boundary)
leap.ByYear(4)           // 2028-02-29 (Next Leap Year)

🧰 Core API

Create Time
// Create time from optional time.Time(s)
Aeon(t ...time.Time) Time

// Create current time with optional location
Now(loc ...*time.Location) Time

// Precisely create time (y, m, d, h, mm, s), with optional nanosecond/location
New(y, m, d, h, mm, int, add ...any) Time

// Create from timestamp (auto-detects second/milli/micro/nano)
Unix(int64, ...*time.Location) Time

// Parse time string (ignores error)
Parse(string, ...*time.Location) Time

// Parse time string (returns error)
ParseE(string, ...*time.Location) (Time, error)

// Parse with layout (ignores error)
ParseBy(layout, value string, loc ...*time.Location) Time

// Parse with layout (returns error)
ParseByE(layout, value string, loc ...*time.Location) (Time, error)
Get Time
t.Year() int                       // Year
t.Month() int                      // Month (1-12)
t.Day() int                        // Day (1-31)
t.Hour() int                       // Hour (0-23)
t.Minute() int                     // Minute (0-59)
t.Second() int                     // Second (0-59)
t.Milli() int                      // Millisecond (0-999)
t.Micro() int                      // Microsecond (0-999999)
t.Nano() int                       // Nanosecond (0-999999999)
t.Clock() (h, mm, s int)           // Hour, Minute, Second
t.Weekday() time.Weekday           // Weekday
t.ISOWeek() (year, week int)       // ISO Week
t.YearDay() int                    // Day of Year (1-365/366)
t.YearDays() int                   // Total Days in Year
t.Days() int                       // Total Days in Month
t.Unix(n ...int) int64             // Timestamp, n specifies precision
t.Time() time.Time                 // Convert to Std Lib
t.Location() *time.Location        // Location
t.Zone() (name string, offset int) // Zone Name and Offset (Seconds)
Compare & Judge
t.Lt(u Time) bool          // t < u
t.Gt(u Time) bool          // t > u
t.Eq(u Time) bool          // t == u
t.Compare(u Time) int      // -1 / 0 / 1

t.IsSame(u Unit, target Time) bool        // Check if same unit (Year/Month/Day etc.)
t.Between(start, end Time, bound ...byte) bool  // Check if within interval
// bound: '=' inclusive, '!' exclusive, '[' left inclusive, ']' right inclusive

t.Diff(u Time, unit string, abs ...bool) float64
// unit: "y"Year, "M"Month, "d"Day, "h"Hour, "m"Minute, "s"Second
// abs: true returns absolute value

t.Sub(u Time) time.Duration  // t - u
t.Until() time.Duration      // t - Now()
Extremum Selection
Pick(op byte, times ...Time) Time
// op: '>' Max, '<' Min, '-' Near, '+' Far
Zone Conversion
t.UTC() Time                         // UTC Time
t.Local() Time                       // Local Time
t.To(loc *time.Location) Time        // Specific Location
t.WithWeekStarts(w time.Weekday) Time // Set Week Start Day
Utility Functions
IsLeapYear(y int) bool      // Is Leap Year
IsLongYear(y int) bool      // Is ISO Long Year (53 Weeks)
DaysIn(y int, m ...int) int // Days in y Year m Month, returns year days if m omitted

t.IsLeapYear() bool   // Is Leap Year
t.IsLongYear() bool   // Is ISO Long Year
t.IsWeekend() bool    // Is Weekend
t.IsAM() bool         // Is AM
t.IsDST() bool        // Is DST
t.IsZero() bool       // Is Zero
t.ZeroOr(u Time) Time // Return u if Zero
Formatting
t.String() string                 // Default Format
t.Format(layout string) string    // Custom Format
t.ToString(f ...string) string    // Custom Format (Short)
t.AppendFormat(b []byte, layout string) []byte
Time Zones
// Constant Zones (70+ IANA Zones)
const (
    UTC, Local, CET, EET, EST, GMT, MET, MST, WET
    Shanghai, Tokyo, NewYork, London, Paris, Berlin, Moscow
    // ...
)

// Return Zone by name and offset
Zone(string, ...int) *time.Location

Documentation

Index

Constants

View Source
const (
	ISO  = flagSign | (1 << 0) // ISO 周标志
	Ord  = flagSign | (1 << 1) // Ord 周标志
	Full = flagSign | (1 << 2) // Full 周标志

	// Overflow 允许月份溢出标志
	Overflow = flagSign | (1 << 3)
	// ABS 绝对时间标志 (内部使用)
	ABS = flagSign | (1 << 4)
	// Qtr 季度周标志 (基于季度索引)
	Qtr = flagSign | (1 << 5)
)
View Source
const (
	Local = "Local" // 本地时间
	UTC   = "UTC"   // 协调世界时间

	CET = "CET" // 中欧标准时间
	EET = "EET" // 东欧标准时间
	EST = "EST" // 东部标准时间
	GMT = "GMT" // 格林尼治标准时间
	MET = "MET" // 中欧时间
	MST = "MST" // 山地标准时间
	WET = "WET" // 西欧标准时间

	Cuba      = "Cuba"      // 古巴
	Egypt     = "Egypt"     // 埃及
	Eire      = "Eire"      // 爱尔兰
	Greenwich = "Greenwich" // 格林尼治
	Iceland   = "Iceland"   // 冰岛
	Iran      = "Iran"      // 伊朗
	Israel    = "Israel"    // 以色列
	Jamaica   = "Jamaica"   // 牙买加
	Japan     = "Japan"     // 日本
	Libya     = "Libya"     // 利比亚
	Poland    = "Poland"    // 波兰
	Portugal  = "Portugal"  // 葡萄牙
	PRC       = "PRC"       // 中国
	Singapore = "Singapore" // 新加坡
	Turkey    = "Turkey"    // 土耳其

	Shanghai   = "Asia/Shanghai"       // 上海
	Chongqing  = "Asia/Chongqing"      // 重庆
	Harbin     = "Asia/Harbin"         // 哈尔滨
	Urumqi     = "Asia/Urumqi"         // 乌鲁木齐
	HongKong   = "Asia/Hong_Kong"      // 香港
	Macao      = "Asia/Macao"          // 澳门
	Taipei     = "Asia/Taipei"         // 台北
	Tokyo      = "Asia/Tokyo"          // 东京
	HoChiMinh  = "Asia/Ho_Chi_Minh"    // 胡志明市
	Hanoi      = "Asia/Hanoi"          // 河内
	Saigon     = "Asia/Saigon"         // 西贡 (胡志明市)
	Seoul      = "Asia/Seoul"          // 首尔
	Pyongyang  = "Asia/Pyongyang"      // 平壤
	Bangkok    = "Asia/Bangkok"        // 曼谷
	Dubai      = "Asia/Dubai"          // 迪拜
	Qatar      = "Asia/Qatar"          // 卡塔尔
	Bangalore  = "Asia/Bangalore"      // 班加罗尔
	Kolkata    = "Asia/Kolkata"        // 加尔各答
	Mumbai     = "Asia/Mumbai"         // 孟买
	MexicoCity = "America/Mexico_City" // 墨西哥城
	NewYork    = "America/New_York"    // 纽约
	LosAngeles = "America/Los_Angeles" // 洛杉矶
	Chicago    = "America/Chicago"     // 芝加哥
	SaoPaulo   = "America/Sao_Paulo"   // 圣保罗
	Moscow     = "Europe/Moscow"       // 莫斯科
	London     = "Europe/London"       // 伦敦
	Berlin     = "Europe/Berlin"       // 柏林
	Paris      = "Europe/Paris"        // 巴黎
	Rome       = "Europe/Rome"         // 罗马
	Sydney     = "Australia/Sydney"    // 悉尼
	Melbourne  = "Australia/Melbourne" // 墨尔本
	Darwin     = "Australia/Darwin"    // 达尔文
)

时区名称常量定义 (IANA 标准)

View Source
const (
	DT      = "2006-01-02 15:04:05"
	DTMilli = "2006-01-02 15:04:05.000"
	DTMicro = "2006-01-02 15:04:05.000000"
	DTNano  = "2006-01-02 15:04:05.000000000"
	DTNs    = "2006-01-02 15:04:05.999999999"
)

Variables

View Source
var (
	// DefaultWeekStarts 全局默认周起始日(默认为周一)
	DefaultWeekStarts = time.Monday
	// DefaultTimeZone Parse() 使用的默认时区
	DefaultTimeZone = time.Local
)

Functions

func DaysIn

func DaysIn(y int, m ...int) int

DaysIn 返回 y 年 m 月最大天数,如果忽略 m 则返回 y 年总天数。

  • 1, 3, 5, 7, 8, 10, 12 月有 31 天;4, 6, 9, 11 月有 30 天。
  • 平年 2 月有 28 天,闰年 29 天。

func IsLeapYear

func IsLeapYear(y int) bool

IsLeapYear 返回 y 是否闰年

func IsLongYear

func IsLongYear(y int) bool

IsLongYear 返回当前年份是否为 ISO 8601 规定的 “长年”(包含 53 周)。

func Zone added in v0.0.8

func Zone(name string, offset ...int) *time.Location

Zone 返回指定名称和偏移量的时区

Types

type Action added in v0.0.6

type Action int

type DateTimeMilli

type DateTimeMilli = F[formatDateTimeMilli]

type F

type F[T Formatter] struct {
	Time
	// contains filtered or unexported fields
}

func (F[T]) MarshalJSON

func (f F[T]) MarshalJSON() ([]byte, error)

func (F[T]) MarshalText

func (f F[T]) MarshalText() ([]byte, error)

func (*F[T]) Scan

func (f *F[T]) Scan(value any) (err error)

func (*F[T]) UnmarshalJSON

func (f *F[T]) UnmarshalJSON(b []byte) (err error)

func (*F[T]) UnmarshalText

func (f *F[T]) UnmarshalText(data []byte) error

func (F[T]) Value

func (f F[T]) Value() (driver.Value, error)

type Flag

type Flag struct {
	// contains filtered or unexported fields
}

Flag 承载级联操作的上下文配置

type Formatter

type Formatter interface {
	Layout() string
}

type Time

type Time struct {
	// contains filtered or unexported fields
}

func Aeon

func Aeon(t ...time.Time) Time

func New

func New(y, m, d, h, mm, s int, add ...any) Time

func Now

func Now(loc ...*time.Location) Time

func Parse

func Parse(value string, loc ...*time.Location) Time

Parse 解析时间字符串,忽略错误

func ParseBy

func ParseBy(layout string, value string, loc ...*time.Location) Time

ParseBy 指定布局解析,忽略错误

func ParseByE

func ParseByE(layout string, value string, loc ...*time.Location) (Time, error)

ParseByE 指定布局解析,返回 Time 和 error

func ParseE

func ParseE(s string, loc ...*time.Location) (Time, error)

ParseE 解析时间字符串,返回 Time 和 error

func Pick added in v0.0.3

func Pick(op byte, times ...Time) Time

Pick 从时间集合中挑选出一个满足特定条件的极值。

op 操作符:

  • '>' : 最大值 (Max / Latest) - 所有参数平等
  • '<' : 最小值 (Min / Earliest) - 所有参数平等
  • '+' : 最远 (Far / Max Distance) - times[0] 为参考点,返回 times[1:] 中离它最远的。
  • '-' : 最近 (Near / Min Distance) - times[0] 为参考点,返回 times[1:] 中离它最近的。

func Unix

func Unix(secs int64, loc ...*time.Location) Time

Unix 返回给定时间戳的时间。secs 可以是秒、毫秒、微妙或纳秒级时间戳。

func (Time) AppendFormat

func (t Time) AppendFormat(b []byte, layout string) []byte

func (Time) At

func (t Time) At(n ...int) Time

func (Time) AtCentury

func (t Time) AtCentury(n ...int) Time

func (Time) AtDay

func (t Time) AtDay(n ...int) Time

func (Time) AtDecade

func (t Time) AtDecade(n ...int) Time

func (Time) AtHour

func (t Time) AtHour(n ...int) Time

func (Time) AtMicro

func (t Time) AtMicro(n ...int) Time

func (Time) AtMilli

func (t Time) AtMilli(n ...int) Time

func (Time) AtMinute

func (t Time) AtMinute(n ...int) Time

func (Time) AtMonth

func (t Time) AtMonth(n ...int) Time

func (Time) AtNano

func (t Time) AtNano(n ...int) Time

func (Time) AtQuarter

func (t Time) AtQuarter(n ...int) Time

func (Time) AtSecond

func (t Time) AtSecond(n ...int) Time

func (Time) AtWeek

func (t Time) AtWeek(n ...int) Time

func (Time) AtWeekday

func (t Time) AtWeekday(n ...int) Time

func (Time) AtYear

func (t Time) AtYear(n ...int) Time

func (Time) Between

func (t Time) Between(start, end Time, bound ...byte) bool

Between 判断 t 是否在 (start, end) 区间内。

可选参数 bound 用于控制边界包含性 (默认为 "="):

  • '=' : 包含边界
  • '!' : 不包含边界
  • '[' : 包含左边界
  • ']' : 包含右边界

func (Time) By

func (t Time) By(d time.Duration) Time

func (Time) ByCentury

func (t Time) ByCentury(n ...int) Time

func (Time) ByDay

func (t Time) ByDay(n ...int) Time

func (Time) ByDecade

func (t Time) ByDecade(n ...int) Time

func (Time) ByHour

func (t Time) ByHour(n ...int) Time

func (Time) ByMicro

func (t Time) ByMicro(n ...int) Time

func (Time) ByMilli

func (t Time) ByMilli(n ...int) Time

func (Time) ByMinute

func (t Time) ByMinute(n ...int) Time

func (Time) ByMonth

func (t Time) ByMonth(n ...int) Time

func (Time) ByNano

func (t Time) ByNano(n ...int) Time

func (Time) ByQuarter

func (t Time) ByQuarter(n ...int) Time

func (Time) BySecond

func (t Time) BySecond(n ...int) Time

func (Time) ByWeek

func (t Time) ByWeek(n ...int) Time

func (Time) ByYear

func (t Time) ByYear(n ...int) Time

func (Time) Clock

func (t Time) Clock() (h, mm, s int)

func (Time) Compare

func (t Time) Compare(u Time) int

Compare 比较 t 和 u。

如果 t == u,返回 0;t > u 返回 1;t < u 返回 -1。

func (Time) Date

func (t Time) Date() (int, int, int)

Date 返回 t 的年月日

func (Time) Day

func (t Time) Day() int

func (Time) Days

func (t Time) Days() int

func (Time) Diff

func (t Time) Diff(u Time, unit string, abs ...bool) float64

Diff 返回 t 和 u 的时间差。

参数:

  • unit: 比较单位 ("y"年, "M"月, "d"日, "h"时, "m"分, "s"秒)
  • abs: 可选,为 true 时返回绝对值

func (Time) End

func (t Time) End(n ...int) Time

func (Time) EndAt

func (t Time) EndAt(n ...int) Time

func (Time) EndAtCentury

func (t Time) EndAtCentury(n ...int) Time

func (Time) EndAtDay

func (t Time) EndAtDay(n ...int) Time

func (Time) EndAtDecade

func (t Time) EndAtDecade(n ...int) Time

func (Time) EndAtHour

func (t Time) EndAtHour(n ...int) Time

func (Time) EndAtMicro

func (t Time) EndAtMicro(n ...int) Time

func (Time) EndAtMilli

func (t Time) EndAtMilli(n ...int) Time

func (Time) EndAtMinute

func (t Time) EndAtMinute(n ...int) Time

func (Time) EndAtMonth

func (t Time) EndAtMonth(n ...int) Time

func (Time) EndAtNano

func (t Time) EndAtNano(n ...int) Time

func (Time) EndAtQuarter

func (t Time) EndAtQuarter(n ...int) Time

func (Time) EndAtSecond

func (t Time) EndAtSecond(n ...int) Time

func (Time) EndAtWeek

func (t Time) EndAtWeek(n ...int) Time

func (Time) EndAtWeekday

func (t Time) EndAtWeekday(n ...int) Time

func (Time) EndAtYear

func (t Time) EndAtYear(n ...int) Time

func (Time) EndByCentury

func (t Time) EndByCentury(n ...int) Time

func (Time) EndByDay

func (t Time) EndByDay(n ...int) Time

func (Time) EndByDecade

func (t Time) EndByDecade(n ...int) Time

func (Time) EndByHour

func (t Time) EndByHour(n ...int) Time

func (Time) EndByMicro

func (t Time) EndByMicro(n ...int) Time

func (Time) EndByMilli

func (t Time) EndByMilli(n ...int) Time

func (Time) EndByMinute

func (t Time) EndByMinute(n ...int) Time

func (Time) EndByMonth

func (t Time) EndByMonth(n ...int) Time

func (Time) EndByNano

func (t Time) EndByNano(n ...int) Time

func (Time) EndByQuarter

func (t Time) EndByQuarter(n ...int) Time

func (Time) EndBySecond

func (t Time) EndBySecond(n ...int) Time

func (Time) EndByWeek

func (t Time) EndByWeek(n ...int) Time

func (Time) EndByWeekday

func (t Time) EndByWeekday(n ...int) Time

func (Time) EndByYear

func (t Time) EndByYear(n ...int) Time

func (Time) EndCentury

func (t Time) EndCentury(n ...int) Time

func (Time) EndDay

func (t Time) EndDay(n ...int) Time

func (Time) EndDecade

func (t Time) EndDecade(n ...int) Time

func (Time) EndHour

func (t Time) EndHour(n ...int) Time

func (Time) EndInCentury

func (t Time) EndInCentury(n ...int) Time

func (Time) EndInDay

func (t Time) EndInDay(n ...int) Time

func (Time) EndInDecade

func (t Time) EndInDecade(n ...int) Time

func (Time) EndInHour

func (t Time) EndInHour(n ...int) Time

func (Time) EndInMicro

func (t Time) EndInMicro(n ...int) Time

func (Time) EndInMilli

func (t Time) EndInMilli(n ...int) Time

func (Time) EndInMinute

func (t Time) EndInMinute(n ...int) Time

func (Time) EndInMonth

func (t Time) EndInMonth(n ...int) Time

func (Time) EndInNano

func (t Time) EndInNano(n ...int) Time

func (Time) EndInQuarter

func (t Time) EndInQuarter(n ...int) Time

func (Time) EndInSecond

func (t Time) EndInSecond(n ...int) Time

func (Time) EndInWeek

func (t Time) EndInWeek(n ...int) Time

func (Time) EndInWeekday

func (t Time) EndInWeekday(n ...int) Time

func (Time) EndInYear

func (t Time) EndInYear(n ...int) Time

func (Time) EndMicro

func (t Time) EndMicro(n ...int) Time

func (Time) EndMilli

func (t Time) EndMilli(n ...int) Time

func (Time) EndMinute

func (t Time) EndMinute(n ...int) Time

func (Time) EndMonth

func (t Time) EndMonth(n ...int) Time

func (Time) EndNano

func (t Time) EndNano(n ...int) Time

func (Time) EndQuarter

func (t Time) EndQuarter(n ...int) Time

func (Time) EndSecond

func (t Time) EndSecond(n ...int) Time

func (Time) EndWeek

func (t Time) EndWeek(n ...int) Time

func (Time) EndWeekday

func (t Time) EndWeekday(n ...int) Time

func (Time) EndYear

func (t Time) EndYear(n ...int) Time

func (Time) Eq

func (t Time) Eq(u Time) bool

Eq 返回 t == u

func (Time) Format

func (t Time) Format(layout string) string

func (Time) Go

func (t Time) Go(n ...int) Time

func (Time) GoCentury

func (t Time) GoCentury(n ...int) Time

func (Time) GoDay

func (t Time) GoDay(n ...int) Time

func (Time) GoDecade

func (t Time) GoDecade(n ...int) Time

func (Time) GoHour

func (t Time) GoHour(n ...int) Time

func (Time) GoMicro

func (t Time) GoMicro(n ...int) Time

func (Time) GoMilli

func (t Time) GoMilli(n ...int) Time

func (Time) GoMinute

func (t Time) GoMinute(n ...int) Time

func (Time) GoMonth

func (t Time) GoMonth(n ...int) Time

func (Time) GoNano

func (t Time) GoNano(n ...int) Time

func (Time) GoQuarter

func (t Time) GoQuarter(n ...int) Time

func (Time) GoSecond

func (t Time) GoSecond(n ...int) Time

func (Time) GoWeek

func (t Time) GoWeek(n ...int) Time

func (Time) GoWeekday

func (t Time) GoWeekday(n ...int) Time

func (Time) GoYear

func (t Time) GoYear(n ...int) Time

func (Time) Gt

func (t Time) Gt(u Time) bool

Gt 返回 t 是否在 u 之后 (t > u)

func (Time) Hour

func (t Time) Hour() int

func (Time) ISOWeek

func (t Time) ISOWeek() (year, week int)

func (Time) InCentury

func (t Time) InCentury(n ...int) Time

func (Time) InDay

func (t Time) InDay(n ...int) Time

func (Time) InDecade

func (t Time) InDecade(n ...int) Time

func (Time) InHour

func (t Time) InHour(n ...int) Time

func (Time) InMicro

func (t Time) InMicro(n ...int) Time

func (Time) InMilli

func (t Time) InMilli(n ...int) Time

func (Time) InMinute

func (t Time) InMinute(n ...int) Time

func (Time) InMonth

func (t Time) InMonth(n ...int) Time

func (Time) InNano

func (t Time) InNano(n ...int) Time

func (Time) InQuarter

func (t Time) InQuarter(n ...int) Time

func (Time) InSecond

func (t Time) InSecond(n ...int) Time

func (Time) InWeek

func (t Time) InWeek(n ...int) Time

func (Time) InYear

func (t Time) InYear(n ...int) Time

func (Time) IsAM

func (t Time) IsAM() bool

IsAM 返回时间是否在上午 (00:00:00 ~ 11:59:59)

func (Time) IsDST

func (t Time) IsDST() bool

IsDST 返回 t 是否夏令时

func (Time) IsLeapYear

func (t Time) IsLeapYear() bool

IsLeapYear 返回 t 是否闰年

func (Time) IsLongYear

func (t Time) IsLongYear() bool

IsLongYear 返回 t 是否 ISO 长年

func (Time) IsSame

func (t Time) IsSame(u Unit, target Time) bool

IsSame 返回 t 与 target 是否在指定单位下相同 (包含上级单位一致性)

func (Time) IsWeekend

func (t Time) IsWeekend() bool

IsWeekend 返回时间是否在周末 (周六或周日)

func (Time) IsZero

func (t Time) IsZero() bool

IsZero 返回 t 是否零时,即 0001-01-01 00:00:00 UTC。

func (Time) Local

func (t Time) Local() Time

Local 返回本地时间

func (Time) Location

func (t Time) Location() *time.Location

Location 返回时区信息

func (Time) Lt

func (t Time) Lt(u Time) bool

Lt 返回 t 是否在 u 之前 (t < u)

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) MarshalText

func (t Time) MarshalText() ([]byte, error)

func (Time) Micro

func (t Time) Micro() int

Micro 返回微秒数 (0-999999)

func (Time) Milli

func (t Time) Milli() int

Milli 返回毫秒数 (0-999)

func (Time) Minute

func (t Time) Minute() int

func (Time) Month

func (t Time) Month() int

func (Time) Nano

func (t Time) Nano() int

Nano 返回纳秒数 (0-999999999)

func (Time) Round

func (t Time) Round(d time.Duration) Time

Round 返回距离当前时间最近的刻度点。

想象时间就是一把尺子,每隔 d 点设置刻度,返回与当前时间最近的刻度点时间。

示例:当前时间 t = 14:35:29,刻度 d = 15分钟

刻度尺:14:15 ──┬── 14:30 ── [t] ────┬── 14:45

此时 t (14:35) 距离刻度 14:30 更近,所以返回 14:30:00。

func (*Time) Scan

func (t *Time) Scan(value any) (err error)

func (Time) Second

func (t Time) Second() int

Second 返回时间的秒数 (0-59)

func (Time) Start

func (t Time) Start(n ...int) Time

func (Time) StartAt

func (t Time) StartAt(n ...int) Time

func (Time) StartAtCentury

func (t Time) StartAtCentury(n ...int) Time

func (Time) StartAtDay

func (t Time) StartAtDay(n ...int) Time

func (Time) StartAtDecade

func (t Time) StartAtDecade(n ...int) Time

func (Time) StartAtHour

func (t Time) StartAtHour(n ...int) Time

func (Time) StartAtMicro

func (t Time) StartAtMicro(n ...int) Time

func (Time) StartAtMilli

func (t Time) StartAtMilli(n ...int) Time

func (Time) StartAtMinute

func (t Time) StartAtMinute(n ...int) Time

func (Time) StartAtMonth

func (t Time) StartAtMonth(n ...int) Time

func (Time) StartAtNano

func (t Time) StartAtNano(n ...int) Time

func (Time) StartAtQuarter

func (t Time) StartAtQuarter(n ...int) Time

func (Time) StartAtSecond

func (t Time) StartAtSecond(n ...int) Time

func (Time) StartAtWeek

func (t Time) StartAtWeek(n ...int) Time

func (Time) StartAtWeekday

func (t Time) StartAtWeekday(n ...int) Time

func (Time) StartAtYear

func (t Time) StartAtYear(n ...int) Time

func (Time) StartByCentury

func (t Time) StartByCentury(n ...int) Time

func (Time) StartByDay

func (t Time) StartByDay(n ...int) Time

func (Time) StartByDecade

func (t Time) StartByDecade(n ...int) Time

func (Time) StartByHour

func (t Time) StartByHour(n ...int) Time

func (Time) StartByMicro

func (t Time) StartByMicro(n ...int) Time

func (Time) StartByMilli

func (t Time) StartByMilli(n ...int) Time

func (Time) StartByMinute

func (t Time) StartByMinute(n ...int) Time

func (Time) StartByMonth

func (t Time) StartByMonth(n ...int) Time

func (Time) StartByNano

func (t Time) StartByNano(n ...int) Time

func (Time) StartByQuarter

func (t Time) StartByQuarter(n ...int) Time

func (Time) StartBySecond

func (t Time) StartBySecond(n ...int) Time

func (Time) StartByWeek

func (t Time) StartByWeek(n ...int) Time

func (Time) StartByWeekday

func (t Time) StartByWeekday(n ...int) Time

func (Time) StartByYear

func (t Time) StartByYear(n ...int) Time

func (Time) StartCentury

func (t Time) StartCentury(n ...int) Time

func (Time) StartDay

func (t Time) StartDay(n ...int) Time

func (Time) StartDecade

func (t Time) StartDecade(n ...int) Time

func (Time) StartHour

func (t Time) StartHour(n ...int) Time

func (Time) StartInCentury

func (t Time) StartInCentury(n ...int) Time

func (Time) StartInDay

func (t Time) StartInDay(n ...int) Time

func (Time) StartInDecade

func (t Time) StartInDecade(n ...int) Time

func (Time) StartInHour

func (t Time) StartInHour(n ...int) Time

func (Time) StartInMicro

func (t Time) StartInMicro(n ...int) Time

func (Time) StartInMilli

func (t Time) StartInMilli(n ...int) Time

func (Time) StartInMinute

func (t Time) StartInMinute(n ...int) Time

func (Time) StartInMonth

func (t Time) StartInMonth(n ...int) Time

func (Time) StartInNano

func (t Time) StartInNano(n ...int) Time

func (Time) StartInQuarter

func (t Time) StartInQuarter(n ...int) Time

func (Time) StartInSecond

func (t Time) StartInSecond(n ...int) Time

func (Time) StartInWeek

func (t Time) StartInWeek(n ...int) Time

func (Time) StartInWeekday

func (t Time) StartInWeekday(n ...int) Time

func (Time) StartInYear

func (t Time) StartInYear(n ...int) Time

func (Time) StartMicro

func (t Time) StartMicro(n ...int) Time

func (Time) StartMilli

func (t Time) StartMilli(n ...int) Time

func (Time) StartMinute

func (t Time) StartMinute(n ...int) Time

func (Time) StartMonth

func (t Time) StartMonth(n ...int) Time

func (Time) StartNano

func (t Time) StartNano(n ...int) Time

func (Time) StartQuarter

func (t Time) StartQuarter(n ...int) Time

func (Time) StartSecond

func (t Time) StartSecond(n ...int) Time

func (Time) StartWeek

func (t Time) StartWeek(n ...int) Time

func (Time) StartWeekday

func (t Time) StartWeekday(n ...int) Time

func (Time) StartYear

func (t Time) StartYear(n ...int) Time

func (Time) String

func (t Time) String() string

func (Time) Sub

func (t Time) Sub(u Time) time.Duration

Sub 返回 t - u 的时间差

func (Time) Time

func (t Time) Time() time.Time

Time 返回 time.Time

func (Time) To

func (t Time) To(loc *time.Location) Time

To 返回指定的 loc 时间

func (Time) ToString

func (t Time) ToString(f ...string) string

func (Time) Truncate

func (t Time) Truncate(d time.Duration) Time

Truncate 与 Round 相同,但它永远截断在过去(而非未来)刻度的时间。

func (Time) UTC

func (t Time) UTC() Time

UTC 返回 UTC 时间

func (Time) Unix

func (t Time) Unix(n ...int) int64

Unix 返回时间戳,可选择指定精度。

参数 n (可选) 指定返回的时间戳精度:

  • 不提供或 0: 秒级 (10位)
  • 3: 毫秒级 (13位)
  • 6: 微秒级 (16位)
  • 9: 纳秒级 (19位)
  • 其他值: 对应位数的时间戳

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) (err error)

func (*Time) UnmarshalText

func (t *Time) UnmarshalText(data []byte) error

func (Time) Until added in v0.0.2

func (t Time) Until() time.Duration

Until 返回 t 与当前时间 (Now) 的相对时长 (t - Now)。

返回值:

  • 正数:t 在未来
  • 负数:t 在过去
  • 零: t 是现在

func (Time) Value

func (t Time) Value() (driver.Value, error)

func (Time) Weekday

func (t Time) Weekday() time.Weekday

func (Time) WithWeekStarts

func (t Time) WithWeekStarts(w time.Weekday) Time

WithWeekStarts 返回新实例,周起始日为 w。

func (Time) Year

func (t Time) Year() int

func (Time) YearDay

func (t Time) YearDay() int

YearDay 返回一年中的第几天,非闰年范围 [1,365],闰年范围 [1,366]。

func (Time) YearDays

func (t Time) YearDays() int

YearDays 返回本年总天数

func (Time) ZeroOr

func (t Time) ZeroOr(u Time) Time

func (Time) Zone

func (t Time) Zone() (name string, offset int)

Zone 获取当前时区的名称和偏移量

type Unit

type Unit int
const (
	Century Unit = iota
	Decade
	Year
	Month
	Day
	Hour
	Minute
	Second
	Millisecond
	Microsecond
	Nanosecond
	Quarter // 季度流
	Week    // 月周流
	Weekday // 星期流
)

type ZoneCache added in v0.0.4

type ZoneCache[K int | string | zoneKey] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ZoneCache[K]) Get added in v0.0.4

func (c *ZoneCache[K]) Get(name string, k K) (loc *time.Location)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL