timex

package
v0.0.0-...-0cc84fb Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[t int | int8 | int16 | int32 | int64 | float32 | float64](num t) t

func Caintains

func Caintains[T comparable](s []T, v T) bool

func CheckTimeBetween

func CheckTimeBetween(t time.Time, start, end string) (bool, error)

func DayEnd

func DayEnd(t ...time.Time) time.Time

func DayStart

func DayStart(t ...time.Time) time.Time

func FloatMulti

func FloatMulti(a, b float64) decimal.Decimal

func GetRealIP

func GetRealIP(r *http.Request) string

GetRealIP 获取客户端真实 IP 地址

func GetUidFromCtx

func GetUidFromCtx(ctx context.Context) uint64

func GetWeekdayMidnightISO

func GetWeekdayMidnightISO(t time.Time, targetWeekday time.Weekday) time.Time

/////////////////////////////////Begin给出任一个时间,算出该时间所属于的周一到周日的0点时间/////////////////////////////////////////////////

func GetWholeWeekDays

func GetWholeWeekDays(t time.Time) []time.Time

func Int64ToString

func Int64ToString(nTimeStamp int64) (strTime string)

////////////////////////////////////////////////////////////////////////////////////////

func Int64ToTime

func Int64ToTime(nTime int64) time.Time

func IntervalToDuration

func IntervalToDuration(interval string) time.Duration

func IntervalToSec

func IntervalToSec(interval string) int64

func IsZero

func IsZero(v any) bool

func Map2Map

func Map2Map[K1 comparable, V1 any, K2 comparable, V2 any](m map[K1]V1, fn func(K1, V1) (K2, V2)) map[K2]V2

func Map2Slice

func Map2Slice[K comparable, V any](m map[K]V) []V

func MapKey2Slice

func MapKey2Slice[K comparable, V any](m map[K]V) []K

func MonthEnd

func MonthEnd(t ...time.Time) time.Time

func MonthStart

func MonthStart(t ...time.Time) time.Time

func ObjectIDToUint64

func ObjectIDToUint64(in primitive.ObjectID) uint64

ObjectIDToUint64 将 [12]byte 数组转换为 uint64,只读取前 8 字节并按大端解析

func ParseLocalTime

func ParseLocalTime(layout, value string) (time.Time, error)

func ParseTimeRange

func ParseTimeRange(value string) (start, end time.Time, err error)

func RandNumWithCheck

func RandNumWithCheck(length, try int, fn func(uint64) bool) (uint64, error)

func ReflectFields

func ReflectFields(v any) map[string]any

ReflectFields 反射对象内容字段,主要是为了获取对象是否包括哪些字段。

func SearchIndex

func SearchIndex[E comparable](slice []E, element E) int

func Slice2Any

func Slice2Any[T any](s []T) []any

func Slice2Map

func Slice2Map[K comparable, V any](s []V, keyFn func(V) K) map[K]V

func Slice2Set

func Slice2Set[T any, K comparable](s []T, fn func(T) K) []K

func Slice2Slice

func Slice2Slice[T any, R any](s []T, fn func(T) R) []R

func Str2ObjectID

func Str2ObjectID(str string) primitive.ObjectID

func StringToInt64

func StringToInt64(strTime string) (nTimeStamp int64)

func StringToTime

func StringToTime(strTime string) time.Time

////////////////////////////////////////////////////////////////////////////////////////////////

func Time64ToTime

func Time64ToTime(t int64) time.Time

func TimeBeforeOrLater

func TimeBeforeOrLater(curr_time int64, tag string, year_diff int, month_diff time.Month, day_diff, hour_diff, min_diff, sec_diff int) (target_time int64)

////////////////////////////////////////////////////////////////////////////////////////

func TimeToString

func TimeToString(t time.Time) string

func TimetToInt64

func TimetToInt64(tTime time.Time) (nTime int64)

////////////////////////////////////////////////////////////////////////////////////////////////

func TimetToString

func TimetToString(tTime time.Time) (strTime string)

func ToPtr

func ToPtr[T any](v T) *T

func Today

func Today() time.Time

func TodayInt64ToInt

func TodayInt64ToInt(time64 int64) int

20250615

func TodayInt64ToStr

func TodayInt64ToStr(time64 int64) string

"2025-06-15 15:05:10"

func Todaystr

func Todaystr() string

func Uint64ToObjectID

func Uint64ToObjectID(num uint64) primitive.ObjectID

Uint64ToObjectID 将 uint64 转换为 [12]byte 数组,前 8 字节为大端表示,后 4 字节为 0 填充

func Yesterday

func Yesterday() string

func YesterdayInt64ToInt

func YesterdayInt64ToInt(time64 int64) int

20250614

func YesterdayInt64ToStr

func YesterdayInt64ToStr(time64 int64) string

"2025-06-14 15:05:10"

Types

This section is empty.

Jump to

Keyboard shortcuts

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