time

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package time provides time module for measuring and displaying time for Gad script language. It wraps ToInterface's time package functionalities. Note that: Gad's int values are converted to ToInterface's time.Duration values.

Index

Constants

This section is empty.

Variables

View Source
var LocationType = &gad.BuiltinObjType{
	NameValue: "location",
}
View Source
var Module = map[string]gad.Object{

	"Type": TimeType,

	"January":   gad.Int(time.January),
	"February":  gad.Int(time.February),
	"March":     gad.Int(time.March),
	"April":     gad.Int(time.April),
	"May":       gad.Int(time.May),
	"June":      gad.Int(time.June),
	"July":      gad.Int(time.July),
	"August":    gad.Int(time.August),
	"September": gad.Int(time.September),
	"October":   gad.Int(time.October),
	"November":  gad.Int(time.November),
	"December":  gad.Int(time.December),

	"Sunday":    gad.Int(time.Sunday),
	"Monday":    gad.Int(time.Monday),
	"Tuesday":   gad.Int(time.Tuesday),
	"Wednesday": gad.Int(time.Wednesday),
	"Thursday":  gad.Int(time.Thursday),
	"Friday":    gad.Int(time.Friday),
	"Saturday":  gad.Int(time.Saturday),

	"ANSIC":       gad.Str(time.ANSIC),
	"UnixDate":    gad.Str(time.UnixDate),
	"RubyDate":    gad.Str(time.RubyDate),
	"RFC822":      gad.Str(time.RFC822),
	"RFC822Z":     gad.Str(time.RFC822Z),
	"RFC850":      gad.Str(time.RFC850),
	"RFC1123":     gad.Str(time.RFC1123),
	"RFC1123Z":    gad.Str(time.RFC1123Z),
	"RFC3339":     gad.Str(time.RFC3339),
	"RFC3339Nano": gad.Str(time.RFC3339Nano),
	"Kitchen":     gad.Str(time.Kitchen),
	"Stamp":       gad.Str(time.Stamp),
	"StampMilli":  gad.Str(time.StampMilli),
	"StampMicro":  gad.Str(time.StampMicro),
	"StampNano":   gad.Str(time.StampNano),

	"Nanosecond":  gad.Int(time.Nanosecond),
	"Microsecond": gad.Int(time.Microsecond),
	"Millisecond": gad.Int(time.Millisecond),
	"Second":      gad.Int(time.Second),
	"Minute":      gad.Int(time.Minute),
	"Hour":        gad.Int(time.Hour),

	"UTC": &gad.Function{
		Name:  "UTC",
		Value: stdlib.FuncPRO(utcFunc),
	},

	"Local": &gad.Function{
		Name:  "Local",
		Value: stdlib.FuncPRO(localFunc),
	},

	"MonthString": &gad.Function{
		Name:  "MonthString",
		Value: stdlib.FuncPiRO(monthStringFunc),
	},

	"WeekdayString": &gad.Function{
		Name:  "WeekdayString",
		Value: stdlib.FuncPiRO(weekdayStringFunc),
	},

	"DurationString": &gad.Function{
		Name:  "DurationString",
		Value: stdlib.FuncPi64RO(durationStringFunc),
	},

	"DurationNanoseconds": &gad.Function{
		Name:  "DurationNanoseconds",
		Value: stdlib.FuncPi64RO(durationNanosecondsFunc),
	},

	"DurationMicroseconds": &gad.Function{
		Name:  "DurationMicroseconds",
		Value: stdlib.FuncPi64RO(durationMicrosecondsFunc),
	},

	"DurationMilliseconds": &gad.Function{
		Name:  "DurationMilliseconds",
		Value: stdlib.FuncPi64RO(durationMillisecondsFunc),
	},

	"DurationSeconds": &gad.Function{
		Name:  "DurationSeconds",
		Value: stdlib.FuncPi64RO(durationSecondsFunc),
	},

	"DurationMinutes": &gad.Function{
		Name:  "DurationMinutes",
		Value: stdlib.FuncPi64RO(durationMinutesFunc),
	},

	"DurationHours": &gad.Function{
		Name:  "DurationHours",
		Value: stdlib.FuncPi64RO(durationHoursFunc),
	},

	"Sleep": &gad.Function{
		Name:  "Sleep",
		Value: sleepFunc,
	},

	"ParseDuration": &gad.Function{
		Name:  "ParseDuration",
		Value: stdlib.FuncPsROe(parseDurationFunc),
	},

	"DurationRound": &gad.Function{
		Name:  "DurationRound",
		Value: stdlib.FuncPi64i64RO(durationRoundFunc),
	},

	"DurationTruncate": &gad.Function{
		Name:  "DurationTruncate",
		Value: stdlib.FuncPi64i64RO(durationTruncateFunc),
	},

	"FixedZone": &gad.Function{
		Name:  "FixedZone",
		Value: stdlib.FuncPsiRO(fixedZoneFunc),
	},

	"LoadLocation": &gad.Function{
		Name:  "LoadLocation",
		Value: stdlib.FuncPsROe(loadLocationFunc),
	},

	"IsLocation": &gad.Function{
		Name:  "IsLocation",
		Value: stdlib.FuncPORO(isLocationFunc),
	},

	"Time": &gad.Function{
		Name:  "Time",
		Value: stdlib.FuncPRO(zerotimeFunc),
	},

	"Since": &gad.Function{
		Name:  "Since",
		Value: funcPTRO(sinceFunc),
	},

	"Until": &gad.Function{
		Name:  "Until",
		Value: funcPTRO(untilFunc),
	},

	"Date": &gad.Function{
		Name:  "Date",
		Value: dateFunc,
	},

	"Now": &gad.Function{
		Name:  "Now",
		Value: stdlib.FuncPRO(nowFunc),
	},

	"Parse": &gad.Function{
		Name:  "Parse",
		Value: parseFunc,
	},

	"Unix": &gad.Function{
		Name:  "Unix",
		Value: unixFunc,
	},

	"Add": &gad.Function{
		Name:  "Add",
		Value: funcPTi64RO(timeAdd),
	},

	"Sub": &gad.Function{
		Name:  "Sub",
		Value: funcPTTRO(timeSub),
	},

	"AddDate": &gad.Function{
		Name:  "AddDate",
		Value: funcPTiiiRO(timeAddDate),
	},

	"After": &gad.Function{
		Name:  "After",
		Value: funcPTTRO(timeAfter),
	},

	"Before": &gad.Function{
		Name:  "Before",
		Value: funcPTTRO(timeBefore),
	},

	"Format": &gad.Function{
		Name:  "Format",
		Value: funcPTsRO(timeFormat),
	},

	"AppendFormat": &gad.Function{
		Name:  "AppendFormat",
		Value: funcPTb2sRO(timeAppendFormat),
	},

	"In": &gad.Function{
		Name:  "In",
		Value: funcPTLRO(timeIn),
	},

	"Round": &gad.Function{
		Name:  "Round",
		Value: funcPTi64RO(timeRound),
	},

	"Truncate": &gad.Function{
		Name:  "Truncate",
		Value: funcPTi64RO(timeTruncate),
	},

	"IsTime": &gad.Function{
		Name:  "IsTime",
		Value: stdlib.FuncPORO(isTimeFunc),
	},
}

