Exemple #1
0
    def cast_date(s):
        """Convert any date string found in WHOIS to a datetime object.
        """
        known_formats = [
            '%Y.%m.%d %H:%M:%S',  # 2000.01.02 17:46:33
            '%Y-%m-%d %H:%M:%S',
            '%Y-%m-%dT%H:%M:%S.000Z',
        ]

        for known_format in known_formats:
            try:
                return datetime.datetime.strptime(s.strip(), known_format)
            except ValueError as e:
                pass
        from whois.parser import cast_date
        return cast_date(s)
Exemple #2
0
    def cast_date(s):
        """Convert any date string found in WHOIS to a datetime object.
        """
        known_formats = [
            '%Y.%m.%d %H:%M:%S',                 # 2000.01.02 17:46:33
            '%Y-%m-%d %H:%M:%S',
            '%Y-%m-%dT%H:%M:%S.000Z',
            ]

        for known_format in known_formats:
            try:
                return datetime.datetime.strptime(s.strip(), known_format)
            except ValueError as e:
                pass
        from whois.parser import cast_date
        return cast_date(s)
Exemple #3
0
 def test_cast_date(self):
     dates = ['14-apr-2008', '2008-04-14']
     for d in dates:
         r = cast_date(d).strftime('%Y-%m-%d')
         self.assertEqual(r, '2008-04-14')
Exemple #4
0
 def test_cast_date(self):
     dates = ['14-apr-2008', '2008-04-14']
     for d in dates:
         r = cast_date(d).strftime('%Y-%m-%d')
         self.assertEquals(r, '2008-04-14')
Exemple #5
0
def test_cast_date():
    dates = ['14-apr-2008', '2008-04-14']
    for d in dates:
        r = cast_date(d).strftime('%Y-%m-%d')
        assert r == '2008-04-14'