datetime

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

精确到s的时间范围计算

Index

Constants

View Source
const (
	DATETIME_FORMATTER          = "2006-01-02 15:04:05"
	DATETIME_FORMATTER_Mill     = "2006-01-02 15:04:05.000"
	DATETIME_TIMEZONE_FORMATTER = "2006-01-02 15:04:05 -0700"
)

Variables

This section is empty.

Functions

func DayFirst

func DayFirst(time Time.Time) uint64

当前时间所在 天 的起始秒时间戳

func DayLast

func DayLast(time Time.Time) uint64

当前时间所在 天 的结束秒时间戳

func FirstAndLastDay

func FirstAndLastDay(time Time.Time) (uint64, uint64)

取1天的开始时间与结束时间

func FirstAndLastHour

func FirstAndLastHour(time Time.Time) (uint64, uint64)

取1小时的开始时间与结束时间

func FirstAndLastMinute

func FirstAndLastMinute(time Time.Time) (uint64, uint64)

取1分钟的开始时间与结束时间

func FirstAndLastMonth

func FirstAndLastMonth(time Time.Time) (uint64, uint64)

取1个月的开始时间与结束时间

func FirstAndLastWeek

func FirstAndLastWeek(time Time.Time) (uint64, uint64)

取1周的开始时间与结束时间

func FirstAndLastYear

func FirstAndLastYear(time Time.Time) (uint64, uint64)

取1年的开始时间与结束时间

func HourFirst

func HourFirst(time Time.Time) uint64

当前时间所在 小时 的起始秒时间戳

func HourLast

func HourLast(time Time.Time) uint64

当前时间所在 小时 的结束秒时间戳

func MinuteFirst

func MinuteFirst(time Time.Time) uint64

当前时间所在 分 的起始秒时间戳

func MinuteLast

func MinuteLast(time Time.Time) uint64

当前时间所在 分 的结束秒时间戳

func MonthDays

func MonthDays(time Time.Time) uint

获取指定时间所在月份的天数

func MonthFirst

func MonthFirst(time Time.Time) uint64

当前时间所在 月 的起始秒时间戳

func MonthLast

func MonthLast(time Time.Time) uint64

当前时间所在 月 的结束秒时间戳

func WeekFirst

func WeekFirst(time Time.Time) uint64

当前时间所在 周 的起始秒时间戳

func WeekLast

func WeekLast(time Time.Time) uint64

func YearDays

func YearDays(time Time.Time) uint

获取指定时间所在年份的天数

func YearFirst

func YearFirst(time Time.Time) uint64

当前时间所在 年 的起始秒时间戳

func YearLast

func YearLast(time Time.Time) uint64

当前时间所在 年 的起始秒时间戳

Types

type Duration

type Duration int64
const (
	NONE   Duration = 0
	SECOND Duration = 1
	MINUTE Duration = 2
	HOUR   Duration = 3
	DAY    Duration = 4
	WEEK   Duration = 5
	MONTH  Duration = 6
	YEAR   Duration = 7
)

type RecordItem

type RecordItem struct {
	Timestamp uint64  // 时间戳, 精确到s
	Value     float64 // 值
}

type TimeSlice

type TimeSlice struct {
	Start uint64 // 时间戳, 精确到s
	End   uint64 // 时间戳, 精确到s
	Tag   any    // 结果集

}

func SplitDuration

func SplitDuration(start, end Time.Time, duration Duration) []*TimeSlice

按指定时间间隔 进行1个自然周期的切割

参数

  • start: 开始时间
  • end: 结束时间
  • duration: 时间间隔周期

返回值

  • []*TimeSlice: 切割后的时间片段

func SplitNaturalDuration

func SplitNaturalDuration(start, end Time.Time, unit uint, duration Duration) []*TimeSlice

按指定时间间隔 进行自然周期的切割

参数

  • start: 开始时间
  • end: 结束时间
  • unit: 间隔数量, 时间间隔等于 unit * duration
  • duration: 时间间隔周期

返回值

  • []*TimeSlice: 切割后的时间片段

func SplitUnnaturalDuration

func SplitUnnaturalDuration(start, end Time.Time, unit uint, duration Duration) []*TimeSlice

按指定时间间隔 进行非自然周期的切割

参数

  • start: 开始时间
  • end: 结束时间
  • unit: 时间间隔单位
  • duration: 时间间隔周期

返回值

  • []*TimeSlice: 切割后的时间片段

Jump to

Keyboard shortcuts

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