internal virtual int get(bool utc, int field) { time.setTimeZone(utc ? Timezone.getTimeZone("GMT") : Timezone.getDefault()); int i = time.get(field); return(field == Calendar.DAY_OF_WEEK ? i - 1 : i); }
internal virtual void setDate(bool utc, double year, double month, double date) { time.setTimeZone(utc ? Timezone.getTimeZone("GMT") : Timezone.getDefault()); if (!Double.IsNaN(year)) { time.set(Calendar.YEAR, (int)year); } if (!Double.IsNaN(month)) { time.set(Calendar.MONTH, (int)month); } if (!Double.IsNaN(date)) { time.set(Calendar.DAY_OF_MONTH, (int)date); } }
internal virtual void setTime(bool utc, double hours, double minutes, double seconds, double ms) { time.setTimeZone(utc ? Timezone.getTimeZone("GMT") : Timezone.getDefault()); if (!Double.IsNaN(hours)) { time.set(Calendar.HOUR_OF_DAY, (int)hours); } if (!Double.IsNaN(minutes)) { time.set(Calendar.MINUTE, (int)minutes); } if (!Double.IsNaN(seconds)) { time.set(Calendar.SECOND, (int)seconds); } if (!Double.IsNaN(ms)) { time.set(Calendar.MILLISECOND, (int)ms); } }
/** * Java implementation of JS date members. */ public override void evalNative(int index, JsArray stack, int sp, int parCount) { switch (index) { // static members case ID_TO_DATE_STRING: case ID_TO_LOCALE_DATE_STRING: stack.setObject(sp, toString(false, true, false)); break; case ID_TO_TIME_STRING: case ID_TO_LOCALE_TIME_STRING: stack.setObject(sp, toString(false, false, true)); break; case ID_VALUE_OF: case ID_GET_TIME: stack.setNumber(sp, time.getTime().Ticks); break; case ID_GET_DATE: stack.setNumber(sp, get(false, Calendar.DAY_OF_MONTH)); break; case ID_GET_FULL_YEAR: stack.setNumber(sp, get(false, Calendar.YEAR)); break; case ID_GET_MONTH: stack.setNumber(sp, get(false, Calendar.MONTH)); break; case ID_GET_DAY: stack.setNumber(sp, get(false, Calendar.DAY_OF_WEEK)); break; case ID_GET_HOURS: stack.setNumber(sp, get(false, Calendar.HOUR_OF_DAY)); break; case ID_GET_MINUTES: stack.setNumber(sp, get(false, Calendar.MINUTE)); break; case ID_GET_SECONDS: stack.setNumber(sp, get(false, Calendar.SECOND)); break; case ID_GET_MILLISECONDS: stack.setNumber(sp, get(false, Calendar.MILLISECOND)); break; case ID_GET_UTC_FULL_YEAR: stack.setNumber(sp, get(true, Calendar.YEAR)); break; case ID_GET_UTC_MONTH: stack.setNumber(sp, get(true, Calendar.MONTH)); break; case ID_GET_UTC_DATE: stack.setNumber(sp, get(true, Calendar.DAY_OF_MONTH)); break; case ID_GET_UTC_DAY: stack.setNumber(sp, get(true, Calendar.DAY_OF_WEEK)); break; case ID_GET_UTC_HOURS: stack.setNumber(sp, get(true, Calendar.HOUR_OF_DAY)); break; case ID_GET_UTC_MINUTES: stack.setNumber(sp, get(true, Calendar.MINUTE)); break; case ID_GET_UTC_SECONDS: stack.setNumber(sp, get(true, Calendar.SECOND)); break; case ID_GET_UTC_MILLISECONDS: stack.setNumber(sp, get(true, Calendar.MILLISECOND)); break; case ID_GET_TIMEZONE_OFFSET: stack.setNumber(sp, Timezone.getDefault().getOffset( time.getTime().Ticks >= 0 ? 1 : 0, time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.DAY_OF_WEEK), time.get(Calendar.HOUR_OF_DAY) * 3600000 + time.get(Calendar.MINUTE) * 60000 + time.get(Calendar.SECOND) * 1000 + time.get(Calendar.MILLISECOND))); break; case ID_SET_TIME: time.setTime(new DateTime((long)stack.getNumber(sp + 2))); break; case ID_SET_MILLISECONDS: setTime( false, Double.NaN, Double.NaN, Double.NaN, stack.getNumber(sp + 2)); break; case ID_SET_SECONDS: setTime( false, Double.NaN, Double.NaN, stack.getNumber(sp + 2), stack.getNumber(sp + 3)); break; case ID_SET_MINUTES: setTime( false, Double.NaN, stack.getNumber(sp + 2), stack.getNumber(sp + 3), stack.getNumber(sp + 4)); break; case ID_SET_HOURS: setTime( false, stack.getNumber(sp + 2), stack.getNumber(sp + 3), stack.getNumber(sp + 4), stack.getNumber(sp + 5)); break; case ID_SET_DATE: setDate( false, Double.NaN, Double.NaN, stack.getNumber(sp + 2)); break; case ID_SET_MONTH: setDate( false, Double.NaN, stack.getNumber(sp + 2), stack.getNumber(sp + 3)); break; case ID_SET_FULL_YEAR: setDate( false, stack.getNumber(sp + 2), stack.getNumber(sp + 3), stack.getNumber(sp + 4)); break; case ID_SET_UTC_MILLISECONDS: setTime( true, Double.NaN, Double.NaN, Double.NaN, stack.getNumber(sp + 2)); break; case ID_SET_UTC_SECONDS: setTime( true, Double.NaN, Double.NaN, stack.getNumber(sp + 2), stack.getNumber(sp + 3)); break; case ID_SET_UTC_MINUTES: setTime( true, Double.NaN, stack.getNumber(sp + 2), stack.getNumber(sp + 3), stack.getNumber(sp + 4)); break; case ID_SET_UTC_HOURS: setTime( true, stack.getNumber(sp + 2), stack.getNumber(sp + 3), stack.getNumber(sp + 4), stack.getNumber(sp + 5)); break; case ID_SET_UTC_DATE: setDate( true, Double.NaN, Double.NaN, stack.getNumber(sp + 2)); break; case ID_SET_UTC_MONTH: setDate( true, Double.NaN, stack.getNumber(sp + 2), stack.getNumber(sp + 3)); break; case ID_SET_UTC_FULL_YEAR: setDate( true, stack.getNumber(sp + 2), stack.getNumber(sp + 3), stack.getNumber(sp + 4)); break; case ID_TO_UTC_STRING: case ID_TO_GMT_STRING: stack.setObject(sp, toString(true, true, true)); break; default: base.evalNative(index, stack, sp, parCount); break; } }