Gregory
Gregory

Reputation: 1245

Methods for Date class?

Is there any documentation for what I can do to an object created like "new Date()"? I thought it would be a Javascript date object, but it doesn't seem to have most of the methods of that object.

Thanks.

Upvotes: 3

Views: 2969

Answers (2)

Matt
Matt

Reputation: 1059

I also ran into a Date related issue in Google Apps Script where Javascript in my browser console would correctly interpret a date (in the format "2014-08-26T11:25:01.000-0400"), but the GAS Date object would not and result in "Invalid Date".

I found this answer to another question where in a comment it was mentioned that GAS uses Rhino to interpret Javascript. I downloaded several versions of Rhino until I found one old enough that gave me the same error (Rhino 1.7R5, Jan. 29, 2015).

You can download that version and peruse the source code and even run the interpreter with a REPL using the command java -jar js.jar. To answer your question, src/org/mozilla/javascript/NativeDate.java would be the file you're looking for, and the definition of the Date object is down near the bottom where a bunch of private static final ints are declared (ex: Id_constructor, Id_toString, etc.) I think those ints correspond to methods in the same Java class that define the Javascript Date object.

Upvotes: 1

Harold
Harold

Reputation: 3337

indeed it is a JS object and have all the JS object methods. But the autocompletion is only available for the google apps scripts class and some a few time for some js native objects like array.

Upvotes: 1

Related Questions