With python3.8 date_time_between_dates returns faker.utils.datetime_safe.datetime instead of datetime.datetime
See original GitHub issue- Faker version: 4.1.0
- OS: Linux
- Python3.8
Brief summary of the issue goes here.
date_time_between_dates
return faker.utils.datetime_safe.datetime
instead of datetime.datetime
Problem stem from solution of python bug: https://bugs.python.org/issue32417
Faker works fine with earlier version of python (eg 3.7)
Steps to reproduce
from datetime import datetime, timedelta
from faker import Faker
fake = Faker()
Faker.seed(0)
fake_date = fake.date_time_between_dates(
datetime_start=datetime.utcnow() - timedelta(days=360),
datetime_end=datetime.utcnow(),
tzinfo=None
)
print(type(fake_date))
Expected behavior
output: <class ‘datetime.datetime’>
Actual behavior
output: <class ‘faker.utils.datetime_safe.datetime’>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Python Faker Datetime Generation returns tuple with datetime ...
The comparision fails as i try to compare a datetime object with a tuple which has a datetime object in it. If I...
Read more >datetime — Basic date and time types — Python 3.11.1 ...
Return a string representing the date, controlled by an explicit format string. Format codes referring to hours, minutes or seconds will see 0...
Read more >faker.providers.date_time — Faker 15.3.4 documentation
Takes two datetime objects and returns a random datetime between the two given datetimes. Accepts datetime objects. Parameters: datetime_start – datetime ...
Read more >Using Python datetime to Work With Dates and Times
Have you ever wondered about working with dates and times in Python? In this tutorial, you'll learn all about the built-in Python datetime...
Read more >How to use the datetime.tzinfo function in DateTime - Snyk
To help you get started, we've selected a few datetime.tzinfo examples, ... import six from faker import Faker from faker.providers.date_time import ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My understanding is that Faker only supports Python >= 3.5 (from the
.travis.yml
).If that’s the case then I think it should be acceptable to remove the workaround which subtypes
datetime
. According to the comment it’s only needed to supportstrftime
on dates before 1900. From my testing it appears that’s only a problem for older versions of Python:Python 2.7:
Python 3.5
I think PR #1258 should fix this.
Closed in #1258