Rhino.NativeDate.ExecIdCall C# (CSharp) Method

ExecIdCall() public method

public ExecIdCall ( IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, object args ) : object
f IdFunctionObject
cx Context
scope Scriptable
thisObj Scriptable
args object
return object
		public override object ExecIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, object[] args)
		{
			if (!f.HasTag(DATE_TAG))
			{
				return base.ExecIdCall(f, cx, scope, thisObj, args);
			}
			int id = f.MethodId();
			switch (id)
			{
				case ConstructorId_now:
				{
					return ScriptRuntime.WrapNumber(Now());
				}

				case ConstructorId_parse:
				{
					string dataStr = ScriptRuntime.ToString(args, 0);
					return ScriptRuntime.WrapNumber(Date_parseString(dataStr));
				}

				case ConstructorId_UTC:
				{
					return ScriptRuntime.WrapNumber(JsStaticFunction_UTC(args));
				}

				case Id_constructor:
				{
					// if called as a function, just return a string
					// representing the current time.
					if (thisObj != null)
					{
						return Date_format(Now(), Id_toString);
					}
					return JsConstructor(args);
				}

				case Id_toJSON:
				{
					if (thisObj is Rhino.NativeDate)
					{
						return ((Rhino.NativeDate)thisObj).ToISOString();
					}
					string toISOString = "toISOString";
					Scriptable o = ScriptRuntime.ToObject(cx, scope, thisObj);
					object tv = ScriptRuntime.ToPrimitive(o, ScriptRuntime.NumberClass);
					if (tv is Number)
					{
						double d = System.Convert.ToDouble(((Number)tv));
						if (d != d || System.Double.IsInfinity(d))
						{
							return null;
						}
					}
					object toISO = o.Get(toISOString, o);
					if (toISO == ScriptableConstants.NOT_FOUND)
					{
						throw ScriptRuntime.TypeError2("msg.function.not.found.in", toISOString, ScriptRuntime.ToString(o));
					}
					if (!(toISO is Callable))
					{
						throw ScriptRuntime.TypeError3("msg.isnt.function.in", toISOString, ScriptRuntime.ToString(o), ScriptRuntime.ToString(toISO));
					}
					object result = ((Callable)toISO).Call(cx, scope, o, ScriptRuntime.emptyArgs);
					if (!ScriptRuntime.IsPrimitive(result))
					{
						throw ScriptRuntime.TypeError1("msg.toisostring.must.return.primitive", ScriptRuntime.ToString(result));
					}
					return result;
				}
			}
			// The rest of Date.prototype methods require thisObj to be Date
			if (!(thisObj is Rhino.NativeDate))
			{
				throw IncompatibleCallError(f);
			}
			Rhino.NativeDate realThis = (Rhino.NativeDate)thisObj;
			double t = realThis.date;
			switch (id)
			{
				case Id_toString:
				case Id_toTimeString:
				case Id_toDateString:
				{
					if (t == t)
					{
						return Date_format(t, id);
					}
					return js_NaN_date_str;
				}

				case Id_toLocaleString:
				case Id_toLocaleTimeString:
				case Id_toLocaleDateString:
				{
					if (t == t)
					{
						return ToLocale_helper(t, id);
					}
					return js_NaN_date_str;
				}

				case Id_toUTCString:
				{
					if (t == t)
					{
						return Js_toUTCString(t);
					}
					return js_NaN_date_str;
				}

				case Id_toSource:
				{
					return "(new Date(" + ScriptRuntime.ToString(t) + "))";
				}

				case Id_valueOf:
				case Id_getTime:
				{
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getYear:
				case Id_getFullYear:
				case Id_getUTCFullYear:
				{
					if (t == t)
					{
						if (id != Id_getUTCFullYear)
						{
							t = LocalTime(t);
						}
						t = YearFromTime(t);
						if (id == Id_getYear)
						{
							if (cx.HasFeature(Context.FEATURE_NON_ECMA_GET_YEAR))
							{
								if (1900 <= t && t < 2000)
								{
									t -= 1900;
								}
							}
							else
							{
								t -= 1900;
							}
						}
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getMonth:
				case Id_getUTCMonth:
				{
					if (t == t)
					{
						if (id == Id_getMonth)
						{
							t = LocalTime(t);
						}
						t = MonthFromTime(t);
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getDate:
				case Id_getUTCDate:
				{
					if (t == t)
					{
						if (id == Id_getDate)
						{
							t = LocalTime(t);
						}
						t = DateFromTime(t);
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getDay:
				case Id_getUTCDay:
				{
					if (t == t)
					{
						if (id == Id_getDay)
						{
							t = LocalTime(t);
						}
						t = WeekDay(t);
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getHours:
				case Id_getUTCHours:
				{
					if (t == t)
					{
						if (id == Id_getHours)
						{
							t = LocalTime(t);
						}
						t = HourFromTime(t);
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getMinutes:
				case Id_getUTCMinutes:
				{
					if (t == t)
					{
						if (id == Id_getMinutes)
						{
							t = LocalTime(t);
						}
						t = MinFromTime(t);
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getSeconds:
				case Id_getUTCSeconds:
				{
					if (t == t)
					{
						if (id == Id_getSeconds)
						{
							t = LocalTime(t);
						}
						t = SecFromTime(t);
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getMilliseconds:
				case Id_getUTCMilliseconds:
				{
					if (t == t)
					{
						if (id == Id_getMilliseconds)
						{
							t = LocalTime(t);
						}
						t = MsFromTime(t);
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_getTimezoneOffset:
				{
					if (t == t)
					{
						t = (t - LocalTime(t)) / msPerMinute;
					}
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_setTime:
				{
					t = TimeClip(ScriptRuntime.ToNumber(args, 0));
					realThis.date = t;
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_setMilliseconds:
				case Id_setUTCMilliseconds:
				case Id_setSeconds:
				case Id_setUTCSeconds:
				case Id_setMinutes:
				case Id_setUTCMinutes:
				case Id_setHours:
				case Id_setUTCHours:
				{
					t = MakeTime(t, args, id);
					realThis.date = t;
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_setDate:
				case Id_setUTCDate:
				case Id_setMonth:
				case Id_setUTCMonth:
				case Id_setFullYear:
				case Id_setUTCFullYear:
				{
					t = MakeDate(t, args, id);
					realThis.date = t;
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_setYear:
				{
					double year = ScriptRuntime.ToNumber(args, 0);
					if (year != year || System.Double.IsInfinity(year))
					{
						t = ScriptRuntime.NaN;
					}
					else
					{
						if (t != t)
						{
							t = 0;
						}
						else
						{
							t = LocalTime(t);
						}
						if (year >= 0 && year <= 99)
						{
							year += 1900;
						}
						double day = MakeDay(year, MonthFromTime(t), DateFromTime(t));
						t = MakeDate(day, TimeWithinDay(t));
						t = InternalUTC(t);
						t = TimeClip(t);
					}
					realThis.date = t;
					return ScriptRuntime.WrapNumber(t);
				}

				case Id_toISOString:
				{
					return realThis.ToISOString();
				}

				default:
				{
					throw new ArgumentException(id.ToString());
				}
			}
		}