archives

« Bugzilla Issues Index

#408 — Information on date/time components


From Markus Scherer's comments on internationalization support in ECMAScript
edition 4:

ECMAScript provides the Date object for parsing and formatting of dates with an unknown format. For validation and localized UI elements, it is required to know the format and elements of the date/time format patterns.

For example, HTML forms for date/time input often use separate fields for the year, month, day, etc. It is necessary to determine the order of those fields programmatically in order to generate such a form appropriately for the browser's locale. For selection UI elements (dropdown controls), the names of the fields are required as well to populate the selection choices.

Proposal: To add functions to the Date object to get each month and day name ("März", "Dienstag"), to get localized AM/PM names, and to get date, time, and date+time format patterns as used by the Date object (e.g., an array like ["Y", "M", "D", "h", "m"]).

There are various ways to do this. For example: getDayName(index), getMonthName(index), getAMName(), getPMName(), getDatePattern(), getTimePattern(), getDateTimePattern().

The getXYZPattern() functions could return array objects corresponding to the order and types of fields used for formatting and parsing date/time strings. Each array element could be

• A single-letter string like "Y" for the year field (using Java date/time pattern characters).
• A string like "year" for the year field (using Java date/time pattern field names).
• A number like 1 for the year field (using Java date/time pattern field indexes).

https://sites.google.com/site/markusicu/unicode/es/i18n-2003#DateTime


The `formatToParts()` proposal for dates can help with this, more details here: https://github.com/tc39/ecma402/issues/30