@@ -472,9 +472,27 @@ var Builtins = []*Function{
472472 {
473473 Name : "now" ,
474474 Func : func (args ... any ) (any , error ) {
475- return time .Now (), nil
475+ if len (args ) == 0 {
476+ return time .Now (), nil
477+ }
478+ if len (args ) == 1 {
479+ if tz , ok := args [0 ].(* time.Location ); ok {
480+ return time .Now ().In (tz ), nil
481+ }
482+ }
483+ return nil , fmt .Errorf ("invalid number of arguments (expected 0, got %d)" , len (args ))
484+ },
485+ Validate : func (args []reflect.Type ) (reflect.Type , error ) {
486+ if len (args ) == 0 {
487+ return timeType , nil
488+ }
489+ if len (args ) == 1 {
490+ if args [0 ].AssignableTo (locationType ) {
491+ return timeType , nil
492+ }
493+ }
494+ return anyType , fmt .Errorf ("invalid number of arguments (expected 0, got %d)" , len (args ))
476495 },
477- Types : types (new (func () time.Time )),
478496 },
479497 {
480498 Name : "duration" ,
@@ -486,9 +504,17 @@ var Builtins = []*Function{
486504 {
487505 Name : "date" ,
488506 Func : func (args ... any ) (any , error ) {
507+ tz , ok := args [0 ].(* time.Location )
508+ if ok {
509+ args = args [1 :]
510+ }
511+
489512 date := args [0 ].(string )
490513 if len (args ) == 2 {
491514 layout := args [1 ].(string )
515+ if tz != nil {
516+ return time .ParseInLocation (layout , date , tz )
517+ }
492518 return time .Parse (layout , date )
493519 }
494520 if len (args ) == 3 {
@@ -516,18 +542,32 @@ var Builtins = []*Function{
516542 time .RFC1123 ,
517543 }
518544 for _ , layout := range layouts {
519- t , err := time .Parse (layout , date )
520- if err == nil {
521- return t , nil
545+ if tz == nil {
546+ t , err := time .Parse (layout , date )
547+ if err == nil {
548+ return t , nil
549+ }
550+ } else {
551+ t , err := time .ParseInLocation (layout , date , tz )
552+ if err == nil {
553+ return t , nil
554+ }
522555 }
523556 }
524557 return nil , fmt .Errorf ("invalid date %s" , date )
525558 },
526- Types : types (
527- new (func (string ) time.Time ),
528- new (func (string , string ) time.Time ),
529- new (func (string , string , string ) time.Time ),
530- ),
559+ Validate : func (args []reflect.Type ) (reflect.Type , error ) {
560+ if len (args ) < 1 {
561+ return anyType , fmt .Errorf ("invalid number of arguments (expected at least 1, got %d)" , len (args ))
562+ }
563+ if args [0 ].AssignableTo (locationType ) {
564+ args = args [1 :]
565+ }
566+ if len (args ) > 3 {
567+ return anyType , fmt .Errorf ("invalid number of arguments (expected at most 3, got %d)" , len (args ))
568+ }
569+ return timeType , nil
570+ },
531571 },
532572 {
533573 Name : "timezone" ,
0 commit comments