/node_modules/moment/src/lib/units/day-of-year.js

https://bitbucket.org/coleman333/smartsite · JavaScript · 36 lines · 20 code · 10 blank · 6 comment · 1 complexity · 9a1909e4a60fedc123920cafbfc0e90f MD5 · raw file

  1. import { addFormatToken } from '../format/format';
  2. import { addUnitAlias } from './aliases';
  3. import { addUnitPriority } from './priorities';
  4. import { addRegexToken, match3, match1to3 } from '../parse/regex';
  5. import { daysInYear } from './year';
  6. import { createUTCDate } from '../create/date-from-array';
  7. import { addParseToken } from '../parse/token';
  8. import toInt from '../utils/to-int';
  9. // FORMATTING
  10. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  11. // ALIASES
  12. addUnitAlias('dayOfYear', 'DDD');
  13. // PRIORITY
  14. addUnitPriority('dayOfYear', 4);
  15. // PARSING
  16. addRegexToken('DDD', match1to3);
  17. addRegexToken('DDDD', match3);
  18. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  19. config._dayOfYear = toInt(input);
  20. });
  21. // HELPERS
  22. // MOMENTS
  23. export function getSetDayOfYear (input) {
  24. var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  25. return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  26. }