Repository: lk-geimfari/mimesis

Issue:
Outdated “current” year
# Bug report

## What's wrong

Some providers return “current” dates from a few years ago, because they are hardwired to the “current” year from those times, such as:

- `mimesis.Datetime().week_date()`
- `mimesis.Datetime().date()`
- `mimesis.Development().version(calver=True)`
- `PolandSpecProvider().pesel()`

## How is that should be

Having a global `now` would break a lot of things, because with the same `seed`, we would get different results at each run.

Then maybe changing mimesis' versioning to calver and do such updates of default year with every major version? This would allow adding methods like `birthdate` to the `Person` provider as well.

## System information

Not relevant.


Discussion:
@eumiro I think that we need to make `end` parameter equal to `None` and use `datetime.now` when `end` was not passed. I think this is the easiest way to do it.
This would break the logic. Every time you initialize `mimesis` with the same seed and call the method with `None`, it will deliver different results.
Right, but this one will break things too:

```
Then maybe changing mimesis' versioning to calver and do such updates of default year
with every major version? This would allow adding methods like birthdate to 
the Person provider as well.
```


@sobolevn @ceccoemi Any suggestions?
@eumiro What if you pass parameters `start` and `end` explicitly?
> @eumiro What if you pass parameters `start` and `end` explicitly?

In that case it works as imagined, of course. The question is, how much code you want to let the user write.

There could be some global switch between deterministic (hardwired minimal and maximal year) and more realistic behavior (`datetime.utcnow`). Now the only realistic external factor is the clock, but mimesis could read and use the current locale (possible) or get the current location to generate random locations in the neighborhood (okay, this is already exaggerated but works as an example).
@eumiro Seems like the only way is changing `end` to current every year.
I mean the only way without breaking things. 
And we don't have to migrate to `calver`. We'll just mention such changes in CHANGELOG.

Resolving patch:
diff --git a/mimesis/providers/date.py b/mimesis/providers/date.py
--- a/mimesis/providers/date.py
+++ b/mimesis/providers/date.py
@@ -17,6 +17,9 @@
 class Datetime(BaseDataProvider):
     """Class for generating data related to the date and time."""
 
+    # See: https://git.io/Jf15A
+    CURRENT_YEAR = datetime.now().year
+
     def __init__(self, *args, **kwargs):
         """Initialize attributes.
 
@@ -72,7 +75,7 @@ def bulk_create_datetimes(date_start: DateTime,
 
         return dt_objects
 
-    def week_date(self, start: int = 2017, end: int = 2018) -> str:
+    def week_date(self, start: int = 2017, end: int = CURRENT_YEAR) -> str:
         """Get week number with year.
 
         :param start: From start.
@@ -106,7 +109,7 @@ def month(self, abbr: bool = False) -> str:
         months = self._data['month'].get(key)
         return self.random.choice(months)
 
-    def year(self, minimum: int = 1990, maximum: int = 2050) -> int:
+    def year(self, minimum: int = 1990, maximum: int = CURRENT_YEAR) -> int:
         """Generate a random year.
 
         :param minimum: Minimum value.
@@ -130,7 +133,7 @@ def periodicity(self) -> str:
         periodicity = self._data['periodicity']
         return self.random.choice(periodicity)
 
-    def date(self, start: int = 2000, end: int = 2019) -> Date:
+    def date(self, start: int = 2000, end: int = CURRENT_YEAR) -> Date:
         """Generate random date object.
 
         :param start: Minimum value of year.
@@ -205,7 +208,7 @@ def gmt_offset(self) -> str:
         """
         return self.random.choice(GMT_OFFSETS)
 
-    def datetime(self, start: int = 2000, end: int = 2035,
+    def datetime(self, start: int = 2000, end: int = CURRENT_YEAR,
                  timezone: Optional[str] = None) -> DateTime:
         """Generate random datetime.
 


Test patch:
diff --git a/tests/test_providers/test_datetime.py b/tests/test_providers/test_datetime.py
--- a/tests/test_providers/test_datetime.py
+++ b/tests/test_providers/test_datetime.py
@@ -47,9 +47,9 @@ def test_bulk_create_datetimes_error(self, _datetime):
             _datetime.bulk_create_datetimes(None, None)
 
     def test_year(self, _datetime):
-        result = _datetime.year(minimum=2000, maximum=2016)
+        result = _datetime.year(minimum=2000, maximum=_datetime.CURRENT_YEAR)
         assert result >= 2000
-        assert result <= 2016
+        assert result <= _datetime.CURRENT_YEAR
 
     def test_gmt_offset(self, _datetime):
         result = _datetime.gmt_offset()
@@ -60,9 +60,9 @@ def test_day_of_month(self, _datetime):
         assert ((result >= 1) or (result <= 31))
 
     def test_date(self, dt):
-        date_object = dt.date(start=1999, end=1999)
+        date_object = dt.date(start=dt.CURRENT_YEAR, end=dt.CURRENT_YEAR)
         assert isinstance(date_object, datetime.date)
-        assert date_object.year == 1999
+        assert date_object.year == dt.CURRENT_YEAR
 
     def test_formatted_date(self, dt):
         fmt_date = dt.formatted_date('%Y', start=2000, end=2000)
@@ -147,11 +147,11 @@ def test_formatted_datetime(self, _datetime, start, end):
         assert start <= int(dt_str) <= end
 
     def test_week_date(self, _datetime):
-        result = _datetime.week_date(start=2017, end=2018)
+        result = _datetime.week_date(start=2017, end=_datetime.CURRENT_YEAR)
         result = result.replace('-', ' ').replace('W', '')
         year, week = result.split(' ')
 
-        assert (int(year) >= 2017) and (int(year) <= 2018)
+        assert (int(year) >= 2017) and (int(year) <= _datetime.CURRENT_YEAR)
         assert int(week) <= 52