datetime

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 7 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 parses a formatted string and returns DateTime object it represents. @param {String} time - String representation of DateTime. @param {String} [layout = "2006-01-02T15:04:05Z07:00"] - String layout. @return {DateTime} - New DateTime object derived from timeString.

func DateAdd

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

DATE_ADD adds amount given in unit to 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 @param {DateTime} date - Source date. @param {Int} amount - Amount of units @param {String} unit - Unit. @return {DateTime} - Calculated date.

func DateCompare

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

DATE_COMPARE checks if two partial dates match. @param {DateTime} date1 - First date. @param {DateTime} date2 - Second date. @param {String} unitRangeStart - Unit to start from. @param {String} [unitRangeEnd="millisecond"] - 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)

DATE_DAY returns the day of date as a number. @param {DateTime} date - Source DateTime. @return {Int} - A day number.

func DateDayOfWeek

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

DATE_DAYOFWEEK returns number of the weekday from the date. Sunday is the 0th day of week. @param {DateTime} date - Source DateTime. @return {Int} - Number of the weekday.

func DateDayOfYear

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

DATE_DAYOFYEAR returns the day of year number of date. The return value range from 1 to 365 (366 in a leap year). @param {DateTime} date - Source DateTime. @return {Int} - A day of year number.

func DateDaysInMonth

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

DATE_DAYS_IN_MONTH returns the number of days in the month of date. @param {DateTime} date - Source DateTime. @return {Int} - Number of the days.

func DateDiff

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

DATE_DIFF returns the difference between two dates in given time unit. @param {DateTime} date1 - First date. @param {DateTime} date2 - Second date. @param {String} unit - Time unit to return the difference in. @param {Boolean} [asFloat=False] - 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)

DATE_FORMAT format date according to the given format string. @param {DateTime} date - Source DateTime object. @param {String} format - String format. @return {String} - Formatted date.

func DateHour

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

DATE_HOUR returns the hour of date as a number. @param {DateTime} date - Source DateTime. @return {Int} - An hour number.

func DateLeapYear

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

DATE_LEAPYEAR returns true if date is in a leap year else false. @param {DateTime} date - Source DateTime. @return {Boolean} - Date is in a leap year.

func DateMillisecond

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

DATE_MILLISECOND returns the millisecond of date as a number. @param {DateTime} date - Source DateTime. @return {Int} - A millisecond number.

func DateMinute

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

DATE_MINUTE returns the minute of date as a number. @param {DateTime} date -Source DateTime. @return {Int} - A minute number.

func DateMonth

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

DATE_MONTH returns the month of date as a number. @param {DateTime} date - Source DateTime. @return {Int} - A month number.

func DateQuarter

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

DATE_QUARTER returns which quarter date belongs to. @param {DateTime} date - Source DateTime. @return {Int} - A quarter number.

func DateSecond

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

DATE_SECOND returns the second of date as a number. @param {DateTime} date - Source DateTime. @return {Int} - A second number.

func DateSubtract

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

DATE_SUBTRACT subtract amount given in unit to 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 @param {DateTime} date - source date. @param {Int} amount - amount of units @param {String} unit - unit. @return {DateTime} - calculated date.

func DateYear

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

DATE_YEAR returns the year extracted from the given date. @param {DateTime} date - 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 Now

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

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

func RegisterLib added in v0.10.1

func RegisterLib(ns core.Namespace) error

Types

type Unit

type Unit int

Unit specifies an unit of time (Millisecond, 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