Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle time-wrapping at midnight (0h vs 24h bug) #110

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions frontend/src/timeRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ export class TimeRange extends Factor {
constructor(dataContext){
super(dataContext)
}
// returns values 0-23
get startHour(){ return this.#startTime?.getHours() }
get endHour(){ return this.#endTime?.getHours() }
// returns values 1-24
get endHour(){
// values 0-23
// BUT if the final hour is midnight, return 24 instead of zero
const hour = this.#endTime?.getHours()
return hour > 0 ? hour : 24
}
get isComplete(){
return this.#startTime && this.#endTime && this.#startTime < this.#endTime
if(!(this.#startTime && this.#endTime)){
return false
}
return this.startHour < this.endHour
}
get name(){
if(this.#startTime || this.#endTime){
Expand Down Expand Up @@ -56,7 +66,7 @@ export class TimeRange extends Factor {
}
get hoursInRange(){ // how many hours are in the timeRange?
if(! this.isComplete){ return undefined }
return this.#endTime.getHours() - this.#startTime.getHours()
return this.endHour - this.startHour
}
}

Expand Down
Loading