#549·otto

Issues with parsing Go time.Time fields

Author: leonoreCreated Jun 26, 2025Updated Jun 26, 2025

The package seems to suggest it supports go time.Time objects and parsing them into Javascript dates, however with a minimal working example this doesn't seem to work:

	vm := otto.New()

	vm.Set("subject", time.Date(2024, 1, 15, 10, 30, 45, 0, time.UTC))
	value, err := vm.Run(`
	console.log("The value of subject is " + typeof(subject));
	console.log("The subject is " + subject.toISOString());
	subject;
	`)
	if err != nil {
		return err
	}
	spew.Dump(value)

outputs:

The value of subject is object
TypeError: "toISOString" is not a function