datetime

package
v10.0.37 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: MIT Imports: 5 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// SignalTimeUnitNOW is now
	SignalTimeUnitNOW int32 = 0
	// SignalTimeUnitMONTH is 30 days
	SignalTimeUnitMONTH int32 = 30
	// SignalTimeUnitQUARTER is 90 days
	SignalTimeUnitQUARTER int32 = 90
	// SignalTimeUnitHALFYEAR is 180 days
	SignalTimeUnitHALFYEAR int32 = 180
	// SignalTimeUnitYEAR is 365 days
	SignalTimeUnitYEAR int32 = 365
	// SignalTimeUnitTHIRDQUARTER is 270 days
	SignalTimeUnitTHIRDQUARTER int32 = 270
	// SignalTimeUnitALLTIME is all time
	SignalTimeUnitALLTIME int32 = -1
	// SignalTimeUnitBIMONTH is two month
	SignalTimeUnitBIMONTH int32 = 60
	// DaysInMilliseconds is one day in milliseconds
	DaysInMilliseconds int64 = 86400000
)
View Source
const RFC3339 = "2006-01-02T15:04:05.999999999-07:00"

RFC3339 There is an edge case where there is no timezone set and that makes the format function return dates like 2019-09-03T20:48:57.073Z. We are using this RFC3339 custom format to always get an offset.

Variables

This section is empty.

Functions

func AddDaysToStrDate

func AddDaysToStrDate(date string, days int) (string, error)

AddDaysToStrDate will add days to string date

func ConvertToModel added in v10.0.6

func ConvertToModel(ts time.Time, dateModel interface{})

ConvertToModel will fill dateModel based on passed time

func DateFromEpoch

func DateFromEpoch(t int64) time.Time

DateFromEpoch returns a time.Time from an epoch value in milliseconds

func DateRange

func DateRange(ref time.Time, timeunit int64) (int64, int64)

DateRange will return the beginning and end of a date range for a given time unit. if the timeunit is -1 it will return epoch zero

func DateRangePrevious

func DateRangePrevious(ref int64, timeunit int64) (int64, int64)

DateRangePrevious will previous time date for the previous range from timeunit

func EndofDay

func EndofDay(tv int64) int64

EndofDay returns the end of the day (midnight) for a given epoch time

func EpochMinuteApart

func EpochMinuteApart(epoch1, epoch2 int64) bool

EpochMinuteApart returns true if both epochs are less than or equal to one minute apart

func EpochNow

func EpochNow() int64

EpochNow will return the current time in epoch (in UTC) with millisecond precision

func GetSignalDate

func GetSignalDate(timeUnit int32, refDate time.Time) string

GetSignalDate returns a metric date in short form for a time unit from the ref date

func GetSignalTime

func GetSignalTime(timeUnit int32, refDate time.Time) time.Time

GetSignalTime returns a metric date for a time unit from the ref date This will be changed from -30 to -29 because of the next example Lets say I want to take 1 day from "yesterday at the end" lets say "2017-02-26 23:59:59.9999" that will result in "2017-02-25 23:59:59.9999" and after truncate "2017-02-25 00:00:00" so it is actually taken 2 days

func GetTimeUnitString

func GetTimeUnitString(timeUnit int32) string

GetTimeUnitString will return the timeunit as a string

func ISODate

func ISODate() string

ISODate returns a RFC 3339 formatted string for the current date time

func ISODateFromTime

func ISODateFromTime(t time.Time) string

ISODateFromTime returns a RFC 3339 formatted string from the supplied timestamp

func ISODateOffsetToTime

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

ISODateOffsetToTime returns a RFC 3339 formatted string as a timestamp

func ISODateToEpoch

func ISODateToEpoch(date string) (int64, error)

ISODateToEpoch returns an epoch date or 0 if invalid or empty

func ISODateToTime

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

ISODateToTime returns a RFC 3339 formatted string as a timestamp

func ShortDate

func ShortDate(date string) string

ShortDate returns a DATE (no time) formatted string from RFC 3339 formatted string

func ShortDateFromEpoch

func ShortDateFromEpoch(t int64) string

ShortDateFromEpoch will return a short date from a epoch value in milliseconds

func ShortDateFromTime

func ShortDateFromTime(tv time.Time) string

ShortDateFromTime will return a short date from a time

func StartofDay

func StartofDay(tv int64) int64

StartofDay returns the start of the day (just after midnight) for a given epoch time

func TimeFromDate added in v10.0.25

func TimeFromDate(date Date) time.Time

TimeFromDate returns a time.Time for a date

func TimeToEpoch

func TimeToEpoch(tv time.Time) int64

TimeToEpoch will convert a time to epoch (in UTC) with millisecond precision

func ToMilliSec

func ToMilliSec(date time.Time) int64

ToMilliSec Convert time to milliseconds int64

func ToTimeRange

func ToTimeRange(tv time.Time, days int) (int64, int64)

ToTimeRange will return a start and end time range in epoch using tv as the reference day and adding days (use negative number to subtract)

Types

type Date

type Date struct {
	// Epoch the date in epoch format
	Epoch int64 `json:"epoch" bson:"epoch" yaml:"epoch" faker:"-"`
	// Offset the timezone offset from GMT
	Offset int64 `json:"offset" bson:"offset" yaml:"offset" faker:"-"`
	// Rfc3339 the date in RFC3339 format
	Rfc3339 string `json:"rfc3339" bson:"rfc3339" yaml:"rfc3339" faker:"-"`
}

Date represents the object structure for date

func NewDate

func NewDate(val string) (*Date, error)

NewDate returns a new Date object from a string date value

func NewDateFromEpoch

func NewDateFromEpoch(epoch int64) Date

NewDateFromEpoch returns a new Date object from a epoch time value

func NewDateNow

func NewDateNow() Date

NewDateNow returns a Date object as of now

func NewDateWithTime

func NewDateWithTime(tv time.Time) *Date

NewDateWithTime returns a new Date object from a time.Time value

Jump to

Keyboard shortcuts

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