Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { MS, Y, D, W } from '../../constant';
  2. export default (function (o, c, d) {
  3. var proto = c.prototype;
  4. proto.week = function (week) {
  5. if (week === void 0) {
  6. week = null;
  7. }
  8. if (week !== null) {
  9. return this.add((week - this.week()) * 7, D);
  10. }
  11. var yearStart = this.$locale().yearStart || 1;
  12. if (this.month() === 11 && this.date() > 25) {
  13. // d(this) is for badMutable
  14. var nextYearStartDay = d(this).startOf(Y).add(1, Y).date(yearStart);
  15. var thisEndOfWeek = d(this).endOf(W);
  16. if (nextYearStartDay.isBefore(thisEndOfWeek)) {
  17. return 1;
  18. }
  19. }
  20. var yearStartDay = d(this).startOf(Y).date(yearStart);
  21. var yearStartWeek = yearStartDay.startOf(W).subtract(1, MS);
  22. var diffInWeek = this.diff(yearStartWeek, W, true);
  23. if (diffInWeek < 0) {
  24. return d(this).startOf('week').week();
  25. }
  26. return Math.ceil(diffInWeek);
  27. };
  28. proto.weeks = function (week) {
  29. if (week === void 0) {
  30. week = null;
  31. }
  32. return this.week(week);
  33. };
  34. });