37e8a9e593763f2e26cebb36d107eca045d2a7140228e38f1e6ddc8d3ee95c81ac9b0877ca976875e4aff4c9d4192de6a22e15cdcd9642651f47bb99fe74a3 1.5 KB

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