Browse Source

Add custom renderer for time and enhance locale string options in clock

pull/22236/head
maliming 2 years ago
parent
commit
735a6cf738
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js
  2. 11
      npm/packs/core/src/abp.js
  3. 10
      npm/packs/luxon/src/abp.luxon.js

8
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js

@ -509,6 +509,14 @@ var abp = abp || {};
} }
}; };
datatables.defaultRenderers['time'] = function (value) {
if (!value) {
return value;
} else {
return abp.clock.normalizeToLocaleString(value, { hour: '2-digit', minute: '2-digit', second: '2-digit' });
}
};
datatables.defaultRenderers['datetime'] = function (value) { datatables.defaultRenderers['datetime'] = function (value) {
if (!value) { if (!value) {
return value; return value;

11
npm/packs/core/src/abp.js

@ -792,7 +792,14 @@ var abp = abp || {};
}; };
// Default options for toLocaleString // Default options for toLocaleString
abp.clock.toLocaleStringOptions = abp.clock.toLocaleStringOptions || {}; abp.clock.toLocaleStringOptions = abp.clock.toLocaleStringOptions || {
"year": "numeric",
"month": "long",
"day": "numeric",
"hour": "numeric",
"minute": "numeric",
"second": "numeric"
};
// Normalize date string to locale date string that will be displayed to user // Normalize date string to locale date string that will be displayed to user
abp.clock.normalizeToLocaleString = function (dateString, options) { abp.clock.normalizeToLocaleString = function (dateString, options) {
@ -806,7 +813,7 @@ var abp = abp || {};
} }
var culture = abp.localization.currentCulture.cultureName; var culture = abp.localization.currentCulture.cultureName;
options = Object.assign({}, abp.clock.toLocaleStringOptions, options || {}); options = options || abp.clock.toLocaleStringOptions;
if (abp.clock.supportsMultipleTimezone()) { if (abp.clock.supportsMultipleTimezone()) {
var timezone = abp.clock.timeZone(); var timezone = abp.clock.timeZone();
if (timezone) { if (timezone) {

10
npm/packs/luxon/src/abp.luxon.js

@ -32,7 +32,7 @@ var abp = abp || {};
.fromFormat( .fromFormat(
getObjectValue(form, field), getObjectValue(form, field),
abp.localization.currentCulture.dateTimeFormat.shortDatePattern, abp.localization.currentCulture.dateTimeFormat.shortDatePattern,
{locale: abp.localization.currentCulture.cultureName} { locale: abp.localization.currentCulture.cultureName }
); );
if (!dateTime.invalid) { if (!dateTime.invalid) {
@ -80,19 +80,19 @@ var abp = abp || {};
return dateString; return dateString;
} }
options = options || luxon.DateTime.DATETIME_FULL; options = options || abp.clock.toLocaleStringOptions;
if (abp.clock.supportsMultipleTimezone()) { if (abp.clock.supportsMultipleTimezone()) {
var timezone = abp.clock.timeZone(); var timezone = abp.clock.timeZone();
if (timezone) { if (timezone) {
return luxon.DateTime.fromJSDate(date) return luxon.DateTime.fromJSDate(date)
.setZone(timezone) .setZone(timezone)
.setLocale(abp.localization.currentCulture.cultureName) .setLocale(abp.localization.currentCulture.cultureName)
.toLocaleString(Object.assign({}, abp.clock.toLocaleStringOptions, options)); .toLocaleString(options);
} }
} }
return luxon.DateTime.fromJSDate(date) return luxon.DateTime.fromJSDate(date)
.setLocale(abp.localization.currentCulture.cultureName) .setLocale(abp.localization.currentCulture.cultureName)
.toLocaleString(Object.assign({}, abp.clock.toLocaleStringOptions, options)); .toLocaleString(options);
} }
})(jQuery); })(jQuery);

Loading…
Cancel
Save