datepart.js 681 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. class DatePart {
  3. constructor({token, date, parts, locales}) {
  4. this.token = token;
  5. this.date = date || new Date();
  6. this.parts = parts || [this];
  7. this.locales = locales || {};
  8. }
  9. up() {}
  10. down() {}
  11. next() {
  12. const currentIdx = this.parts.indexOf(this);
  13. return this.parts.find((part, idx) => idx > currentIdx && part instanceof DatePart);
  14. }
  15. setTo(val) {}
  16. prev() {
  17. let parts = [].concat(this.parts).reverse();
  18. const currentIdx = parts.indexOf(this);
  19. return parts.find((part, idx) => idx > currentIdx && part instanceof DatePart);
  20. }
  21. toString() {
  22. return String(this.date);
  23. }
  24. }
  25. module.exports = DatePart;