[#6688] added optional timezone identifier argument to the JSVM DateTime constructor

This commit is contained in:
Gani Georgiev
2025-04-08 14:16:53 +03:00
parent 5d32d22ff5
commit 0efbbb0d10
5 changed files with 3378 additions and 3324 deletions

View File

@@ -548,9 +548,18 @@ func baseBinds(vm *goja.Runtime) {
vm.Set("DateTime", func(call goja.ConstructorCall) *goja.Object {
instance := types.NowDateTime()
val, _ := call.Argument(0).Export().(string)
if val != "" {
instance, _ = types.ParseDateTime(val)
rawDate, _ := call.Argument(0).Export().(string)
locName, _ := call.Argument(1).Export().(string)
if rawDate != "" && locName != "" {
loc, err := time.LoadLocation(locName)
if err != nil {
loc = time.UTC
}
instance, _ = types.ParseDateTime(cast.ToTimeInDefaultLocation(rawDate, loc))
} else if rawDate != "" {
// forward directly to ParseDateTime to preserve the original behavior
instance, _ = types.ParseDateTime(rawDate)
}
instanceValue := vm.ToValue(instance).(*goja.Object)