Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.dynjs.runtime.builtins.types;
  
  import static org.dynjs.runtime.builtins.types.date.AbstractDateFunction.*;
  
 
 public class BuiltinDate extends AbstractBuiltinType {
 
     public BuiltinDate(final GlobalObject globalObject) {
         super(globalObject"year""month""date""hours""minutes""seconds""ms");
         final DynDate proto = new DynDate(globalObject);
         setPrototypeProperty(proto);
     }
 
     @Override
     public JSObject createNewObject(ExecutionContext context) {
         return new DynDate(context.getGlobalObject());
     }
 
     @Override
     public void initialize(GlobalObject globalObjectJSObject proto) {
         proto.setPrototype(globalObject.getPrototypeFor("Object"));
 
         defineNonEnumerableProperty(this"now"new Now(globalObject) );
         defineNonEnumerableProperty(this"parse"new Parse(globalObject));
         defineNonEnumerableProperty(this"UTC"new UTC(globalObject) );
         defineNonEnumerableProperty(proto"constructor"this);
         defineNonEnumerableProperty(proto"toString"new ToString(globalObject));
         defineNonEnumerableProperty(proto"toDateString"new ToDateString(globalObject));
         defineNonEnumerableProperty(proto"toTimeString"new ToTimeString(globalObject));
         defineNonEnumerableProperty(proto"toLocaleString"new ToLocaleString(globalObject));
         defineNonEnumerableProperty(proto"toLocaleDateString"new ToLocaleDateString(globalObject));
         defineNonEnumerableProperty(proto"toLocaleTimeString"new ToLocaleTimeString(globalObject));
         defineNonEnumerableProperty(proto"toISOString"new ToISOString(globalObject));
         defineNonEnumerableProperty(proto"toUTCString"new ToUTCString(globalObject));
         defineNonEnumerableProperty(proto"toGMTString"new ToUTCString(globalObject));
         defineNonEnumerableProperty(proto"valueOf"new ValueOf(globalObject));
         defineNonEnumerableProperty(proto"getTime"new ValueOf(globalObject));
         defineNonEnumerableProperty(proto"getFullYear"new GetFullYear(globalObject));
         defineNonEnumerableProperty(proto"getMonth"new GetMonth(globalObject));
         defineNonEnumerableProperty(proto"getDay"new GetDay(globalObject));
         defineNonEnumerableProperty(proto"getHours"new GetHours(globalObject));
         defineNonEnumerableProperty(proto"getMinutes"new GetMinutes(globalObject));
         defineNonEnumerableProperty(proto"getSeconds"new GetSeconds(globalObject));
         defineNonEnumerableProperty(proto"getUTCFullYear"new GetUTCFullYear(globalObject));
         defineNonEnumerableProperty(proto"getUTCMonth"new GetUTCMonth(globalObject));
        defineNonEnumerableProperty(proto"getUTCDay"new GetUTCDay(globalObject));
        defineNonEnumerableProperty(proto"getUTCHours"new GetUTCHours(globalObject));
        defineNonEnumerableProperty(proto"getUTCMinutes"new GetUTCMinutes(globalObject));
        defineNonEnumerableProperty(proto"getUTCSeconds"new GetUTCSeconds(globalObject));
        defineNonEnumerableProperty(proto"getTimezoneOffset"new GetTimezoneOffset(globalObject));
        defineNonEnumerableProperty(proto"getMilliseconds"new GetMilliseconds(globalObject));
        defineNonEnumerableProperty(proto"setMilliseconds"new SetMilliseconds(globalObject));
        defineNonEnumerableProperty(proto"getUTCMilliseconds"new GetUTCMilliseconds(globalObject));
        defineNonEnumerableProperty(proto"setUTCMilliseconds"new SetUTCMilliseconds(globalObject));
        defineNonEnumerableProperty(proto"setTime"new SetTime(globalObject));
        defineNonEnumerableProperty(proto"setSeconds"new SetSeconds(globalObject));
        defineNonEnumerableProperty(proto"setUTCSeconds"new SetUTCSeconds(globalObject));
        defineNonEnumerableProperty(proto"setMinutes"new SetMinutes(globalObject));
        defineNonEnumerableProperty(proto"setUTCMinutes"new SetUTCMinutes(globalObject));
        defineNonEnumerableProperty(proto"setHours"new SetHours(globalObject));
        defineNonEnumerableProperty(proto"setUTCHours"new SetUTCHours(globalObject));
        defineNonEnumerableProperty(proto"setDate"new SetDate(globalObject));
        defineNonEnumerableProperty(proto"getDate"new GetDate(globalObject));
        defineNonEnumerableProperty(proto"setUTCDate"new SetUTCDate(globalObject));
        defineNonEnumerableProperty(proto"getUTCDate"new GetUTCDate(globalObject));
        defineNonEnumerableProperty(proto"setMonth"new SetMonth(globalObject));
        defineNonEnumerableProperty(proto"setUTCMonth"new SetUTCMonth(globalObject));
        defineNonEnumerableProperty(proto"setFullYear"new SetFullYear(globalObject));
        defineNonEnumerableProperty(proto"setUTCFullYear"new SetUTCFullYear(globalObject));
        defineNonEnumerableProperty(proto"toJSON"new ToJSON(globalObject));
        defineNonEnumerableProperty(proto"getYear"new GetYear(globalObject));
        defineNonEnumerableProperty(proto"setYear"new SetYear(globalObject));
    }
    @Override
    public Object call(ExecutionContext contextObject selfObject... args) {
        if (self == . || self == .) {
            DynDate now = new DynDate(context.getGlobalObject());
            JSFunction toString = (JSFunctionnow.get(context"toString");
            return context.call(toStringnow);
        }
        Arguments argsObj = (Argumentscontext.resolve("arguments").getValue(context);
        int numArgs = (intargsObj.get(context"length");
        DynDate date = (DynDateself;
        if (numArgs == 0) {
            date.setTimeValue(context.getClock().currentTimeMillis());
        } else if (numArgs == 1) {
            Object v = Types.toPrimitive(contextargs[0]);
            if (v instanceof String) {
                date.setTimeValue(timeClip(context, Parse.parse(context, (Stringv)));
            } else {
                date.setTimeValue(timeClip(context, Types.toNumber(contextv)));
            }
        } else {
            Number y = Types.toNumber(contextargs[0]);
            Number m = Types.toNumber(contextargs[1]);
            Number dt = 1;
            Number h = 0;
            Number min = 0;
            Number s = 0;
            Number milli = 0;
            if (numArgs >= 3) {
                dt = Types.toNumber(contextargs[2]);
            }
            if (numArgs >= 4) {
                h = Types.toNumber(contextargs[3]);
            }
            if (numArgs >= 5) {
                min = Types.toNumber(contextargs[4]);
            }
            if (numArgs >= 6) {
                s = Types.toNumber(contextargs[5]);
            }
            if (numArgs >= 7) {
                milli = Types.toNumber(contextargs[6]);
            }
            Number yr = y;
            
            if (!Double.isNaN(y.doubleValue())) {
                long longYr = yr.longValue();
                if (longYr >= 0 && longYr <= 99) {
                    yr = longYr + 1900;
                }
            }
            Number finalDate = makeDate(contextmakeDay(contextyrmdt), makeTime(contexthminsmilli));
            Number clipped = timeClip(contextutc(contextfinalDate));
            date.setTimeValue(clipped);
        }
        return date;
    }
New to GrepCode? Check out our FAQ X