index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Q, M, D } from '../../constant';
  2. export default (function (o, c) {
  3. var proto = c.prototype;
  4. proto.quarter = function (quarter) {
  5. if (!this.$utils().u(quarter)) {
  6. return this.month(this.month() % 3 + (quarter - 1) * 3);
  7. }
  8. return Math.ceil((this.month() + 1) / 3);
  9. };
  10. var oldAdd = proto.add;
  11. proto.add = function (number, units) {
  12. number = Number(number); // eslint-disable-line no-param-reassign
  13. var unit = this.$utils().p(units);
  14. if (unit === Q) {
  15. return this.add(number * 3, M);
  16. }
  17. return oldAdd.bind(this)(number, units);
  18. };
  19. var oldStartOf = proto.startOf;
  20. proto.startOf = function (units, startOf) {
  21. var utils = this.$utils();
  22. var isStartOf = !utils.u(startOf) ? startOf : true;
  23. var unit = utils.p(units);
  24. if (unit === Q) {
  25. var quarter = this.quarter() - 1;
  26. return isStartOf ? this.month(quarter * 3).startOf(M).startOf(D) : this.month(quarter * 3 + 2).endOf(M).endOf(D);
  27. }
  28. return oldStartOf.bind(this)(units, startOf);
  29. };
  30. });