timeutils

package
v0.0.0-...-c558e1b Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DaysToSeconds

func DaysToSeconds(days int) int64

DaysToSeconds converts a number of days into the equivalent number of seconds.

func IsAtLeastAge

func IsAtLeastAge(dob int64, age int) bool

IsAtLeastAge determines if a given date of birth (in Unix timestamp format) represents a person who is at least the specified age in years. The function compares the date of birth against a timestamp calculated as the current time minus the specified age in years.

func MonthsAgoUnix

func MonthsAgoUnix(months int) int64

MonthsAgoUnix returns the Unix timestamp corresponding to the current time minus a specified number of months. The function uses the AddDate method to subtract the specified number of months.

func MonthsAgoUnixPointer

func MonthsAgoUnixPointer(months int) *int64

MonthsAgoUnixPointer returns a pointer to the Unix timestamp corresponding to the current time minus a specified number of months. The function uses the AddDate method to subtract the specified number of months.

func MonthsFromNowUnix

func MonthsFromNowUnix(months int) int64

MonthsFromNowUnix returns the Unix timestamp corresponding to the current time plus a specified number of months. The function uses the AddDate method to add the specified number of months.

func NowUnix

func NowUnix() int64

NowUnix returns the current time as a Unix timestamp. The Unix timestamp represents the number of seconds elapsed since January 1, 1970 UTC.

func NowUnixPointer

func NowUnixPointer() *int64

NowUnixPointer returns a pointer to the current Unix timestamp. This is useful for cases where a pointer to the timestamp is needed.

func ParseTimeValue

func ParseTimeValue(value any) (time.Time, error)

ParseTimeValue parses a given value into a time.Time object. Supported input types: - string: Parses the string as an RFC3339 formatted timestamp. - time.Time: Returns the input as-is. - int64: Treats the value as a Unix timestamp and converts it to time.Time. Returns an error if the input type is unsupported.

func SecondsPerYear

func SecondsPerYear() int64

SecondsPerYear returns the number of seconds in a year. It assumes a year has 365 days and does not account for leap years.

func YearsAgoUnix

func YearsAgoUnix(years int) int64

YearsAgoUnix returns the Unix timestamp corresponding to the current time minus a specified number of years. The function uses the AddDate method to subtract the specified number of years.

func YearsAgoUnixPointer

func YearsAgoUnixPointer(years int) *int64

YearsAgoUnixPointer returns a pointer to the Unix timestamp corresponding to the current time minus a specified number of years. The function uses the AddDate method to subtract the specified number of years.

func YearsFromNowUnix

func YearsFromNowUnix(years int) int64

YearsFromNowUnix returns the Unix timestamp corresponding to the current time plus a specified number of years. The function uses the AddDate method to add the specified number of years.

func YearsFromNowUnixPointer

func YearsFromNowUnixPointer(years int) *int64

YearsFromNowUnixPointer returns a pointer to the Unix timestamp corresponding to the current time plus a specified number of years. The function uses the AddDate method to add the specified number of years.

func YearsToSeconds

func YearsToSeconds(years int) int64

YearsToSeconds converts a number of years into the equivalent number of seconds. It assumes a year has 365 days and does not account for leap years.

Types

This section is empty.

Jump to

Keyboard shortcuts

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