d20283791cdf74b121c9f6f54d3266d807c6d858f45fdac26d5b09cb46869485907347b8edb231fdce3897d0e9663298f96d290fab2e4d7bf303c4a4310be2 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { addFormatToken } from '../format/format';
  2. import { addUnitAlias } from './aliases';
  3. import { addUnitPriority } from './priorities';
  4. import { addRegexToken, match1to2, match2 } from '../parse/regex';
  5. import { addWeekParseToken } from '../parse/token';
  6. import toInt from '../utils/to-int';
  7. import { createLocal } from '../create/local';
  8. import { weekOfYear } from './week-calendar-utils';
  9. // FORMATTING
  10. addFormatToken('w', ['ww', 2], 'wo', 'week');
  11. addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
  12. // ALIASES
  13. addUnitAlias('week', 'w');
  14. addUnitAlias('isoWeek', 'W');
  15. // PRIORITIES
  16. addUnitPriority('week', 5);
  17. addUnitPriority('isoWeek', 5);
  18. // PARSING
  19. addRegexToken('w', match1to2);
  20. addRegexToken('ww', match1to2, match2);
  21. addRegexToken('W', match1to2);
  22. addRegexToken('WW', match1to2, match2);
  23. addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  24. week[token.substr(0, 1)] = toInt(input);
  25. });
  26. // HELPERS
  27. // LOCALES
  28. export function localeWeek (mom) {
  29. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  30. }
  31. export var defaultLocaleWeek = {
  32. dow : 0, // Sunday is the first day of the week.
  33. doy : 6 // The week that contains Jan 1st is the first week of the year.
  34. };
  35. export function localeFirstDayOfWeek () {
  36. return this._week.dow;
  37. }
  38. export function localeFirstDayOfYear () {
  39. return this._week.doy;
  40. }
  41. // MOMENTS
  42. export function getSetWeek (input) {
  43. var week = this.localeData().week(this);
  44. return input == null ? week : this.add((input - week) * 7, 'd');
  45. }
  46. export function getSetISOWeek (input) {
  47. var week = weekOfYear(this, 1, 4).week;
  48. return input == null ? week : this.add((input - week) * 7, 'd');
  49. }