Skip to content

Commit

Permalink
Make unix_time always return floats
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Nov 14, 2023
1 parent 3959345 commit 67c1ef8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions faker/providers/date_time/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ class Provider(BaseProvider):
if platform.system() == "Windows":

@property
def _rand_seconds(self):
def _rand_seconds(self) -> Callable[[int, int], int]:
return self.generator.random.randint

else:

@property
def _rand_seconds(self):
def _rand_seconds(self) -> Callable[[float, float], float]:
return self.generator.random.uniform

centuries: ElementsType[str] = [
Expand Down Expand Up @@ -1826,11 +1826,13 @@ def unix_time(
Get a timestamp between January 1, 1970 and now, unless passed
explicit start_datetime or end_datetime values.
:example: 1061306726
On Windows, the decimal part is always 0.
:example: 1061306726.6
"""
start_datetime = self._parse_start_datetime(start_datetime)
end_datetime = self._parse_end_datetime(end_datetime)
return self._rand_seconds(start_datetime, end_datetime)
return float(self._rand_seconds(start_datetime, end_datetime))

def time_delta(self, end_datetime: Optional[DateParseType] = None) -> timedelta:
"""
Expand Down

0 comments on commit 67c1ef8

Please sign in to comment.