Beispiel #1
0
def test_align_date_to_day_summertime():

    unaligned = sedate.standardize_date(datetime(2016, 3, 27, 1),
                                        'Europe/Zurich')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'down')

    assert aligned.isoformat() == '2016-03-26T23:00:00+00:00'

    unaligned = sedate.standardize_date(datetime(2016, 3, 27, 4),
                                        'Europe/Zurich')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'down')

    assert aligned.isoformat() == '2016-03-26T23:00:00+00:00'

    unaligned = sedate.standardize_date(datetime(2016, 3, 27, 1),
                                        'Europe/Zurich')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'up')

    assert aligned.isoformat() == '2016-03-27T21:59:59.999999+00:00'

    unaligned = sedate.standardize_date(datetime(2016, 3, 27, 4),
                                        'Europe/Zurich')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'up')

    assert aligned.isoformat() == '2016-03-27T21:59:59.999999+00:00'
Beispiel #2
0
def test_align_date_to_day_wintertime():

    unaligned = sedate.standardize_date(datetime(2016, 10, 30, 1),
                                        'Europe/Zurich')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'down')

    assert aligned.isoformat() == '2016-10-29T22:00:00+00:00'

    unaligned = sedate.standardize_date(datetime(2016, 10, 30, 4),
                                        'Europe/Zurich')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'down')

    assert aligned.isoformat() == '2016-10-29T22:00:00+00:00'

    unaligned = sedate.standardize_date(datetime(2016, 10, 30, 1),
                                        'Europe/Zurich')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'up')

    assert aligned.isoformat() == '2016-10-30T22:59:59.999999+00:00'

    unaligned = sedate.standardize_date(datetime(2016, 10, 30, 4),
                                        'Europe/Zurich')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'up')

    assert aligned.isoformat() == '2016-10-30T22:59:59.999999+00:00'
Beispiel #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')
Beispiel #4
0
def test_align_date_to_day_up():
    unaligned = sedate.standardize_date(datetime(2012, 1, 24, 10), 'UTC')
    aligned = sedate.align_date_to_day(unaligned, 'Europe/Zurich', 'up')

    assert aligned.tzname() == 'UTC'
    assert aligned == sedate.standardize_date(
        datetime(2012, 1, 24, 23, 59, 59, 999999), 'Europe/Zurich')

    already_aligned = sedate.replace_timezone(
        datetime(2012, 1, 1, 23, 59, 59, 999999), 'Europe/Zurich')

    assert already_aligned == sedate.align_date_to_day(already_aligned,
                                                       'Europe/Zurich', 'up')