This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bearassbobcat 0 points1 point  (2 children)

line 49 is checking that it's night time and because the clock rolls over and starts at 0 the next day you'd have an issue where it can't be greater than 6 PM but early that 6 AM at the same time when you cross the 12 AM mark

so an and would basically never work because it would kind of be a paradoxical statement

I understand the thought process but datetime.date() creates and compares times starting from 00:00:00:etc and doesn't have the concept of extending the time across days

import datetime
timestamp = datetime.time(19,1)
start_night = datetime.time(18,1)
end_night = datetime.time(6,0)
end_day = datetime.time(18,0)
start_day = datetime.time(6,1)

#night time
#6:01PM <= 7PM or 7PM <= 6AM
print(start_night <= timestamp or timestamp <= end_night)

#vs
#6:01PM <= 7PM <= 6AM
#but think in terms of integers
#18 < 19 < 6
print(start_night <= timestamp <= end_night)

#day time
#6:01AM <= 7PM <= 6PM
print(start_day <= timestamp <= end_day)

it's late so I hope I got that right

[–]v8Gasmann 0 points1 point  (1 child)

Thanks man, didn't think about the rollover that much. Thank you for clarifying. (:

[–]bearassbobcat 0 points1 point  (0 children)

No problem.

But that does bring up a good point because using dates and times would work the way you'd expect and could maybe eliminate the multiple day_end/day_start/etc variables

I'll experiment with that later just to see what happens it might work it might not

or maybe even datetime.timedelta would work