| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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);
- }
- list.push(
- minList.map((item) => {
- return moment(`${i}:${item}`, 'H:m').format('HH:mm');
- })
- );
- } else {
- list.push(
- [0, 15, 30, 45].map((item) => {
- return moment(`${i}:${item}`, 'H:m').format('HH:mm');
- })
- );
- }
- }
- return list.flat();
- }
-
- getFormat(formatType){
- return this.time.format(formatType);
- }
- }
|