Example #1
0
def test_is_whole_day_wintertime():

    start = sedate.standardize_date(datetime(2015, 3, 29, 0, 0, 0),
                                    'Europe/Zurich')

    end = sedate.standardize_date(datetime(2015, 3, 29, 23, 59, 59),
                                  'Europe/Zurich')

    assert sedate.is_whole_day(start, end, 'Europe/Zurich')
    assert not sedate.is_whole_day(start, end, 'Europe/Istanbul')
Example #2
0
def test_is_whole_day_summertime():

    start = sedate.standardize_date(datetime(2014, 10, 26, 0, 0, 0),
                                    'Europe/Zurich')

    end = sedate.standardize_date(datetime(2014, 10, 26, 23, 59, 59),
                                  'Europe/Zurich')

    assert sedate.is_whole_day(start, end, 'Europe/Zurich')
    assert not sedate.is_whole_day(start, end, 'Europe/Istanbul')
Example #3
0
def test_require_timezone_awareness():

    naive = datetime(2014, 10, 26, 0, 0, 0)

    with pytest.raises(sedate.NotTimezoneAware):
        sedate.to_timezone(naive, 'UTC')

    with pytest.raises(sedate.NotTimezoneAware):
        sedate.is_whole_day(naive, naive, 'UTC')

    with pytest.raises(sedate.NotTimezoneAware):
        sedate.align_date_to_day(naive, 'UTC', 'up')
Example #4
0
def is_valid_reservation_length(start, end, timezone):
    start = sedate.standardize_date(start, timezone)
    end = sedate.standardize_date(end, timezone)

    hours = (end - start).total_seconds() // 3600

    if hours < 24:
        return True

    if sedate.is_whole_day(start, end, timezone) and hours <= 25:
        return True

    return False
Example #5
0
def test_is_whole_day():
    assert sedate.is_whole_day(
        sedate.replace_timezone(
            datetime(2015, 6, 30), 'Europe/Zurich'),
        sedate.replace_timezone(
            datetime(2015, 7, 1), 'Europe/Zurich'),
        'Europe/Zurich'
    )

    assert sedate.is_whole_day(
        sedate.replace_timezone(
            datetime(2015, 6, 30), 'Europe/Zurich'),
        sedate.replace_timezone(
            datetime(2015, 6, 30, 23, 59, 59), 'Europe/Zurich'),
        'Europe/Zurich'
    )

    assert not sedate.is_whole_day(
        sedate.replace_timezone(
            datetime(2015, 6, 30), 'Europe/Zurich'),
        sedate.replace_timezone(
            datetime(2015, 6, 30, 1), 'Europe/Zurich'),
        'Europe/Zurich'
    )
    assert not sedate.is_whole_day(
        sedate.replace_timezone(
            datetime(2015, 6, 30), 'Europe/Zurich'),
        sedate.replace_timezone(
            datetime(2015, 6, 30, 23, 59, 58), 'Europe/Zurich'),
        'Europe/Zurich'
    )
    assert not sedate.is_whole_day(
        sedate.replace_timezone(
            datetime(2015, 6, 30, 0, 0, 0, 999), 'Europe/Zurich'),
        sedate.replace_timezone(
            datetime(2015, 6, 30, 23, 59, 59), 'Europe/Zurich'),
        'Europe/Zurich'
    )
Example #6
0
    def whole_day(self):
        """True if the allocation is a whole-day allocation.

        A whole-day allocation is not really special. It's just an allocation
        which starts at 0:00 and ends at 24:00 (or 23:59:59'999). Relative
        to its timezone.

        As such it can actually also span multiple days, only hours and minutes
        count.

        The use of this is to display allocations spanning days differently.
        """

        s, e = self.display_start(), self.display_end()
        assert s != e  # this can never be, except when caused by cosmic rays

        return sedate.is_whole_day(s, e, self.timezone)