A
A
aesfur2017-03-25 21:21:34
Django
aesfur, 2017-03-25 21:21:34

How to check if a time is in an interval?

class StopTime(models.Model):
    time_from = models.TimeField(verbose_name="Время от")
    time_to = models.TimeField(verbose_name="Время до")
    type= models.ForeignKey(Type)

Can you please tell me how to correctly check if the time is included in the time interval?
For example, the time is 23:00 in the interval from 22:00 to 06:00

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2017-03-25
@aesfur

so all intervals should start from 0 and end with 24. That is, you need to split your interval into two subintervals if the first value is greater than the second. Time to translate the absolute minutes of the day (how many minutes have passed since 00:00) - it will be easier to compare.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question