index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var dateLongFormatter = function dateLongFormatter(pattern, formatLong) {
  7. switch (pattern) {
  8. case 'P':
  9. return formatLong.date({
  10. width: 'short'
  11. });
  12. case 'PP':
  13. return formatLong.date({
  14. width: 'medium'
  15. });
  16. case 'PPP':
  17. return formatLong.date({
  18. width: 'long'
  19. });
  20. case 'PPPP':
  21. default:
  22. return formatLong.date({
  23. width: 'full'
  24. });
  25. }
  26. };
  27. var timeLongFormatter = function timeLongFormatter(pattern, formatLong) {
  28. switch (pattern) {
  29. case 'p':
  30. return formatLong.time({
  31. width: 'short'
  32. });
  33. case 'pp':
  34. return formatLong.time({
  35. width: 'medium'
  36. });
  37. case 'ppp':
  38. return formatLong.time({
  39. width: 'long'
  40. });
  41. case 'pppp':
  42. default:
  43. return formatLong.time({
  44. width: 'full'
  45. });
  46. }
  47. };
  48. var dateTimeLongFormatter = function dateTimeLongFormatter(pattern, formatLong) {
  49. var matchResult = pattern.match(/(P+)(p+)?/) || [];
  50. var datePattern = matchResult[1];
  51. var timePattern = matchResult[2];
  52. if (!timePattern) {
  53. return dateLongFormatter(pattern, formatLong);
  54. }
  55. var dateTimeFormat;
  56. switch (datePattern) {
  57. case 'P':
  58. dateTimeFormat = formatLong.dateTime({
  59. width: 'short'
  60. });
  61. break;
  62. case 'PP':
  63. dateTimeFormat = formatLong.dateTime({
  64. width: 'medium'
  65. });
  66. break;
  67. case 'PPP':
  68. dateTimeFormat = formatLong.dateTime({
  69. width: 'long'
  70. });
  71. break;
  72. case 'PPPP':
  73. default:
  74. dateTimeFormat = formatLong.dateTime({
  75. width: 'full'
  76. });
  77. break;
  78. }
  79. return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
  80. };
  81. var longFormatters = {
  82. p: timeLongFormatter,
  83. P: dateTimeLongFormatter
  84. };
  85. var _default = longFormatters;
  86. exports.default = _default;
  87. module.exports = exports.default;