Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FutureDatetime and PastDatetime providers #779

Closed
wants to merge 8 commits into from

Conversation

sinecode
Copy link
Contributor

@sinecode sinecode commented Dec 12, 2019

I have made things!

Checklist

  • I'm sure that I did not unrelated changes in this pull request
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the CHANGELOG.rst

Related issues

Format is:

@lk-geimfari
@sobolevn

Before I continue any further, I'd like to know what do you think about this approach.

FutureDatetime is a subclass of Datetime. It takes some argument in the __init__() function to specify how much time to shift from the time when it's initialized.

All the methods that take as argument a start date are overrided and start is replaced with the current future. The end argument is set in a way that the timedelta from start to end is the same in Datetime and in FutureDatetime. For example in Datetime.week_date(), start=2017 and end=2018, there is a year of difference in the default arguments, so in FutureDatetime, by default, we have start=self.future.year and end=self.future.year+1.

@lk-geimfari
Copy link
Owner

@ceccoemi I see you have requested a review, but as I can judge there is only one method implemented in the provider. Did you request a review to illustrate the idea?

@sinecode
Copy link
Contributor Author

@ceccoemi I see you have requested a review, but as I can judge there is only one method implemented in the provider. Did you request a review to illustrate the idea?

@lk-geimfari yes exactly, I don't want to write a big amount of code and then discover that you don't like my solutions. The other methods will be implemented with the same approach.

@lk-geimfari
Copy link
Owner

@ceccoemi I agree. It's better to discuss solutions. Well, it looks good for me. @sobolevn What do you think? Any comments?

@sinecode sinecode changed the title Add week_date() in the FutureDatetime provider FutureDatetime and PastDatetime providers Dec 12, 2019
@codecov
Copy link

codecov bot commented Dec 12, 2019

Codecov Report

Merging #779 into master will increase coverage by 0.29%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #779      +/-   ##
==========================================
+ Coverage   98.54%   98.83%   +0.29%     
==========================================
  Files          60       60              
  Lines        1919     1971      +52     
==========================================
+ Hits         1891     1948      +57     
+ Misses         28       23       -5

Comment on lines 276 to 286
self._dt = Datetime(*args, **kwargs)
self.day_of_week = self._dt.day_of_week
self.month = self._dt.month
self.century = self._dt.century
self.periodicity = self._dt.periodicity
self.time = self._dt.time
self.formatted_time = self._dt.formatted_time
self.day_of_month = self._dt.day_of_month
self.timezone = self._dt.timezone
self.gmt_offset = self._dt.gmt_offset
self.timestamp = self._dt.timestamp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lk-geimfari @sobolevn I had to switch to composition instead of inheritance because of the incompatibility with the overloaded methods.

I know this section is a bit tricky. It can be replaced with:

        self._dt = Datetime(*args, **kwargs)
        for method in (
            m for m in dir(Datetime)
            if callable(getattr(Datetime, m))
            and not m.startswith('_')
            and m not in dir(FutureDatetime)
        ):
            setattr(self, method, getattr(self._dt, method))

which it automatically adds the methods not overridden, but it is more black magic and less explicit. What do you prefer?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ceccoemi I think that we need to implement only some methods in this provider, not all of them. We must decide which methods can be really useful in FutureDatetime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lk-geimfari ok, if you don't want all the methods then it's really easy.

I propose to keep date, formatted_date, datetime, formatted_datetime and timestamp only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lk-geimfari see my last commit!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ceccoemi I agree with your propose.

lk-geimfari
lk-geimfari previously approved these changes Dec 13, 2019
@sinecode sinecode requested a review from lk-geimfari December 13, 2019 22:14
@sinecode
Copy link
Contributor Author

@lk-geimfari please wait before publish a new version. There are some sections in the documentation that must be updated. I will do it as soon as this PR is merged in another branch.

@lk-geimfari
Copy link
Owner

lk-geimfari commented Dec 13, 2019

@ceccoemi Although I completely like your solution, I'm not quite sure that this idea was a good one, when now I see how much code of the same type we got because of the specifics of the issue.

If you do not mind I'll try to figure out how we can do it in a much simple and clear way. Can you, please, freeze your activity on this PR for now? You can work on another issue if you want.

@lk-geimfari
Copy link
Owner

@ceccoemi Sorry for this. I hope that you're not mad.

@sinecode
Copy link
Contributor Author

@lk-geimfari ok, no problem.

@sinecode
Copy link
Contributor Author

@lk-geimfari I agree that there is a lot of repetition.

Maybe the best thing to do is to implement just some methods in the Datetime provider. I'm thinking of future_date(), future_datetime() ...

@lk-geimfari
Copy link
Owner

@ceccoemi We need to check out how the faker implements similar features and implement this feature in a similar way.

Related: https://faker.readthedocs.io/en/master/providers/faker.providers.date_time.html

@stale
Copy link

stale bot commented Feb 2, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 2, 2020
@stale
Copy link

stale bot commented Feb 12, 2020

Closing this pull request automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one.

@stale stale bot closed this Feb 12, 2020
@lk-geimfari lk-geimfari reopened this Feb 12, 2020
@stale stale bot removed the stale label Feb 12, 2020
@stale
Copy link

stale bot commented Apr 2, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 2, 2020
@stale
Copy link

stale bot commented Apr 19, 2020

Closing this pull request automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one.

@stale stale bot closed this Apr 19, 2020
@lk-geimfari lk-geimfari deleted the future_past_datetime branch June 23, 2020 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add future and past providers to datetime
2 participants