| Index: src/js/i18n.js
|
| diff --git a/src/js/i18n.js b/src/js/i18n.js
|
| index 18d13db9a2c2f96e88f2c96305486ec7cb933cc9..92c9a80a0b7b5ed4264738e2c7f5001f97a4b1ba 100644
|
| --- a/src/js/i18n.js
|
| +++ b/src/js/i18n.js
|
| @@ -1959,7 +1959,10 @@ var savedObjects = {
|
| 'numberformat': GlobalIntlNumberFormat,
|
| 'dateformatall': GlobalIntlDateTimeFormat,
|
| 'dateformatdate': GlobalIntlDateTimeFormat,
|
| - 'dateformattime': GlobalIntlDateTimeFormat
|
| + 'dateformattime': GlobalIntlDateTimeFormat,
|
| + 'datetostring': GlobalIntlDateTimeFormat,
|
| + 'datetodatestring': GlobalIntlDateTimeFormat,
|
| + 'datetotimestring': GlobalIntlDateTimeFormat,
|
| };
|
|
|
|
|
| @@ -1971,12 +1974,18 @@ var defaultObjects = {
|
| 'dateformatall': UNDEFINED,
|
| 'dateformatdate': UNDEFINED,
|
| 'dateformattime': UNDEFINED,
|
| + 'datetostring': UNDEFINED,
|
| + 'datetodatestring': UNDEFINED,
|
| + 'datetotimestring': UNDEFINED,
|
| };
|
|
|
| function clearDefaultObjects() {
|
| defaultObjects['dateformatall'] = UNDEFINED;
|
| defaultObjects['dateformatdate'] = UNDEFINED;
|
| defaultObjects['dateformattime'] = UNDEFINED;
|
| + defaultObjects['datetostring'] = UNDEFINED;
|
| + defaultObjects['datetodatestring'] = UNDEFINED;
|
| + defaultObjects['datetotimestring'] = UNDEFINED;
|
| }
|
|
|
| var date_cache_version = 0;
|
| @@ -1993,11 +2002,14 @@ function checkDateCacheCurrent() {
|
|
|
| /**
|
| * Returns cached or newly created instance of a given service.
|
| - * We cache only default instances (where no locales or options are provided).
|
| + * We cache only default instances (where no locales or options are provided)
|
| + * or overrides of Date.prototype.to{,Date,Time}String for which useCached
|
| + * is defined.
|
| */
|
| -function cachedOrNewService(service, locales, options, defaults) {
|
| +function cachedOrNewService(service, locales, options, defaults, useCached) {
|
| var useOptions = (IS_UNDEFINED(defaults)) ? options : defaults;
|
| - if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) {
|
| + if (!IS_UNDEFINED(useCached) ||
|
| + (IS_UNDEFINED(locales) && IS_UNDEFINED(options))) {
|
| checkDateCacheCurrent();
|
| if (IS_UNDEFINED(defaultObjects[service])) {
|
| defaultObjects[service] = new savedObjects[service](locales, useOptions);
|
| @@ -2139,7 +2151,8 @@ OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
|
| /**
|
| * Returns actual formatted date or fails if date parameter is invalid.
|
| */
|
| -function toLocaleDateTime(date, locales, options, required, defaults, service) {
|
| +function toLocaleDateTime(date, locales, options, required, defaults, service,
|
| + useCached) {
|
| if (!(date instanceof GlobalDate)) {
|
| throw %make_type_error(kMethodInvokedOnWrongType, "Date");
|
| }
|
| @@ -2150,7 +2163,7 @@ function toLocaleDateTime(date, locales, options, required, defaults, service) {
|
| var internalOptions = toDateTimeOptions(options, required, defaults);
|
|
|
| var dateFormat =
|
| - cachedOrNewService(service, locales, options, internalOptions);
|
| + cachedOrNewService(service, locales, options, internalOptions, useCached);
|
|
|
| return formatDate(dateFormat, date);
|
| }
|
| @@ -2169,6 +2182,18 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
|
| }
|
| );
|
|
|
| +OverrideFunction(GlobalDate.prototype, 'toString', function() {
|
| + var options = {
|
| + weekday: "short", month: "short", year: "numeric", day: "2-digit",
|
| + hour: "2-digit", minute: "2-digit", second: "2-digit",
|
| + timeZoneName: "short", hour12: false,
|
| + };
|
| +
|
| + return toLocaleDateTime(
|
| + this, "en-US", options, 'any', 'all', 'datetostring', true);
|
| + }
|
| +);
|
| +
|
|
|
| /**
|
| * Formats a Date object (this) using locale and options values.
|
| @@ -2183,6 +2208,15 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
|
| }
|
| );
|
|
|
| +OverrideFunction(GlobalDate.prototype, 'toDateString', function() {
|
| + var options = { weekday: "short", month: "short", year: "numeric",
|
| + day: "2-digit",};
|
| +
|
| + return toLocaleDateTime(
|
| + this, "en-US", options, 'date', 'date', 'datetodatestring', true);
|
| + }
|
| +);
|
| +
|
|
|
| /**
|
| * Formats a Date object (this) using locale and options values.
|
| @@ -2198,9 +2232,17 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() {
|
| );
|
|
|
| %FunctionRemovePrototype(FormatDateToParts);
|
| -
|
| utils.Export(function(to) {
|
| to.FormatDateToParts = FormatDateToParts;
|
| });
|
|
|
| +OverrideFunction(GlobalDate.prototype, 'toTimeString', function() {
|
| + var options = { hour: "2-digit", minute: "2-digit", second: "2-digit",
|
| + timeZoneName: "short", hour12: false};
|
| +
|
| + return toLocaleDateTime(
|
| + this, "en-US", options, 'time', 'time', 'datetotimestring', true);
|
| + }
|
| +);
|
| +
|
| })
|
|
|