Module represents time module.

View Source
var TimeType = &gad.BuiltinObjType{
	NameValue: "time",
}

Functions

This section is empty.

Types

type Location

type Location struct {
	gad.ObjectImpl
	Value *time.Location
}

Location represents location values and implements gad.Object interface.

func ToLocation

func ToLocation(o gad.Object) (ret *Location, ok bool)

ToLocation will try to convert given gad.Object to *Location value.

func (*Location) Equal

func (o *Location) Equal(right gad.Object) bool

Equal implements gad.Object interface.

func (*Location) IsFalsy

func (o *Location) IsFalsy() bool

IsFalsy implements gad.Object interface.

func (*Location) ToString

func (o *Location) ToString() string

ToString implements gad.Object interface.

func (*Location) Type

func (*Location) Type() gad.ObjectType

type Time

type Time struct {
	Value time.Time
}

Time represents time values and implements gad.Object interface.

func ToTime

func ToTime(o gad.Object) (ret *Time, ok bool)

ToTime will try to convert given gad.Object to *Time value.

func (*Time) BinaryOp

func (o *Time) BinaryOp(_ *gad.VM, tok token.Token,
	right gad.Object) (gad.Object, error)

BinaryOp implements gad.Object interface.

func (*Time) CallName

func (o *Time) CallName(name string, c gad.Call) (gad.Object, error)

func (*Time) Equal

func (o *Time) Equal(right gad.Object) bool

Equal implements gad.Object interface.

func (*Time) IndexGet

func (o *Time) IndexGet(_ *gad.VM, index gad.Object) (gad.Object, error)

IndexGet implements gad.Object interface.

func (*Time) IsFalsy

func (o *Time) IsFalsy() bool

IsFalsy implements gad.Object interface.

func (*Time) MarshalBinary

func (o *Time) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler interface.

func (*Time) MarshalJSON

func (o *Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.JSONMarshaler interface.

func (*Time) ToString

func (o *Time) ToString() string

ToString implements gad.Object interface.

func (*Time) Type

func (*Time) Type() gad.ObjectType

func (*Time) UnmarshalBinary

func (o *Time) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler interface.

func (*Time) UnmarshalJSON

func (o *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.JSONUnmarshaler interface.

Jump to

Keyboard shortcuts

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