datetime

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUnit

func AddUnit(tm time.Time, amount int, u Unit) (res time.Time)

AddUnit add amount given in u to tm

func Date

func Date(_ context.Context, args ...core.Value) (core.Value, error)

Date convert RFC3339 date time string to DateTime object. @params timeString (String) - string in RFC3339 format. @return (DateTime) - new DateTime object derived from timeString.

func DateAdd

func DateAdd(_ context.Context, args ...core.Value) (core.Value, error)

DateAdd add amount given in unit to date. @params date (DateTime) - source date. @params amount (Int) - amount of units @params unit (String) - unit. @return (DateTime) - calculated date. The following units are available: * y, year, year * m, month, months * w, week, weeks * d, day, days * h, hour, hours * i, minute, minutes * s, second, seconds * f, millisecond, milliseconds

func DateCompare

func DateCompare(_ context.Context, args ...core.Value) (core.Value, error)

DateCompare check if two partial dates match. @params date1, date2 (DateTime) - comparable dates. @params unitRangeStart (String) - unit to start from. @params unitRangeEnd (String, Optional) - unit to end with. Error will be returned if unitRangeStart unit less that unitRangeEnd. @return (Boolean) - true if the dates match, else false.

func DateDay

func DateDay(_ context.Context, args ...core.Value) (core.Value, error)

DateDay returns the day of date as a number. @params date (DateTime) - source DateTime. @return (Int) - a day number.

func DateDayOfWeek

func DateDayOfWeek(_ context.Context, args ...core.Value) (core.Value, error)

DateDayOfWeek returns number of the weekday from the date. Sunday is the 0th day of week. @params date (DateTime) - source DateTime. @return (Int) - return number of the weekday.

func DateDayOfYear

func DateDayOfYear(_ context.Context, args ...core.Value) (core.Value, error)

DateDayOfYear returns the day of year number of date. The return value range from 1 to 365 (366 in a leap year). @params date (DateTime) - source DateTime. @return (Int) - a day of year number.

func DateDaysInMonth

func DateDaysInMonth(_ context.Context, args ...core.Value) (core.Value, error)

DateDaysInMonth returns the number of days in the month of date. @params date (DateTime) - source DateTime. @return (Int) - number of the days.

func DateDiff

func DateDiff(_ context.Context, args ...core.Value) (core.Value, error)

DateDiff returns the difference between two dates in given time unit. @params date1 (DateTime) - first DateTime. @params date2 (DateTime) - second DateTime. @params unit (String) - time unit to return the difference in. @params asFloat (Boolean, optional) - if true amount of unit will be as float. @return (Int, Float) - difference between date1 and date2.

func DateFormat

func DateFormat(_ context.Context, args ...core.Value) (core.Value, error)

DateFormat format date according to the given format string. @params date (DateTime) - source DateTime object. @return (String) - formatted date.

func DateHour

func DateHour(_ context.Context, args ...core.Value) (core.Value, error)

DateHour returns the hour of date as a number. @params date (DateTime) - source DateTime. @return (Int) - a hour number.

func DateLeapYear

func DateLeapYear(_ context.Context, args ...core.Value) (core.Value, error)

DateLeapYear returns true if date is in a leap year else false. @params date (DateTime) - source DateTime. @return (Boolean) - date is in a leap year.

func DateMillisecond

func DateMillisecond(_ context.Context, args ...core.Value) (core.Value, error)

DateMillisecond returns the millisecond of date as a number. @params date (DateTime) - source DateTime. @return (Int) - a millisecond number.

func DateMinute

func DateMinute(_ context.Context, args ...core.Value) (core.Value, error)

DateMinute returns the minute of date as a number. @params date (DateTime) - source DateTime. @return (Int) - a minute number.

func DateMonth

func DateMonth(_ context.Context, args ...core.Value) (core.Value, error)

DateMonth returns the month of date as a number. @params date (DateTime) - source DateTime. @return (Int) - a month number.

func DateQuarter

func DateQuarter(_ context.Context, args ...core.Value) (core.Value, error)

DateQuarter returns which quarter date belongs to. @params date (DateTime) - source DateTime. @return (Int) - a quarter number.

func DateSecond

func DateSecond(_ context.Context, args ...core.Value) (core.Value, error)

DateSecond returns the second of date as a number. @params date (DateTime) - source DateTime. @return (Int) - a second number.

func DateSubtract

func DateSubtract(_ context.Context, args ...core.Value) (core.Value, error)

DateSubtract subtract amount given in unit to date. @params date (DateTime) - source date. @params amount (Int) - amount of units @params unit (String) - unit. @return (DateTime) - calculated date. The following units are available: * y, year, year * m, month, months * w, week, weeks * d, day, days * h, hour, hours * i, minute, minutes * s, second, seconds * f, millisecond, milliseconds

func DateYear

func DateYear(_ context.Context, args ...core.Value) (core.Value, error)

DateYear returns the year extracted from the given date. @params date (DateTime) - source DateTime. @return (Int) - a year number.

func IsDatesEqual

func IsDatesEqual(tm1, tm2 time.Time, u Unit) bool

IsDatesEqual check if two partial dates match. This case the day means not the amount of days in Time, but the day of the month. The same rules applied to each unit.

func NewLib

func NewLib() map[string]core.Function

func Now

func Now(_ context.Context, args ...core.Value) (core.Value, error)

Now returns new DateTime object with Time equal to time.Now(). @returns (DateTime) - New DateTime object.

Types

type Unit

type Unit int

Unit specifies an unit of time (Millsecond, Second...).

const (
	Millisecond Unit = iota
	Second
	Minute
	Hour
	Day
	Week
	Month
	Year
)

func UnitFromString

func UnitFromString(s string) (Unit, error)

UnitFromString returns true and an Unit object if Unit with that name exists. Returns false, otherwise.

func (Unit) Nanosecond

func (u Unit) Nanosecond() float64

Nanosecond returns representation of an Unit in nanosconds

Jump to

Keyboard shortcuts

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