abp.luxon.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var abp = abp || {};
  2. (function () {
  3. if (!luxon) {
  4. throw "abp/luxon library requires the luxon library included to the page!";
  5. }
  6. /* TIMING *************************************************/
  7. abp.timing = abp.timing || {};
  8. var setObjectValue = function (obj, property, value) {
  9. if (typeof property === "string") {
  10. property = property.split('.');
  11. }
  12. if (property.length > 1) {
  13. var p = property.shift();
  14. setObjectValue(obj[p], property, value);
  15. } else {
  16. obj[property[0]] = value;
  17. }
  18. }
  19. var getObjectValue = function (obj, property) {
  20. return property.split('.').reduce((a, v) => a[v], obj)
  21. }
  22. abp.timing.convertFieldsToIsoDate = function (form, fields) {
  23. for (var field of fields) {
  24. var dateTime = luxon.DateTime
  25. .fromFormat(
  26. getObjectValue(form, field),
  27. abp.localization.currentCulture.dateTimeFormat.shortDatePattern,
  28. {locale: abp.localization.currentCulture.cultureName}
  29. );
  30. if (!dateTime.invalid) {
  31. setObjectValue(form, field, dateTime.toFormat("yyyy-MM-dd HH:mm:ss"))
  32. }
  33. }
  34. return form;
  35. }
  36. })(jQuery);