kalkutago/client/src/ticks.ts

66 lines
1.4 KiB
TypeScript

interface ITick {
id: number
track_id?: number
year?: number
month?: number
day?: number
hour?: number
minute?: number
second?: number
has_time_info?: number
}
class Tick implements ITick {
id: number
track_id?: number
year?: number
month?: number
day?: number
hour?: number
minute?: number
second?: number
has_time_info?: number
constructor(id: number,
track_id?: number,
year?: number,
month?: number,
day?: number,
hour?: number,
minute?: number,
second?: number,
has_time_info?: number,
) {
this.id = id
this.track_id = track_id
this.year = year
this.month = month
this.day = day
this.hour = hour
this.minute = minute
this.second = second
this.has_time_info = has_time_info
}
static fromJSON(tick: ITick): Tick {
return new Tick(
tick.id,
tick.track_id,
tick.year,
tick.month,
tick.day,
tick.hour,
tick.minute,
tick.second,
tick.has_time_info,
)
}
date(): Date | null {
if (this.year && this.month && this.day && this.hour && this.minute && this.second) {
return new Date(this.year!, this.month!, this.day, this.hour, this.minute, this.second)
}
return null
}
}