Ejemplo n.º 1
0
    def test_fromdatetime(self):
        rdt = RelativeDateTime.fromdatetime(datetime(2016, 1, 1, 15, 45),
                                            offset=timedelta(minutes=15))

        assert rdt == datetime(2016, 1, 1, 16)
        assert rdt == RelativeDateTime(
            clock=lambda: datetime(2016, 1, 1, 15, 45),
            offset=timedelta(minutes=15))
Ejemplo n.º 2
0
    def test_relative_datetime_astimezone(self):
        rdt = RelativeDateTime.fromdatetime(
            datetime(2016, 1, 1, tzinfo=UTC)
        ).astimezone(
            UTCPlusOne
        )  # noqa

        assert rdt == datetime(2016, 1, 1, 1, tzinfo=UTCPlusOne)
Ejemplo n.º 3
0
    def test_fromdatetime(self):
        rdt = RelativeDateTime.fromdatetime(
            datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15)
        )

        assert rdt == datetime(2016, 1, 1, 16)
        assert rdt == RelativeDateTime(
            clock=lambda: datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15)
        )
Ejemplo n.º 4
0
    def test_relative_datetime_fromdate(self):
        rdt = RelativeDateTime.fromdate(date(2016, 1, 1))

        assert rdt == RelativeDateTime.fromdatetime(datetime(2016, 1, 1))
Ejemplo n.º 5
0
 def test_relativedatetime_today(self, monkeypatch):
     monkeypatch.setattr("datestuff.relative.datetime", FakeDateTime)
     assert RelativeDateTime.today() == NOW
Ejemplo n.º 6
0
 def test_relative_datetime_utcnow(self, monkeypatch):
     monkeypatch.setattr("datestuff.relative.datetime", FakeDateTime)
     rdt = RelativeDateTime.utcnow(offset=timedelta(days=5))
     assert rdt == FakeDateTime.utcnow() + timedelta(days=5)
Ejemplo n.º 7
0
 def test_asdate(self):
     rdt = RelativeDateTime.fromdatetime(datetime(2016, 1, 1, 15)).as_date()
     assert rdt == date(2016, 1, 1)
Ejemplo n.º 8
0
    def test_relative_datetime_now(self, monkeypatch):
        monkeypatch.setattr("datestuff.relative.datetime", FakeDateTime)
        rdt = RelativeDateTime.now()

        # just need to know it is close enough
        assert within_delta(rdt, FakeDateTime.now(), timedelta(seconds=1))
Ejemplo n.º 9
0
    def test_relative_datetime_now_with_tzinfo(self, monkeypatch):
        monkeypatch.setattr("datestuff.relative.datetime", FakeDateTime)
        rdt = RelativeDateTime.now(UTC)

        assert within_delta(rdt, FakeDateTime.now(UTC), timedelta(seconds=1))
Ejemplo n.º 10
0
    def test_asdatetime(self):
        rdt = RelativeDateTime.fromdatetime(
            datetime(2016, 1, 1, 15,
                     45), offset=timedelta(minutes=15)).as_datetime()

        assert rdt == datetime(2016, 1, 1, 16)
Ejemplo n.º 11
0
 def test_asdate(self):
     rdt = RelativeDateTime.fromdatetime(datetime(2016, 1, 1, 15)).as_date()
     assert rdt == date(2016, 1, 1)
Ejemplo n.º 12
0
 def test_relativedatetime_today(self, monkeypatch):
     monkeypatch.setattr('datestuff.relative.datetime', FakeDateTime)
     assert RelativeDateTime.today() == NOW
Ejemplo n.º 13
0
    def test_replace_with_date_arguments(self):
        rd = RelativeDateTime.fromdate(date(2016, 1, 1)).replace(
            year=2015, day=2, month=2
        )

        assert rd.as_date() == date(2015, 2, 2)
Ejemplo n.º 14
0
    def test_relative_datetime_fromdate(self):
        rdt = RelativeDateTime.fromdate(date(2016, 1, 1))

        assert rdt == RelativeDateTime.fromdatetime(datetime(2016, 1, 1))
Ejemplo n.º 15
0
    def test_relative_datetime_astimezone(self):
        rdt = RelativeDateTime.fromdatetime(datetime(2016, 1, 1,
                                                     tzinfo=UTC)).astimezone(
                                                         UTCPlusOne)  # noqa

        assert rdt == datetime(2016, 1, 1, 1, tzinfo=UTCPlusOne)
Ejemplo n.º 16
0
 def test_relative_datetime_utcnow(self, monkeypatch):
     monkeypatch.setattr('datestuff.relative.datetime', FakeDateTime)
     rdt = RelativeDateTime.utcnow(offset=timedelta(days=5))
     assert rdt == FakeDateTime.utcnow() + timedelta(days=5)
Ejemplo n.º 17
0
    def test_relative_datetime_now_with_tzinfo(self, monkeypatch):
        monkeypatch.setattr('datestuff.relative.datetime', FakeDateTime)
        rdt = RelativeDateTime.now(UTC)

        assert within_delta(rdt, FakeDateTime.now(UTC), timedelta(seconds=1))
Ejemplo n.º 18
0
    def test_relative_datetime_now(self, monkeypatch):
        monkeypatch.setattr('datestuff.relative.datetime', FakeDateTime)
        rdt = RelativeDateTime.now()

        # just need to know it is close enough
        assert within_delta(rdt, FakeDateTime.now(), timedelta(seconds=1))
Ejemplo n.º 19
0
    def test_replace_with_offset_argument(self):
        rd = RelativeDateTime.fromdate(TODAY).replace(offset=timedelta(days=5))

        assert rd == RelativeDateTime.fromdate(TODAY, offset=timedelta(days=5))
Ejemplo n.º 20
0
    def test_asdatetime(self):
        rdt = RelativeDateTime.fromdatetime(
            datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15)
        ).as_datetime()

        assert rdt == datetime(2016, 1, 1, 16)