Repository: joke2k/faker

Issue:
Tests fail (on Xubuntu 14.04) due to timestamp out of range issue
Running the tests fail on my Xubuntu 14.04 virtual machine (32-bit with Python 2.7.6) due to a `ValueError: timestamp out of range for platform time_t` in L246 of `faker/providers/date_time.py`; see below for the output:

```
$ python setup.py test
running test
running egg_info
writing dependency_links to fake_factory.egg-info/dependency_links.txt
writing fake_factory.egg-info/PKG-INFO
writing top-level names to fake_factory.egg-info/top_level.txt
reading manifest file 'fake_factory.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'fake_factory.egg-info/SOURCES.txt'
running build_ext
test_add_provider_gives_priority_to_newly_added_provider (faker.tests.FactoryTestCase) ... ok
test_command (faker.tests.FactoryTestCase) ... 6588 Shasta Locks
South Tamikaville, CO 72509-4971


ok
test_documentor (faker.tests.FactoryTestCase) ... ERROR
test_format_calls_formatter_on_provider (faker.tests.FactoryTestCase) ... ok
test_format_transfers_arguments_to_formatter (faker.tests.FactoryTestCase) ... ok
test_get_formatter_returns_callable (faker.tests.FactoryTestCase) ... ok
test_get_formatter_returns_correct_formatter (faker.tests.FactoryTestCase) ... ok
test_get_formatter_throws_exception_on_incorrect_formatter (faker.tests.FactoryTestCase) ... ok
test_magic_call_calls_format (faker.tests.FactoryTestCase) ... ok
test_magic_call_calls_format_with_arguments (faker.tests.FactoryTestCase) ... ok
test_parse_returns_same_string_when_it_contains_no_curly_braces (faker.tests.FactoryTestCase) ... ok
test_parse_returns_string_with_tokens_replaced_by_formatters (faker.tests.FactoryTestCase) ... ok

======================================================================
ERROR: test_documentor (faker.tests.FactoryTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mdxs/dev/gh/faker/faker/tests.py", line 65, in test_documentor
    print_doc()
  File "/home/mdxs/dev/gh/faker/faker/cli.py", line 77, in print_doc
    formatters = doc.get_formatters(with_args=True, with_defaults=True)
  File "/home/mdxs/dev/gh/faker/faker/documentor.py", line 28, in get_formatters
    (provider, self.get_provider_formatters(provider, **kwargs))
  File "/home/mdxs/dev/gh/faker/faker/documentor.py", line 78, in get_provider_formatters
    example = self.generator.format(name)
  File "/home/mdxs/dev/gh/faker/faker/generator.py", line 56, in format
    return self.get_formatter(formatter)(*args, **kwargs)
  File "/home/mdxs/dev/gh/faker/faker/providers/date_time.py", line 246, in date_time_ad
    return datetime.fromtimestamp(random.randint(-62135600400, int(time())))
ValueError: timestamp out of range for platform time_t

----------------------------------------------------------------------
Ran 12 tests in 0.201s

FAILED (errors=1)
```



Discussion:
Same for the alternative test method (as mentioned in `README.md`):

```
$ python -m unittest -v faker.tests
test_add_provider_gives_priority_to_newly_added_provider (faker.tests.FactoryTestCase) ... ok
test_command (faker.tests.FactoryTestCase) ... 683 Russel Groves
Princehaven, CO 45021


ok
test_documentor (faker.tests.FactoryTestCase) ... ERROR
test_format_calls_formatter_on_provider (faker.tests.FactoryTestCase) ... ok
test_format_transfers_arguments_to_formatter (faker.tests.FactoryTestCase) ... ok
test_get_formatter_returns_callable (faker.tests.FactoryTestCase) ... ok
test_get_formatter_returns_correct_formatter (faker.tests.FactoryTestCase) ... ok
test_get_formatter_throws_exception_on_incorrect_formatter (faker.tests.FactoryTestCase) ... ok
test_magic_call_calls_format (faker.tests.FactoryTestCase) ... ok
test_magic_call_calls_format_with_arguments (faker.tests.FactoryTestCase) ... ok
test_parse_returns_same_string_when_it_contains_no_curly_braces (faker.tests.FactoryTestCase) ... ok
test_parse_returns_string_with_tokens_replaced_by_formatters (faker.tests.FactoryTestCase) ... ok

======================================================================
ERROR: test_documentor (faker.tests.FactoryTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "faker/tests.py", line 65, in test_documentor
    print_doc()
  File "faker/cli.py", line 77, in print_doc
    formatters = doc.get_formatters(with_args=True, with_defaults=True)
  File "faker/documentor.py", line 28, in get_formatters
    (provider, self.get_provider_formatters(provider, **kwargs))
  File "faker/documentor.py", line 78, in get_provider_formatters
    example = self.generator.format(name)
  File "faker/generator.py", line 56, in format
    return self.get_formatter(formatter)(*args, **kwargs)
  File "faker/providers/date_time.py", line 246, in date_time_ad
    return datetime.fromtimestamp(random.randint(-62135600400, int(time())))
ValueError: timestamp out of range for platform time_t

----------------------------------------------------------------------
Ran 12 tests in 0.185s

FAILED (errors=1)
```


Resolving patch:
diff --git a/faker/providers/date_time.py b/faker/providers/date_time.py
--- a/faker/providers/date_time.py
+++ b/faker/providers/date_time.py
@@ -243,7 +243,12 @@ def date_time_ad(cls):
         :example DateTime('1265-03-22 21:15:52')
         :return datetime
         """
-        return datetime.fromtimestamp(random.randint(-62135600400, int(time())))
+        ts = random.randint(-62135600400, int(time()))
+        # NOTE: using datetime.fromtimestamp(ts) directly will raise
+        #       a "ValueError: timestamp out of range for platform time_t"
+        #       on some platforms due to system C functions;
+        #       see http://stackoverflow.com/a/10588133/2315612
+        return datetime.fromtimestamp(0) + timedelta(seconds=ts)
 
     @classmethod
     def iso8601(cls):


Test patch: