package goja

import (
	
	
	
	
)

func ( *Runtime) ( []Value,  bool) ( time.Time,  bool) {
	switch {
	case len() >= 2:
		 = time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)
		,  = _dateSetYear(, FunctionCall{Arguments: }, 0, )
	case len() == 0:
		 = .now()
		 = true
	default: // one argument
		if ,  := [0].(*Object);  {
			if ,  := .self.(*dateObject);  {
				 = .time()
				 = true
			}
		}
		if ! {
			 := toPrimitive([0])
			if ,  := .(String);  {
				return dateParse(.String())
			}
			 = .ToNumber()
			var  int64
			if ,  := .(valueInt);  {
				 = int64()
			} else if ,  := .(valueFloat);  {
				 := float64()
				if math.IsNaN() || math.IsInf(, 0) {
					return
				}
				if math.Abs() > maxTime {
					return
				}
				 = int64()
			} else {
				 = .ToInteger()
			}
			 = timeFromMsec()
			 = true
		}
	}
	if  {
		 := .Unix()*1000 + int64(.Nanosecond()/1e6)
		if  < 0 {
			 = -
		}
		if  > maxTime {
			 = false
		}
	}
	return
}

func ( *Runtime) ( []Value,  *Object) *Object {
	,  := .makeDate(, false)
	return .newDateObject(, , )
}

func ( *Runtime) ( []Value,  *Object) *Object {
	return .newDateTime(, )
}

func ( *Runtime) (FunctionCall) Value {
	return asciiString(dateFormat(.now()))
}

func ( *Runtime) ( FunctionCall) Value {
	,  := dateParse(.Argument(0).toString().String())
	if  {
		return intToValue(timeToMsec())
	}
	return _NaN
}

func ( *Runtime) ( FunctionCall) Value {
	var  []Value
	if len(.Arguments) < 2 {
		 = []Value{.Argument(0), _positiveZero}
	} else {
		 = .Arguments
	}
	,  := .makeDate(, true)
	if ! {
		return _NaN
	}
	return intToValue(timeToMsec())
}

func ( *Runtime) (FunctionCall) Value {
	return intToValue(timeToMsec(.now()))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return asciiString(.time().Format(dateTimeLayout))
		} else {
			return stringInvalidDate
		}
	}
	panic(.NewTypeError("Method Date.prototype.toString is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return asciiString(.timeUTC().Format(utcDateTimeLayout))
		} else {
			return stringInvalidDate
		}
	}
	panic(.NewTypeError("Method Date.prototype.toUTCString is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			 := .timeUTC()
			 := .Year()
			if  >= -9999 &&  <= 9999 {
				return asciiString(.Format(isoDateTimeLayout))
			}
			// extended year
			return asciiString(fmt.Sprintf("%+06d-", ) + .Format(isoDateTimeLayout[5:]))
		} else {
			panic(.newError(.getRangeError(), "Invalid time value"))
		}
	}
	panic(.NewTypeError("Method Date.prototype.toISOString is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .This.ToObject()
	 := .toPrimitiveNumber()
	if ,  := .(valueFloat);  {
		 := float64()
		if math.IsNaN() || math.IsInf(, 0) {
			return _null
		}
	}

	if ,  := .self.getStr("toISOString", nil).(*Object);  {
		if ,  := .self.assertCallable();  {
			return (FunctionCall{
				This: ,
			})
		}
	}

	panic(.NewTypeError("toISOString is not a function"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	 := .Argument(0)

	if asciiString("string").StrictEquals() || asciiString("default").StrictEquals() {
		return .ordinaryToPrimitiveString()
	}
	if asciiString("number").StrictEquals() {
		return .ordinaryToPrimitiveNumber()
	}
	panic(.NewTypeError("Invalid hint: %s", ))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return asciiString(.time().Format(dateLayout))
		} else {
			return stringInvalidDate
		}
	}
	panic(.NewTypeError("Method Date.prototype.toDateString is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return asciiString(.time().Format(timeLayout))
		} else {
			return stringInvalidDate
		}
	}
	panic(.NewTypeError("Method Date.prototype.toTimeString is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return asciiString(.time().Format(datetimeLayout_en_GB))
		} else {
			return stringInvalidDate
		}
	}
	panic(.NewTypeError("Method Date.prototype.toLocaleString is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return asciiString(.time().Format(dateLayout_en_GB))
		} else {
			return stringInvalidDate
		}
	}
	panic(.NewTypeError("Method Date.prototype.toLocaleDateString is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return asciiString(.time().Format(timeLayout_en_GB))
		} else {
			return stringInvalidDate
		}
	}
	panic(.NewTypeError("Method Date.prototype.toLocaleTimeString is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(.msec)
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.valueOf is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(.msec)
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getTime is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.time().Year()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getFullYear is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.timeUTC().Year()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getUTCFullYear is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.time().Month()) - 1)
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getMonth is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.timeUTC().Month()) - 1)
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getUTCMonth is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.time().Hour()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getHours is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.timeUTC().Hour()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getUTCHours is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.time().Day()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getDate is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.timeUTC().Day()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getUTCDate is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.time().Weekday()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getDay is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.timeUTC().Weekday()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getUTCDay is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.time().Minute()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getMinutes is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.timeUTC().Minute()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getUTCMinutes is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.time().Second()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getSeconds is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.timeUTC().Second()))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getUTCSeconds is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.time().Nanosecond() / 1e6))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getMilliseconds is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			return intToValue(int64(.timeUTC().Nanosecond() / 1e6))
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getUTCMilliseconds is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		if .isSet() {
			,  := .time().Zone()
			return floatToValue(float64(-) / 60)
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.getTimezoneOffset is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		 := .Argument(0).ToNumber()
		if IsNaN() {
			.unset()
			return _NaN
		}
		return .setTimeMs(.ToInteger())
	}
	panic(.NewTypeError("Method Date.prototype.setTime is called on incompatible receiver"))
}

// _norm returns nhi, nlo such that
//
//	hi * base + lo == nhi * base + nlo
//	0 <= nlo < base
func _norm(, ,  int64) (,  int64,  bool) {
	if  < 0 {
		if  == math.MinInt64 &&  <= - {
			// underflow
			 = false
			return
		}
		 := (--1)/ + 1
		 -= 
		 +=  * 
	}
	if  >=  {
		if  == math.MaxInt64 {
			// overflow
			 = false
			return
		}
		 :=  / 
		 += 
		 -=  * 
	}
	return , , true
}

func mkTime(, , , , , ,  int64,  *time.Location) ( time.Time,  bool) {
	, ,  = _norm(, , 12)
	if ! {
		return
	}

	// Normalise nsec, sec, min, hour, overflowing into day.
	, ,  = _norm(, , 1e9)
	if ! {
		return
	}
	, ,  = _norm(, , 60)
	if ! {
		return
	}
	, ,  = _norm(, , 60)
	if ! {
		return
	}
	, ,  = _norm(, , 24)
	if ! {
		return
	}
	if  > math.MaxInt32 ||  < math.MinInt32 ||
		 > math.MaxInt32 ||  < math.MinInt32 ||
		 >= math.MaxInt32 ||  < math.MinInt32-1 {
		return time.Time{}, false
	}
	 := time.Month() + 1
	return time.Date(int(), , int(), int(), int(), int(), int(), ), true
}

func _intArg( FunctionCall,  int) (int64, bool) {
	 := .Argument().ToNumber()
	if IsNaN() {
		return 0, false
	}
	return .ToInteger(), true
}

func _dateSetYear( time.Time,  FunctionCall,  int,  bool) (time.Time, bool) {
	var  int64
	if  == 0 ||  > 0 &&  < len(.Arguments) {
		var  bool
		,  = _intArg(, )
		if ! {
			return time.Time{}, false
		}
		if  >= 0 &&  <= 99 {
			 += 1900
		}
	} else {
		 = int64(.Year())
	}

	return _dateSetMonth(, , , +1, )
}

func _dateSetFullYear( time.Time,  FunctionCall,  int,  bool) (time.Time, bool) {
	var  int64
	if  == 0 ||  > 0 &&  < len(.Arguments) {
		var  bool
		,  = _intArg(, )
		if ! {
			return time.Time{}, false
		}
	} else {
		 = int64(.Year())
	}
	return _dateSetMonth(, , , +1, )
}

func _dateSetMonth( int64,  time.Time,  FunctionCall,  int,  bool) (time.Time, bool) {
	var  int64
	if  == 0 ||  > 0 &&  < len(.Arguments) {
		var  bool
		,  = _intArg(, )
		if ! {
			return time.Time{}, false
		}
	} else {
		 = int64(.Month()) - 1
	}

	return _dateSetDay(, , , , +1, )
}

func _dateSetDay(,  int64,  time.Time,  FunctionCall,  int,  bool) (time.Time, bool) {
	var  int64
	if  == 0 ||  > 0 &&  < len(.Arguments) {
		var  bool
		,  = _intArg(, )
		if ! {
			return time.Time{}, false
		}
	} else {
		 = int64(.Day())
	}

	return _dateSetHours(, , , , , +1, )
}

func _dateSetHours(, ,  int64,  time.Time,  FunctionCall,  int,  bool) (time.Time, bool) {
	var  int64
	if  == 0 ||  > 0 &&  < len(.Arguments) {
		var  bool
		,  = _intArg(, )
		if ! {
			return time.Time{}, false
		}
	} else {
		 = int64(.Hour())
	}
	return _dateSetMinutes(, , , , , , +1, )
}

func _dateSetMinutes(, , ,  int64,  time.Time,  FunctionCall,  int,  bool) (time.Time, bool) {
	var  int64
	if  == 0 ||  > 0 &&  < len(.Arguments) {
		var  bool
		,  = _intArg(, )
		if ! {
			return time.Time{}, false
		}
	} else {
		 = int64(.Minute())
	}
	return _dateSetSeconds(, , , , , , , +1, )
}

func _dateSetSeconds(, , , ,  int64,  time.Time,  FunctionCall,  int,  bool) (time.Time, bool) {
	var  int64
	if  == 0 ||  > 0 &&  < len(.Arguments) {
		var  bool
		,  = _intArg(, )
		if ! {
			return time.Time{}, false
		}
	} else {
		 = int64(.Second())
	}
	return _dateSetMilliseconds(, , , , , , , , +1, )
}

func _dateSetMilliseconds(, , , , ,  int64,  time.Time,  FunctionCall,  int,  bool) (time.Time, bool) {
	var  int64
	if  == 0 ||  > 0 &&  < len(.Arguments) {
		var  bool
		,  = _intArg(, )
		if ! {
			return time.Time{}, false
		}
	} else {
		 = int64(.Nanosecond() / 1e6)
	}
	var  bool
	, ,  = _norm(, , 1e3)
	if ! {
		return time.Time{}, false
	}

	var  *time.Location
	if  {
		 = time.UTC
	} else {
		 = time.Local
	}
	,  := mkTime(, , , , , , *1e6, )
	if ! {
		return time.Time{}, false
	}
	if  {
		return .In(time.Local), true
	}
	return , true
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		 := .Argument(0).ToNumber()
		if IsNaN() {
			.unset()
			return _NaN
		}
		 := .ToInteger()
		 := .msec / 1e3
		var  bool
		, ,  = _norm(, , 1e3)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(*1e3 + )
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setMilliseconds is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		 := .Argument(0).ToNumber()
		if IsNaN() {
			.unset()
			return _NaN
		}
		 := .ToInteger()
		 := .msec / 1e3
		var  bool
		, ,  = _norm(, , 1e3)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(*1e3 + )
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setUTCMilliseconds is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.time(), , -5, false)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setSeconds is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.timeUTC(), , -5, true)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setUTCSeconds is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.time(), , -4, false)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setMinutes is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.timeUTC(), , -4, true)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setUTCMinutes is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.time(), , -3, false)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setHours is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.timeUTC(), , -3, true)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setUTCHours is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.time(), limitCallArgs(, 1), -2, false)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setDate is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.timeUTC(), limitCallArgs(, 1), -2, true)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setUTCDate is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.time(), limitCallArgs(, 2), -1, false)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setMonth is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		,  := _dateSetFullYear(.timeUTC(), limitCallArgs(, 2), -1, true)
		if ! {
			.unset()
			return _NaN
		}
		if .isSet() {
			return .setTimeMs(timeToMsec())
		} else {
			return _NaN
		}
	}
	panic(.NewTypeError("Method Date.prototype.setUTCMonth is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		var  time.Time
		if .isSet() {
			 = .time()
		} else {
			 = time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)
		}
		,  := _dateSetFullYear(, limitCallArgs(, 3), 0, false)
		if ! {
			.unset()
			return _NaN
		}
		return .setTimeMs(timeToMsec())
	}
	panic(.NewTypeError("Method Date.prototype.setFullYear is called on incompatible receiver"))
}

func ( *Runtime) ( FunctionCall) Value {
	 := .toObject(.This)
	if ,  := .self.(*dateObject);  {
		var  time.Time
		if .isSet() {
			 = .timeUTC()
		} else {
			 = time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC)
		}
		,  := _dateSetFullYear(, limitCallArgs(, 3), 0, true)
		if ! {
			.unset()
			return _NaN
		}
		return .setTimeMs(timeToMsec())
	}
	panic(.NewTypeError("Method Date.prototype.setUTCFullYear is called on incompatible receiver"))
}

var dateTemplate *objectTemplate
var dateTemplateOnce sync.Once

func getDateTemplate() *objectTemplate {
	dateTemplateOnce.Do(func() {
		dateTemplate = createDateTemplate()
	})
	return dateTemplate
}

func createDateTemplate() *objectTemplate {
	 := newObjectTemplate()
	.protoFactory = func( *Runtime) *Object {
		return .getFunctionPrototype()
	}

	.putStr("name", func( *Runtime) Value { return valueProp(asciiString("Date"), false, false, true) })
	.putStr("length", func( *Runtime) Value { return valueProp(intToValue(7), false, false, true) })

	.putStr("prototype", func( *Runtime) Value { return valueProp(.getDatePrototype(), false, false, false) })

	.putStr("parse", func( *Runtime) Value { return .methodProp(.date_parse, "parse", 1) })
	.putStr("UTC", func( *Runtime) Value { return .methodProp(.date_UTC, "UTC", 7) })
	.putStr("now", func( *Runtime) Value { return .methodProp(.date_now, "now", 0) })

	return 
}

func ( *Runtime) () *Object {
	 := .global.Date
	if  == nil {
		 = &Object{runtime: }
		.global.Date = 
		.newTemplatedFuncObject(getDateTemplate(), , .builtin_date,
			.wrapNativeConstruct(.builtin_newDate, , .getDatePrototype()))
	}
	return 
}

