Question

I'm developing a API Proxy in Apigee API Platform. I'm using a Javascript script to convert a Date to a User-Friendly representation. So I have this code:

var endDate = new Date(2014, 01, 01, 00, 00, 00);
var options = {
  localeMatcher: 'best fit',
  weekDay: 'short',
  year: 'numeric',
  month: 'short',
  day: '2-digit',
  hour: '2-digit',
  minute: '2-digit',
  second: '2-digit',
  timezone: 'America/El_Salvador',
  timeZoneName: 'short'
};
var friendly_endDate = endDate.toLocaleDateString('es-SV', options);

And I always end up with a en-US formatted date like the following:

February 1, 2014 12:00:00 UTC

Timezone, options and locale is ignored. is this normal? Am I missing something?

Was it helpful?

Solution

The latest version of Rhino (1.7R4) was released on 6/18/2012. According to the Mozilla docs on Date.toLocaleDateString, the locales and options arguments were added with the ECMAScript Internalization API, which looks like it came out in December 2012.

I think your best bet is to find a JavaScript library that can be included for your policy, and use that. See the Apigee JavaScript policy documentation for instructions on including JavaScript libraries.

OTHER TIPS

I use moment JS libray. Very nicely design simple library for JS base Date manipulations. Give it a try.

We also have a working sample that shows you how to work with JavaScript libraries as includes in an API proxy:

https://github.com/apigee/api-platform-samples/tree/master/sample-proxies/base64encoder

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top