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

Allow time to wrap around midnight #160

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions backend/app/get_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
SELECT 1 FROM ref.holiday WHERE ta.dt = holiday.dt
)'''

# if end_time is less than the start_time, then we wrap around midnight
ToD_and_or = 'AND' if end_time > start_time else 'OR'

query = f'''
SELECT
link_dir,
Expand All @@ -45,8 +48,10 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
FROM here.ta
WHERE
link_dir = ANY(%(link_dir_list)s)
AND tod >= %(start_time)s::time
AND tod < %(end_time)s::time
AND (
tod >= %(start_time)s::time
{ToD_and_or} tod < %(end_time)s::time
)
AND date_part('ISODOW', dt) = ANY(%(dow_list)s)
AND dt >= %(start_date)s::date
AND dt < %(end_date)s::date
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/timeRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class TimeRange extends Factor {
if(!(this.#startTime && this.#endTime)){
return false
}
return this.startHour < this.endHour
return this.startHour != this.endHour
}
get name(){
if(this.#startTime || this.#endTime){
Expand Down Expand Up @@ -68,7 +68,11 @@ export class TimeRange extends Factor {
}
get hoursInRange(){ // how many hours are in the timeRange?
if(! this.isComplete){ return undefined }
return this.endHour - this.startHour
if(this.endHour > this.startHour){
return this.endHour - this.startHour
} else {
return 24 - this.startHour + this.endHour
}
}
}

Expand Down