datejs / Datejs

A JavaScript Date and Time Library
Other
1.89k stars 483 forks source link

Will Datejs work with JavaScript for Automation (JXA)? #74

Open JMichaelTX opened 8 years ago

JMichaelTX commented 8 years ago

Hi. I just found this great library, and it looks awesome! It runs fine, testing with Chrome JavaScript console.

But I can't get it to work with JXA.

I get this error: image

When running this code:

var app = Application.currentApplication()
app.includeStandardAdditions = true

Date.today();

/**
 * @version: 1.0 Alpha-1
 * @author: Coolite Inc. http://www.coolite.com/
 * @date: 2008-05-13
 * @copyright: Copyright (c) 2006-2008, Coolite Inc. (http://www.coolite.com/). All rights reserved.
 * @license: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 
 * @website: http://www.datejs.com/
 */
Date.CultureInfo={name:"en-US",englishName:"English (United 

The code from the entire Date-en-US.js file is at the bottom of my Script Editor file, I just cut off the code when I pasted it here.

Same file runs fine in a simple HTML page using Chrome JavaScript console.

Any suggestions as to how I can make this work with JXA?

TIA.

martinschilliger commented 8 years ago

I don't know much about JXA, but maybe it's a problem related to Datejs expanding the native Date()-function? Is this allowed in JXA? I didn't found out with a quick Google search.

According to http://www.automatedworkflows.com/2014/10/28/whats-new-with-automation-in-yosemite/:

JXA can access Objective-C and Cocoa frameworks

you may use the native Date-Framework of Mac OS X as an alternative?