I am currently creating an interface for a personal project and need to include a field that contains a length of time that a task took to complete. What is the proper data type/format for expressing a length of time in TypeScript?
Here is my interface
export interface Task {
id: number,
name: string,
taskDate: Date,
taskDuration: {DURATION TYPE HERE}
}
I’ve seen several ways online to calculate a duration from 2 dates, so I could just use a taskStart and taskEnd and then calculate from there, but surely there is a way to simply enter a duration without having to perform a calculation.
>Solution :
ISO 8601 specifies a format for durations, which is pretty much industry standard.
Some examples:
P1D - one day
PT5H - 5 hours
P2YT2S - 2 years, 2 seconds
https://en.wikipedia.org/wiki/ISO_8601#Durations