Skip to content

Commit

Permalink
Revert "fix stubs and format code"
Browse files Browse the repository at this point in the history
This reverts commit 032a108.
  • Loading branch information
fcurella committed Oct 31, 2024
1 parent bd0e786 commit 74b9aa9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 46 deletions.
7 changes: 3 additions & 4 deletions faker/providers/date_time/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ def timestamp_to_datetime(timestamp: Union[int, float], tzinfo: Optional[TzInfo]

def maybe_format_as_string(func):
"""Format date as string if a pattern is provided."""

@functools.wraps(func)
def wrapper(*args, **kwargs):
result: dtdate = func(*args, **kwargs)
pattern = kwargs.get("pattern")
pattern = kwargs.get('pattern')
if pattern:
return result.strftime(pattern)
return result

return wrapper



def change_year(current_date: dtdate, year_diff: int) -> dtdate:
"""
Unless the current_date is February 29th, it is fine to just subtract years.
Expand Down Expand Up @@ -2075,7 +2074,7 @@ def date_time_between(
@maybe_format_as_string
def date_between(
self,
start_date: DateParseType = "-30y",
start_date: DateParseType = "-30y",
end_date: DateParseType = "today",
pattern: Optional[str] = None,
) -> Union[dtdate, str]:
Expand Down
59 changes: 17 additions & 42 deletions faker/proxy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -970,34 +970,30 @@ class Faker:
self,
start_date: Union[datetime.date, datetime.datetime, datetime.timedelta, str, int] = ...,
end_date: Union[datetime.date, datetime.datetime, datetime.timedelta, str, int] = ...,
pattern: Optional[str] = ...,
) -> Union[datetime.date, str]:
) -> datetime.date:
"""
Get a Date object based on a random date between two given dates.
Accepts date strings that can be recognized by strtotime().
:param start_date: Defaults to 30 years ago
:param end_date: Defaults to "today"
:param pattern: optional pattern to format the date as string
:example: Date('1999-02-02') or '1999-02-02'
:return: Date or string
:example: Date('1999-02-02')
:return: Date
"""
...

def date_between_dates(
self,
date_start: Union[datetime.date, datetime.datetime, datetime.timedelta, str, int, None] = ...,
date_end: Union[datetime.date, datetime.datetime, datetime.timedelta, str, int, None] = ...,
pattern: Optional[str] = ...,
) -> Union[datetime.date, str]:
) -> datetime.date:
"""
Takes two Date objects and returns a random date between the two given dates.
Accepts Date or datetime objects
:param date_start: Date
:param date_end: Date
:param pattern: optional pattern to format the date as string
:return: Date or string
:return: Date
"""
...

Expand All @@ -1010,12 +1006,8 @@ class Faker:
...

def date_of_birth(
self,
tzinfo: Optional[datetime.tzinfo] = ...,
minimum_age: int = ...,
maximum_age: int = ...,
pattern: Optional[str] = ...,
) -> Union[datetime.date, str]:
self, tzinfo: Optional[datetime.tzinfo] = ..., minimum_age: int = ..., maximum_age: int = ...
) -> datetime.date:
"""
Generate a random date of birth represented as a Date object,
constrained by optional miminimum_age and maximum_age
Expand All @@ -1024,64 +1016,51 @@ class Faker:
:param tzinfo: Defaults to None.
:param minimum_age: Defaults to 0.
:param maximum_age: Defaults to 115.
:param pattern: optional pattern to format the date as string
:example: Date('1979-02-02')
:return: Date
"""
...

def date_this_century(
self, before_today: bool = ..., after_today: bool = ..., pattern: Optional[str] = ...
) -> Union[datetime.date, str]:
def date_this_century(self, before_today: bool = ..., after_today: bool = ...) -> datetime.date:
"""
Gets a Date object for the current century.
:param before_today: include days in current century before today
:param after_today: include days in current century after today
:param pattern: optional pattern to format the date as string
:example: Date('2012-04-04')
:return: Date or string
:return: Date
"""
...

def date_this_decade(
self, before_today: bool = ..., after_today: bool = ..., pattern: Optional[str] = ...
) -> Union[datetime.date, str]:
def date_this_decade(self, before_today: bool = ..., after_today: bool = ...) -> datetime.date:
"""
Gets a Date object for the decade year.
:param before_today: include days in current decade before today
:param after_today: include days in current decade after today
:param pattern: optional pattern to format the date as string
:example: Date('2012-04-04')
:return: Date or string
:return: Date
"""
...

def date_this_month(
self, before_today: bool = ..., after_today: bool = ..., pattern: Optional[str] = ...
) -> Union[datetime.date, str]:
def date_this_month(self, before_today: bool = ..., after_today: bool = ...) -> datetime.date:
"""
Gets a Date object for the current month.
:param before_today: include days in current month before today
:param after_today: include days in current month after today
:param pattern: optional pattern to format the date as string
:example: dtdate('2012-04-04')
:return: dtdate or string
:return: dtdate
"""
...

def date_this_year(
self, before_today: bool = ..., after_today: bool = ..., pattern: Optional[str] = ...
) -> Union[datetime.date, str]:
def date_this_year(self, before_today: bool = ..., after_today: bool = ...) -> datetime.date:
"""
Gets a Date object for the current year.
:param before_today: include days in current year before today
:param after_today: include days in current year after today
:param pattern: optional pattern to format the date as string
:example: Date('2012-04-04')
:return: Date
"""
Expand Down Expand Up @@ -1215,16 +1194,14 @@ class Faker:
self,
end_date: Union[datetime.date, datetime.datetime, datetime.timedelta, str, int] = ...,
tzinfo: Optional[datetime.tzinfo] = ...,
pattern: Optional[str] = ...,
) -> Union[datetime.date, str]:
) -> datetime.date:
"""
Get a Date object based on a random date between 1 day from now and a
given date.
Accepts date strings that can be recognized by strtotime().
:param end_date: Defaults to "+30d"
:param tzinfo: timezone, instance of datetime.tzinfo subclass
:param pattern: optional pattern to format the date as string
:example: dtdate('2030-01-01')
:return: dtdate
"""
Expand Down Expand Up @@ -1270,18 +1247,16 @@ class Faker:
self,
start_date: Union[datetime.date, datetime.datetime, datetime.timedelta, str, int] = ...,
tzinfo: Optional[datetime.tzinfo] = ...,
pattern: Optional[str] = ...,
) -> Union[datetime.date, str]:
) -> datetime.date:
"""
Get a Date object based on a random date between a given date and 1 day
ago.
Accepts date strings that can be recognized by strtotime().
:param start_date: Defaults to "-30d"
:param tzinfo: timezone, instance of datetime.tzinfo subclass
:param pattern: optional pattern to format the date as string
:example: dtdate('1999-02-02')
:return: dtdate or string
:return: dtdate
"""
...

Expand Down

0 comments on commit 74b9aa9

Please sign in to comment.