Work around lack of English locales

by David Storey

JavaScript

var locale = "en-AU",
    country = locale.split("-")[1],
    usedLocale = null,
    formatter = null;

console.clear();

// Gah, Chrome says supported but it is not
console.log(Intl.DateTimeFormat.supportedLocalesOf(locale));

formatter = new Intl.DateTimeFormat(locale);

// Woops, US date format.
console.log(formatter.format(new Date("2013-11-09")));

usedLocale = formatter.resolvedOptions().locale;

// That is why: usedLocale = "en". Set to British English instead
if (usedLocale.indexOf("en") === 0 && usedLocale.indexOf("-" + country) === -1) {
    formatter = new Intl.DateTimeFormat("en-GB");
}

console.log(formatter.format(new Date("2013-11-09")));