コード例 #1
0
    def test_ewsdate(self):
        self.assertEqual(EWSDate(2000, 1, 1).ewsformat(), "2000-01-01")
        self.assertEqual(EWSDate.from_string("2000-01-01"),
                         EWSDate(2000, 1, 1))
        self.assertEqual(EWSDate.from_string("2000-01-01Z"),
                         EWSDate(2000, 1, 1))
        self.assertEqual(EWSDate.from_string("2000-01-01+01:00"),
                         EWSDate(2000, 1, 1))
        self.assertEqual(EWSDate.from_string("2000-01-01-01:00"),
                         EWSDate(2000, 1, 1))
        self.assertIsInstance(
            EWSDate(2000, 1, 2) - EWSDate(2000, 1, 1), datetime.timedelta)
        self.assertIsInstance(
            EWSDate(2000, 1, 2) + datetime.timedelta(days=1), EWSDate)
        self.assertIsInstance(
            EWSDate(2000, 1, 2) - datetime.timedelta(days=1), EWSDate)

        # Test in-place add and subtract
        dt = EWSDate(2000, 1, 2)
        dt += datetime.timedelta(days=1)
        self.assertIsInstance(dt, EWSDate)
        self.assertEqual(dt, EWSDate(2000, 1, 3))
        dt = EWSDate(2000, 1, 2)
        dt -= datetime.timedelta(days=1)
        self.assertIsInstance(dt, EWSDate)
        self.assertEqual(dt, EWSDate(2000, 1, 1))

        with self.assertRaises(TypeError):
            EWSDate.from_date(EWSDate(2000, 1, 2))

        self.assertEqual(EWSDate.fromordinal(730120), EWSDate(2000, 1, 1))
コード例 #2
0
ファイル: common.py プロジェクト: mvasagam/exchangelib
def get_random_date(start_date=EWSDate(1996, 1, 1),
                    end_date=EWSDate(2030, 1, 1)):
    # Keep with a reasonable date range. A wider date range is unstable WRT timezones
    return EWSDate.fromordinal(
        random.randint(start_date.toordinal(), end_date.toordinal()))
コード例 #3
0
ファイル: __init__.py プロジェクト: xmkevinchen/exchangelib
def get_random_date(start_date=date(1900, 1, 1), end_date=date(2100, 1, 1)):
    return EWSDate.fromordinal(random.randint(start_date.toordinal(), end_date.toordinal()))