timex

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 7 Imported by: 2

README

timex

Time helper for Golang.

Install

go get github.com/innotechdevops/timex

How to use

  • Parse by date ISO
datetime, _ := timex.ParseBy("2023-12-03T13:51:06.474Z", timex.DateTimeFormatISO)
  • Parse by GMT7
date, _ := timex.ParseByGMT7(datetime, timex.TimeFormatDash1)

Documentation

Index

Constants

View Source
const (
	Day                 = "day"
	Week                = "week"
	Month               = "month"
	Year                = "year"
	Custom              = "custom"
	PeriodPrevious      = "previous"
	PeriodCurrent       = "current"
	TimeZoneAsiaBangkok = "Asia/Bangkok"
	TimeFormatDash1     = "2006-01-02 15:04:05"
	TimeFormatSlash     = "2006/01/02 15:04:05"
	TimeFormatDash2     = "2006-01-02 15:04"
	DateFormatSlash1    = "2006/01/02"
	DateFormatSlash2    = "02/01/2006"
	DateFormatSlash3    = "2/1/2006"
	DateFormatSlash4    = "01/02/2006 15:04:05"
	DateFormatDash      = "2006-01-02"
	DateFormat          = "20060102"
	DateFormatTime      = "15:04:05"
	DateFormatMin       = "15:04"
	DateFormatTime2     = "200601021504"
	DateTimeFormatISO   = "2006-01-02T15:04:05.000Z"
	DateTimeFormatUTC   = "2006-01-02 15:04:05 +0000 UTC"
	DateTimeFormatUTC2  = "2006-01-02 15:04:05 -0700 -07"
)

Variables

This section is empty.

Functions

func CalcEndOfMonth

func CalcEndOfMonth(date time.Time) time.Time

func ConvertDdMmYyyyBy

func ConvertDdMmYyyyBy(date string, layout string) string

func Date

func Date() (int, time.Month, int)

func EndOfMonth

func EndOfMonth(date time.Time) int

func Format

func Format(year int, m time.Month, d int) string

func FromTimestamp

func FromTimestamp(timestamp int64, tz *time.Location) time.Time

func FromTimestampGMT7

func FromTimestampGMT7(timestamp int64) time.Time

func GetFebruaryLastOfMonth

func GetFebruaryLastOfMonth()

func GetTimeZone

func GetTimeZone(zone string) *time.Location

func GetWeekday

func GetWeekday(date time.Time) string

func IsIntervalElapsed

func IsIntervalElapsed(location string, timestamp time.Time, updatedAt time.Time, interval int64) (time.Time, bool)

func IsWorkday

func IsWorkday(date time.Time) bool

func IsWorkdayBy

func IsWorkdayBy(date string, layout string) (bool, error)

func IsYyyyMm

func IsYyyyMm(month string, format string) bool

func MonthsToDays

func MonthsToDays(months int) int

MonthsToDays Function to convert months to days considering leap years

func NextDay

func NextDay(day int) time.Time

func Now

func Now() time.Time

func NowWithoutTime

func NowWithoutTime() time.Time

func Parse

func Parse(date string) (time.Time, error)

Parse date string 2021-09-09T00:00:00.000Z to time.Time

func ParseBy

func ParseBy(date string, layout string) (time.Time, error)

func ParseByGMT7

func ParseByGMT7(date string, layout string, utc ...bool) (time.Time, error)

func ParseByLocation

func ParseByLocation(date string, layout string, tz string, utc ...bool) (time.Time, error)

func ParseByYmDash

func ParseByYmDash(ym string) (time.Time, error)

func ParseByYyyyMm

func ParseByYyyyMm(month string, format string) time.Time

func ParseDdMmYyyy

func ParseDdMmYyyy(date string) (string, error)

func ParseEndOfDay

func ParseEndOfDay(date string) (time.Time, error)

ParseEndOfDay date string 2021-09-09 to time.Time

func ParseStartOfDay

func ParseStartOfDay(date string) (time.Time, error)

ParseStartOfDay date string 2021-09-09 to time.Time

func PrevDay

func PrevDay(num int) time.Time

func PrevMonth

func PrevMonth(num int) time.Time

func PrevYear

func PrevYear(num int) time.Time

func SubDay

func SubDay(currentDate time.Time, day int) time.Time

func SubMonth

func SubMonth(t time.Time, num int) time.Time

func TimeNow

func TimeNow() *now.Now

func TimeNowFormat

func TimeNowFormat(zone string, format string) string

func UtcToGmt7

func UtcToGmt7(utcTime time.Time) time.Time

func Validate

func Validate(date string, layout string) bool

func ValidateDateFormatDash

func ValidateDateFormatDash(dateTime string) bool

func ValidateDateFormatSlash3

func ValidateDateFormatSlash3(dateTime string) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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