29d994eb47a7b8c29156be944f9e6e1c7ddd3184213cd83f85cc0a66e5818d1b96ebe06e385eacfe5f3dde9833ff546cc22ef06a790f979853f749ea9cb835 1.5 KB

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