implement ISO date to facilitate all the store values
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
|
import type { ISODate } from '@/shared/types/date'
|
||||||
|
|
||||||
export interface Recordable {
|
export interface Recordable {
|
||||||
id: string
|
id: string
|
||||||
taskId: string
|
taskId: string
|
||||||
start: Date
|
start: ISODate
|
||||||
end?: Date
|
end?: ISODate
|
||||||
stepRecords: Record<string, { start: Date; end?: Date }>
|
stepRecords: Record<string, { start: ISODate; end?: ISODate }>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
import { toISODate, type ISODate } from '@/shared/types/date'
|
||||||
import type { Recordable } from '../interfaces/recordable'
|
import type { Recordable } from '../interfaces/recordable'
|
||||||
|
|
||||||
export class TaskRecord implements Recordable {
|
export class TaskRecord implements Recordable {
|
||||||
public start: Date = new Date()
|
public start: ISODate = toISODate(new Date())
|
||||||
public end: Date | undefined = undefined
|
public end: ISODate | undefined = undefined
|
||||||
public stepRecords: Record<string, { start: Date; end?: Date }> = {}
|
public stepRecords: Record<string, { start: ISODate; end?: ISODate }> = {}
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
public readonly id: string,
|
public readonly id: string,
|
||||||
@@ -15,7 +16,8 @@ export class TaskRecord implements Recordable {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const durationMilliseconds = this.end.getTime() - this.start.getTime()
|
const durationMilliseconds =
|
||||||
|
new Date(this.end).getTime() - new Date(this.start).getTime()
|
||||||
|
|
||||||
return Math.round(durationMilliseconds / (1000 * 60))
|
return Math.round(durationMilliseconds / (1000 * 60))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import type { Recordable } from '../interfaces/recordable'
|
import type { Recordable } from '../interfaces/recordable'
|
||||||
|
|
||||||
interface StoredTaskRecordable
|
|
||||||
extends Omit<Recordable, 'start' | 'end' | 'stepRecords'> {
|
|
||||||
start: string
|
|
||||||
end?: string
|
|
||||||
stepRecords: Record<string, { start: string; end?: string }>
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TaskRecordStoreState {
|
export interface TaskRecordStoreState {
|
||||||
records: { [taskId: string]: StoredTaskRecordable[] }
|
records: { [taskId: string]: Recordable[] }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useTaskRecordStore = defineStore('task-record-store', {
|
export const useTaskRecordStore = defineStore('task-record-store', {
|
||||||
|
|||||||
3
src/shared/types/date.ts
Normal file
3
src/shared/types/date.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export type ISODate = string
|
||||||
|
|
||||||
|
export const toISODate = (date: Date): ISODate => date.toISOString()
|
||||||
Reference in New Issue
Block a user