| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import moment from 'moment';
- export default class Time {
- constructor(time = new Date(), format = '') {
- this.time = moment(time, format);
- }
- getNowTime(format) {
- return moment(this.time.format('X') - moment().format('X'), 'X').format(
- format
- );
- }
- addTime(time, formatType) {
- return this.time.add(time, 'hours').format(formatType);
- }
- nextList() {
- const time2 = this.time.add(1, 'hours');
- const hour = Number(time2.format('H'));
- const list = [];
- for (let i = hour; i < 24; i++) {
- if (hour === i) {
- const min = Number(time2.format('s'));
- const minList = [];
- if (min <= 0) {
- minList.push(0);
- }
- if (min <= 15) {
- minList.push(15);
- }
- if (min <= 30) {
- minList.push(30);
- }
- if (min <= 45) {
- minList.push(45);
- }
- minList.forEach((item) => {
- list.push(moment(`${i}:${item}`, 'H:m').format('HH:mm'));
- });
- } else {
- [0, 15, 30, 45].forEach((item) => {
- list.push(moment(`${i}:${item}`, 'H:m').format('HH:mm'));
- });
- }
- }
- return list;
- }
- getFormat(formatType) {
- return this.time.format(formatType);
- }
- }
|