37bd90e1913ef703e40a12cba9f91d0d8c4b1e09e9e3e730744d7e5be269bde1b11b37226a2ddcb57fd03c4fbe9f0ef8420f5d327d776503d304b2e3571d45 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { getLocale } from './locales';
  2. import { createUTC } from '../create/utc';
  3. function get (format, index, field, setter) {
  4. var locale = getLocale();
  5. var utc = createUTC().set(setter, index);
  6. return locale[field](utc, format);
  7. }
  8. function listMonthsImpl (format, index, field) {
  9. if (typeof format === 'number') {
  10. index = format;
  11. format = undefined;
  12. }
  13. format = format || '';
  14. if (index != null) {
  15. return get(format, index, field, 'month');
  16. }
  17. var i;
  18. var out = [];
  19. for (i = 0; i < 12; i++) {
  20. out[i] = get(format, i, field, 'month');
  21. }
  22. return out;
  23. }
  24. // ()
  25. // (5)
  26. // (fmt, 5)
  27. // (fmt)
  28. // (true)
  29. // (true, 5)
  30. // (true, fmt, 5)
  31. // (true, fmt)
  32. function listWeekdaysImpl (localeSorted, format, index, field) {
  33. if (typeof localeSorted === 'boolean') {
  34. if (typeof format === 'number') {
  35. index = format;
  36. format = undefined;
  37. }
  38. format = format || '';
  39. } else {
  40. format = localeSorted;
  41. index = format;
  42. localeSorted = false;
  43. if (typeof format === 'number') {
  44. index = format;
  45. format = undefined;
  46. }
  47. format = format || '';
  48. }
  49. var locale = getLocale(),
  50. shift = localeSorted ? locale._week.dow : 0;
  51. if (index != null) {
  52. return get(format, (index + shift) % 7, field, 'day');
  53. }
  54. var i;
  55. var out = [];
  56. for (i = 0; i < 7; i++) {
  57. out[i] = get(format, (i + shift) % 7, field, 'day');
  58. }
  59. return out;
  60. }
  61. export function listMonths (format, index) {
  62. return listMonthsImpl(format, index, 'months');
  63. }
  64. export function listMonthsShort (format, index) {
  65. return listMonthsImpl(format, index, 'monthsShort');
  66. }
  67. export function listWeekdays (localeSorted, format, index) {
  68. return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  69. }
  70. export function listWeekdaysShort (localeSorted, format, index) {
  71. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  72. }
  73. export function listWeekdaysMin (localeSorted, format, index) {
  74. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  75. }