Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixbug: fix new Date().toLocaleDateString() with locals #633

Closed
wants to merge 3 commits into from

Conversation

linkxzhou
Copy link

fixbug: fix toLocaleDateString
testcases:

var locales = {
	"cs-CZ": "2. 1. 2006",
	"da-DK": "2.1.2006",
	"de-AT": "2.1.2006",
	"de-CH": "2.1.2006",
	"de-DE": "2.1.2006",
	"el-GR": "2/1/2006",
	"en-AU": "02/01/2006",
	"en-CA": "2006-01-02",
	"en-GB": "02/01/2006",
	"en-IE": "2/1/2006",
	"en-IN": "2/1/2006",
	"en-NZ": "2/01/2006",
	"en-US": "1/2/2006",
	"en-ZA": "2006/01/02",
	"es-AR": "2/1/2006",
	"es-CL": "02-01-2006",
	"es-CO": "2/1/2006",
	"es-ES": "2/1/2006",
	"es-MX": "2/1/2006",
	"es-US": "2/1/2006",
	"fi-FI": "2.1.2006",
	"fr-BE": "02/01/2006",
	"fr-CA": "2006-01-02",
	"fr-CH": "02.01.2006",
	"fr-FR": "02/01/2006",
	"he-IL": "2.1.2006",
	"hi-IN": "2/1/2006",
	"hu-HU": "2006. 01. 02.",
	"id-ID": "2/1/2006",
	"it-CH": "02/01/2006",
	"it-IT": "02/01/2006",
	"ja-JP": "2006/1/2",
	"ko-KR": "2006. 1. 2.",
	"nl-BE": "2/1/2006",
	"nl-NL": "2-1-2006",
	"no-NO": "2.1.2006",
	"pl-PL": "2.01.2006",
	"pt-BR": "02/01/2006",
	"pt-PT": "02/01/2006",
	"ro-RO": "02.01.2006",
	"ru-RU": "02.01.2006",
	"sk-SK": "2. 1. 2006",
	"sv-SE": "2006-01-02",
	"ta-IN": "2/1/2006",
	"ta-LK": "2/1/2006",
	"th-TH": "2/1/2006",
	"tr-TR": "02.01.2006",
	"zh-CN": "2006/1/2",
	"zh-HK": "2/1/2006",
	"zh-TW": "2006/1/2",
};

var testDateCase = new Date("2006-01-02T12:00:00");
Object.keys(locales).forEach(key => {
	assert.sameValue(testDateCase.toLocaleDateString(key), locales[key]);
})
assert.sameValue(testDateCase.toLocaleDateString(), "01/02/2006");

and test cases is PASS.

@dop251
Copy link
Owner

dop251 commented Dec 17, 2024

Hi. Thanks for your submission, however I don't think this would be the right approach to address it.

First of all, locale-specific formatting is not part of the ECMAScript Language Specification, rather it's a separate ECMA-402 standard. In order to support it, nodejs uses the ICU library, which is huge and to my knowledge hasn't been fully ported to Go (at least I could not find any projects that would support date formatting in a way compatible with ECMA-402).

As soon as such port becomes available, this could be implemented as part of ECMA-402 (or not), but in a separate module, not part of the core goja project which focuses on the ECMAScript Language Specification.

In the meantime, if your project really needs it, you could just implement it as a module, either in Go, or in Javascript, or use a shim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants