1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00

Date() => string (Not an object)

This commit is contained in:
Robert Krimen 2013-04-20 18:59:58 -07:00
parent 345c4705f9
commit 7624bc44fe
2 changed files with 9 additions and 0 deletions

View File

@ -7,6 +7,12 @@ import (
// Date
func builtinDate(call FunctionCall) Value {
if len(call.ArgumentList) == 0 {
// Should make this prettier
date := &_dateObject{}
date.Set(newDateTime([]Value{}))
return toValue(date.Time().Format(time_.RFC1123))
}
return toValue(call.runtime.newDate(newDateTime(call.ArgumentList)))
}

View File

@ -89,6 +89,9 @@ func TestDate(t *testing.T) {
test(`abc = new Date(12564504e5); abc.setFullYear(2010); abc.toUTCString()`, time.Format(format))
test(`new Date("2001-01-01T10:01:02.000").getTime()`, "978343262000")
// Date()
test(`typeof Date()`, "string")
}
func TestDate_parse(t *testing.T) {