func createDateProtoTemplate() *objectTemplate {
	 := newObjectTemplate()
	.protoFactory = func( *Runtime) *Object {
		return .global.ObjectPrototype
	}

	.putStr("constructor", func( *Runtime) Value { return valueProp(.getDate(), true, false, true) })

	.putStr("toString", func( *Runtime) Value { return .methodProp(.dateproto_toString, "toString", 0) })
	.putStr("toDateString", func( *Runtime) Value { return .methodProp(.dateproto_toDateString, "toDateString", 0) })
	.putStr("toTimeString", func( *Runtime) Value { return .methodProp(.dateproto_toTimeString, "toTimeString", 0) })
	.putStr("toLocaleString", func( *Runtime) Value { return .methodProp(.dateproto_toLocaleString, "toLocaleString", 0) })
	.putStr("toLocaleDateString", func( *Runtime) Value { return .methodProp(.dateproto_toLocaleDateString, "toLocaleDateString", 0) })
	.putStr("toLocaleTimeString", func( *Runtime) Value { return .methodProp(.dateproto_toLocaleTimeString, "toLocaleTimeString", 0) })
	.putStr("valueOf", func( *Runtime) Value { return .methodProp(.dateproto_valueOf, "valueOf", 0) })
	.putStr("getTime", func( *Runtime) Value { return .methodProp(.dateproto_getTime, "getTime", 0) })
	.putStr("getFullYear", func( *Runtime) Value { return .methodProp(.dateproto_getFullYear, "getFullYear", 0) })
	.putStr("getUTCFullYear", func( *Runtime) Value { return .methodProp(.dateproto_getUTCFullYear, "getUTCFullYear", 0) })
	.putStr("getMonth", func( *Runtime) Value { return .methodProp(.dateproto_getMonth, "getMonth", 0) })
	.putStr("getUTCMonth", func( *Runtime) Value { return .methodProp(.dateproto_getUTCMonth, "getUTCMonth", 0) })
	.putStr("getDate", func( *Runtime) Value { return .methodProp(.dateproto_getDate, "getDate", 0) })
	.putStr("getUTCDate", func( *Runtime) Value { return .methodProp(.dateproto_getUTCDate, "getUTCDate", 0) })
	.putStr("getDay", func( *Runtime) Value { return .methodProp(.dateproto_getDay, "getDay", 0) })
	.putStr("getUTCDay", func( *Runtime) Value { return .methodProp(.dateproto_getUTCDay, "getUTCDay", 0) })
	.putStr("getHours", func( *Runtime) Value { return .methodProp(.dateproto_getHours, "getHours", 0) })
	.putStr("getUTCHours", func( *Runtime) Value { return .methodProp(.dateproto_getUTCHours, "getUTCHours", 0) })
	.putStr("getMinutes", func( *Runtime) Value { return .methodProp(.dateproto_getMinutes, "getMinutes", 0) })
	.putStr("getUTCMinutes", func( *Runtime) Value { return .methodProp(.dateproto_getUTCMinutes, "getUTCMinutes", 0) })
	.putStr("getSeconds", func( *Runtime) Value { return .methodProp(.dateproto_getSeconds, "getSeconds", 0) })
	.putStr("getUTCSeconds", func( *Runtime) Value { return .methodProp(.dateproto_getUTCSeconds, "getUTCSeconds", 0) })
	.putStr("getMilliseconds", func( *Runtime) Value { return .methodProp(.dateproto_getMilliseconds, "getMilliseconds", 0) })
	.putStr("getUTCMilliseconds", func( *Runtime) Value { return .methodProp(.dateproto_getUTCMilliseconds, "getUTCMilliseconds", 0) })
	.putStr("getTimezoneOffset", func( *Runtime) Value { return .methodProp(.dateproto_getTimezoneOffset, "getTimezoneOffset", 0) })
	.putStr("setTime", func( *Runtime) Value { return .methodProp(.dateproto_setTime, "setTime", 1) })
	.putStr("setMilliseconds", func( *Runtime) Value { return .methodProp(.dateproto_setMilliseconds, "setMilliseconds", 1) })
	.putStr("setUTCMilliseconds", func( *Runtime) Value { return .methodProp(.dateproto_setUTCMilliseconds, "setUTCMilliseconds", 1) })
	.putStr("setSeconds", func( *Runtime) Value { return .methodProp(.dateproto_setSeconds, "setSeconds", 2) })
	.putStr("setUTCSeconds", func( *Runtime) Value { return .methodProp(.dateproto_setUTCSeconds, "setUTCSeconds", 2) })
	.putStr("setMinutes", func( *Runtime) Value { return .methodProp(.dateproto_setMinutes, "setMinutes", 3) })
	.putStr("setUTCMinutes", func( *Runtime) Value { return .methodProp(.dateproto_setUTCMinutes, "setUTCMinutes", 3) })
	.putStr("setHours", func( *Runtime) Value { return .methodProp(.dateproto_setHours, "setHours", 4) })
	.putStr("setUTCHours", func( *Runtime) Value { return .methodProp(.dateproto_setUTCHours, "setUTCHours", 4) })
	.putStr("setDate", func( *Runtime) Value { return .methodProp(.dateproto_setDate, "setDate", 1) })
	.putStr("setUTCDate", func( *Runtime) Value { return .methodProp(.dateproto_setUTCDate, "setUTCDate", 1) })
	.putStr("setMonth", func( *Runtime) Value { return .methodProp(.dateproto_setMonth, "setMonth", 2) })
	.putStr("setUTCMonth", func( *Runtime) Value { return .methodProp(.dateproto_setUTCMonth, "setUTCMonth", 2) })
	.putStr("setFullYear", func( *Runtime) Value { return .methodProp(.dateproto_setFullYear, "setFullYear", 3) })
	.putStr("setUTCFullYear", func( *Runtime) Value { return .methodProp(.dateproto_setUTCFullYear, "setUTCFullYear", 3) })
	.putStr("toUTCString", func( *Runtime) Value { return .methodProp(.dateproto_toUTCString, "toUTCString", 0) })
	.putStr("toISOString", func( *Runtime) Value { return .methodProp(.dateproto_toISOString, "toISOString", 0) })
	.putStr("toJSON", func( *Runtime) Value { return .methodProp(.dateproto_toJSON, "toJSON", 1) })

	.putSym(SymToPrimitive, func( *Runtime) Value {
		return valueProp(.newNativeFunc(.dateproto_toPrimitive, "[Symbol.toPrimitive]", 1), false, false, true)
	})

	return 
}

var dateProtoTemplate *objectTemplate
var dateProtoTemplateOnce sync.Once

func getDateProtoTemplate() *objectTemplate {
	dateProtoTemplateOnce.Do(func() {
		dateProtoTemplate = createDateProtoTemplate()
	})
	return dateProtoTemplate
}

func ( *Runtime) () *Object {
	 := .global.DatePrototype
	if  == nil {
		 = &Object{runtime: }
		.global.DatePrototype = 
		.newTemplatedObject(getDateProtoTemplate(), )
	}
	return 
}