month.js 648 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const DatePart = require('./datepart');
  3. class Month extends DatePart {
  4. constructor(opts = {}) {
  5. super(opts);
  6. }
  7. up() {
  8. this.date.setMonth(this.date.getMonth() + 1);
  9. }
  10. down() {
  11. this.date.setMonth(this.date.getMonth() - 1);
  12. }
  13. setTo(val) {
  14. val = parseInt(val.substr(-2)) - 1;
  15. this.date.setMonth(val < 0 ? 0 : val);
  16. }
  17. toString() {
  18. let month = this.date.getMonth();
  19. let tl = this.token.length;
  20. return tl === 2 ? String(month + 1).padStart(2, '0') : tl === 3 ? this.locales.monthsShort[month] : tl === 4 ? this.locales.months[month] : String(month + 1);
  21. }
  22. }
  23. module.exports = Month;