1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135 |
- package stdlib
- import (
- "time"
- "github.com/d5/tengo/v2"
- )
- var timesModule = map[string]tengo.Object{
- "format_ansic": &tengo.String{Value: time.ANSIC},
- "format_unix_date": &tengo.String{Value: time.UnixDate},
- "format_ruby_date": &tengo.String{Value: time.RubyDate},
- "format_rfc822": &tengo.String{Value: time.RFC822},
- "format_rfc822z": &tengo.String{Value: time.RFC822Z},
- "format_rfc850": &tengo.String{Value: time.RFC850},
- "format_rfc1123": &tengo.String{Value: time.RFC1123},
- "format_rfc1123z": &tengo.String{Value: time.RFC1123Z},
- "format_rfc3339": &tengo.String{Value: time.RFC3339},
- "format_rfc3339_nano": &tengo.String{Value: time.RFC3339Nano},
- "format_kitchen": &tengo.String{Value: time.Kitchen},
- "format_stamp": &tengo.String{Value: time.Stamp},
- "format_stamp_milli": &tengo.String{Value: time.StampMilli},
- "format_stamp_micro": &tengo.String{Value: time.StampMicro},
- "format_stamp_nano": &tengo.String{Value: time.StampNano},
- "nanosecond": tengo.Int{Value: int64(time.Nanosecond)},
- "microsecond": tengo.Int{Value: int64(time.Microsecond)},
- "millisecond": tengo.Int{Value: int64(time.Millisecond)},
- "second": tengo.Int{Value: int64(time.Second)},
- "minute": tengo.Int{Value: int64(time.Minute)},
- "hour": tengo.Int{Value: int64(time.Hour)},
- "january": tengo.Int{Value: int64(time.January)},
- "february": tengo.Int{Value: int64(time.February)},
- "march": tengo.Int{Value: int64(time.March)},
- "april": tengo.Int{Value: int64(time.April)},
- "may": tengo.Int{Value: int64(time.May)},
- "june": tengo.Int{Value: int64(time.June)},
- "july": tengo.Int{Value: int64(time.July)},
- "august": tengo.Int{Value: int64(time.August)},
- "september": tengo.Int{Value: int64(time.September)},
- "october": tengo.Int{Value: int64(time.October)},
- "november": tengo.Int{Value: int64(time.November)},
- "december": tengo.Int{Value: int64(time.December)},
- "sleep": &tengo.UserFunction{
- Name: "sleep",
- Value: timesSleep,
- }, // sleep(int)
- "parse_duration": &tengo.UserFunction{
- Name: "parse_duration",
- Value: timesParseDuration,
- }, // parse_duration(str) => int
- "since": &tengo.UserFunction{
- Name: "since",
- Value: timesSince,
- }, // since(time) => int
- "until": &tengo.UserFunction{
- Name: "until",
- Value: timesUntil,
- }, // until(time) => int
- "duration_hours": &tengo.UserFunction{
- Name: "duration_hours",
- Value: timesDurationHours,
- }, // duration_hours(int) => float
- "duration_minutes": &tengo.UserFunction{
- Name: "duration_minutes",
- Value: timesDurationMinutes,
- }, // duration_minutes(int) => float
- "duration_nanoseconds": &tengo.UserFunction{
- Name: "duration_nanoseconds",
- Value: timesDurationNanoseconds,
- }, // duration_nanoseconds(int) => int
- "duration_seconds": &tengo.UserFunction{
- Name: "duration_seconds",
- Value: timesDurationSeconds,
- }, // duration_seconds(int) => float
- "duration_string": &tengo.UserFunction{
- Name: "duration_string",
- Value: timesDurationString,
- }, // duration_string(int) => string
- "month_string": &tengo.UserFunction{
- Name: "month_string",
- Value: timesMonthString,
- }, // month_string(int) => string
- "date": &tengo.UserFunction{
- Name: "date",
- Value: timesDate,
- }, // date(year, month, day, hour, min, sec, nsec) => time
- "now": &tengo.UserFunction{
- Name: "now",
- Value: timesNow,
- }, // now() => time
- "parse": &tengo.UserFunction{
- Name: "parse",
- Value: timesParse,
- }, // parse(format, str) => time
- "unix": &tengo.UserFunction{
- Name: "unix",
- Value: timesUnix,
- }, // unix(sec, nsec) => time
- "add": &tengo.UserFunction{
- Name: "add",
- Value: timesAdd,
- }, // add(time, int) => time
- "add_date": &tengo.UserFunction{
- Name: "add_date",
- Value: timesAddDate,
- }, // add_date(time, years, months, days) => time
- "sub": &tengo.UserFunction{
- Name: "sub",
- Value: timesSub,
- }, // sub(t time, u time) => int
- "after": &tengo.UserFunction{
- Name: "after",
- Value: timesAfter,
- }, // after(t time, u time) => bool
- "before": &tengo.UserFunction{
- Name: "before",
- Value: timesBefore,
- }, // before(t time, u time) => bool
- "time_year": &tengo.UserFunction{
- Name: "time_year",
- Value: timesTimeYear,
- }, // time_year(time) => int
- "time_month": &tengo.UserFunction{
- Name: "time_month",
- Value: timesTimeMonth,
- }, // time_month(time) => int
- "time_day": &tengo.UserFunction{
- Name: "time_day",
- Value: timesTimeDay,
- }, // time_day(time) => int
- "time_weekday": &tengo.UserFunction{
- Name: "time_weekday",
- Value: timesTimeWeekday,
- }, // time_weekday(time) => int
- "time_hour": &tengo.UserFunction{
- Name: "time_hour",
- Value: timesTimeHour,
- }, // time_hour(time) => int
- "time_minute": &tengo.UserFunction{
- Name: "time_minute",
- Value: timesTimeMinute,
- }, // time_minute(time) => int
- "time_second": &tengo.UserFunction{
- Name: "time_second",
- Value: timesTimeSecond,
- }, // time_second(time) => int
- "time_nanosecond": &tengo.UserFunction{
- Name: "time_nanosecond",
- Value: timesTimeNanosecond,
- }, // time_nanosecond(time) => int
- "time_unix": &tengo.UserFunction{
- Name: "time_unix",
- Value: timesTimeUnix,
- }, // time_unix(time) => int
- "time_unix_nano": &tengo.UserFunction{
- Name: "time_unix_nano",
- Value: timesTimeUnixNano,
- }, // time_unix_nano(time) => int
- "time_format": &tengo.UserFunction{
- Name: "time_format",
- Value: timesTimeFormat,
- }, // time_format(time, format) => string
- "time_location": &tengo.UserFunction{
- Name: "time_location",
- Value: timesTimeLocation,
- }, // time_location(time) => string
- "time_string": &tengo.UserFunction{
- Name: "time_string",
- Value: timesTimeString,
- }, // time_string(time) => string
- "is_zero": &tengo.UserFunction{
- Name: "is_zero",
- Value: timesIsZero,
- }, // is_zero(time) => bool
- "to_local": &tengo.UserFunction{
- Name: "to_local",
- Value: timesToLocal,
- }, // to_local(time) => time
- "to_utc": &tengo.UserFunction{
- Name: "to_utc",
- Value: timesToUTC,
- }, // to_utc(time) => time
- }
- func timesSleep(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt64(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- time.Sleep(time.Duration(i1))
- ret = tengo.UndefinedValue
- return
- }
- func timesParseDuration(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- s1, ok := tengo.ToString(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "string(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- dur, err := time.ParseDuration(s1)
- if err != nil {
- ret = wrapError(err)
- return
- }
- ret = tengo.Int{Value: int64(dur)}
- return
- }
- func timesSince(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(time.Since(t1))}
- return
- }
- func timesUntil(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(time.Until(t1))}
- return
- }
- func timesDurationHours(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt64(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Float{Value: time.Duration(i1).Hours()}
- return
- }
- func timesDurationMinutes(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt64(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Float{Value: time.Duration(i1).Minutes()}
- return
- }
- func timesDurationNanoseconds(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt64(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: time.Duration(i1).Nanoseconds()}
- return
- }
- func timesDurationSeconds(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt64(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Float{Value: time.Duration(i1).Seconds()}
- return
- }
- func timesDurationString(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt64(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = &tengo.String{Value: time.Duration(i1).String()}
- return
- }
- func timesMonthString(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt64(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = &tengo.String{Value: time.Month(i1).String()}
- return
- }
- func timesDate(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 7 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- i2, ok := tengo.ToInt(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "int(compatible)",
- Found: args[1].TypeName(),
- }
- return
- }
- i3, ok := tengo.ToInt(args[2])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "third",
- Expected: "int(compatible)",
- Found: args[2].TypeName(),
- }
- return
- }
- i4, ok := tengo.ToInt(args[3])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "fourth",
- Expected: "int(compatible)",
- Found: args[3].TypeName(),
- }
- return
- }
- i5, ok := tengo.ToInt(args[4])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "fifth",
- Expected: "int(compatible)",
- Found: args[4].TypeName(),
- }
- return
- }
- i6, ok := tengo.ToInt(args[5])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "sixth",
- Expected: "int(compatible)",
- Found: args[5].TypeName(),
- }
- return
- }
- i7, ok := tengo.ToInt(args[6])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "seventh",
- Expected: "int(compatible)",
- Found: args[6].TypeName(),
- }
- return
- }
- ret = &tengo.Time{
- Value: time.Date(i1,
- time.Month(i2), i3, i4, i5, i6, i7, time.Now().Location()),
- }
- return
- }
- func timesNow(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 0 {
- err = tengo.ErrWrongNumArguments
- return
- }
- ret = &tengo.Time{Value: time.Now()}
- return
- }
- func timesParse(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 2 {
- err = tengo.ErrWrongNumArguments
- return
- }
- s1, ok := tengo.ToString(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "string(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- s2, ok := tengo.ToString(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "string(compatible)",
- Found: args[1].TypeName(),
- }
- return
- }
- parsed, err := time.Parse(s1, s2)
- if err != nil {
- ret = wrapError(err)
- return
- }
- ret = &tengo.Time{Value: parsed}
- return
- }
- func timesUnix(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 2 {
- err = tengo.ErrWrongNumArguments
- return
- }
- i1, ok := tengo.ToInt64(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "int(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- i2, ok := tengo.ToInt64(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "int(compatible)",
- Found: args[1].TypeName(),
- }
- return
- }
- ret = &tengo.Time{Value: time.Unix(i1, i2)}
- return
- }
- func timesAdd(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 2 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- i2, ok := tengo.ToInt64(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "int(compatible)",
- Found: args[1].TypeName(),
- }
- return
- }
- ret = &tengo.Time{Value: t1.Add(time.Duration(i2))}
- return
- }
- func timesSub(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 2 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- t2, ok := tengo.ToTime(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "time(compatible)",
- Found: args[1].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Sub(t2))}
- return
- }
- func timesAddDate(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 4 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- i2, ok := tengo.ToInt(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "int(compatible)",
- Found: args[1].TypeName(),
- }
- return
- }
- i3, ok := tengo.ToInt(args[2])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "third",
- Expected: "int(compatible)",
- Found: args[2].TypeName(),
- }
- return
- }
- i4, ok := tengo.ToInt(args[3])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "fourth",
- Expected: "int(compatible)",
- Found: args[3].TypeName(),
- }
- return
- }
- ret = &tengo.Time{Value: t1.AddDate(i2, i3, i4)}
- return
- }
- func timesAfter(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 2 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- t2, ok := tengo.ToTime(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "time(compatible)",
- Found: args[1].TypeName(),
- }
- return
- }
- if t1.After(t2) {
- ret = tengo.TrueValue
- } else {
- ret = tengo.FalseValue
- }
- return
- }
- func timesBefore(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 2 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- t2, ok := tengo.ToTime(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- if t1.Before(t2) {
- ret = tengo.TrueValue
- } else {
- ret = tengo.FalseValue
- }
- return
- }
- func timesTimeYear(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Year())}
- return
- }
- func timesTimeMonth(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Month())}
- return
- }
- func timesTimeDay(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Day())}
- return
- }
- func timesTimeWeekday(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Weekday())}
- return
- }
- func timesTimeHour(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Hour())}
- return
- }
- func timesTimeMinute(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Minute())}
- return
- }
- func timesTimeSecond(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Second())}
- return
- }
- func timesTimeNanosecond(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: int64(t1.Nanosecond())}
- return
- }
- func timesTimeUnix(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: t1.Unix()}
- return
- }
- func timesTimeUnixNano(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = tengo.Int{Value: t1.UnixNano()}
- return
- }
- func timesTimeFormat(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 2 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- s2, ok := tengo.ToString(args[1])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "second",
- Expected: "string(compatible)",
- Found: args[1].TypeName(),
- }
- return
- }
- s := t1.Format(s2)
- if len(s) > tengo.MaxStringLen {
- return nil, tengo.ErrStringLimit
- }
- ret = &tengo.String{Value: s}
- return
- }
- func timesIsZero(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- if t1.IsZero() {
- ret = tengo.TrueValue
- } else {
- ret = tengo.FalseValue
- }
- return
- }
- func timesToLocal(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = &tengo.Time{Value: t1.Local()}
- return
- }
- func timesToUTC(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = &tengo.Time{Value: t1.UTC()}
- return
- }
- func timesTimeLocation(args ...tengo.Object) (
- ret tengo.Object,
- err error,
- ) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = &tengo.String{Value: t1.Location().String()}
- return
- }
- func timesTimeString(args ...tengo.Object) (ret tengo.Object, err error) {
- if len(args) != 1 {
- err = tengo.ErrWrongNumArguments
- return
- }
- t1, ok := tengo.ToTime(args[0])
- if !ok {
- err = tengo.ErrInvalidArgumentType{
- Name: "first",
- Expected: "time(compatible)",
- Found: args[0].TypeName(),
- }
- return
- }
- ret = &tengo.String{Value: t1.String()}
- return
- }
|