Autofill data between times

This commit is contained in:
2023-12-19 17:47:24 +08:00
parent 46ec332298
commit 810c301398
2 changed files with 58 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import moment from 'moment/moment'
import moment, { unitOfTime } from 'moment/moment'
import dayjs from 'dayjs'
export const getNowLocalTime = (format: string = 'yyyy-MM-DD HH:mm:ssZ') => {
@@ -36,3 +36,22 @@ export const utcToMillisecond = (utcTime: string) => {
export const millisecondToUtc = (millisecond: number) => {
return moment(millisecond).toISOString()
}
export const getTimesBetweenTwoTimes = (
startTime: string,
endTime: string,
interval: unitOfTime.Diff
) => {
const timesList: string[] = []
const start = moment.utc(startTime)
const end = moment.utc(endTime)
const count = end.diff(start, interval)
timesList.push(start.toISOString())
for (let i = 0; i < count; i++) {
timesList.push(start.add(1, interval).toISOString())
}
return timesList
}