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

Add future and past providers to datetime #775

Open
sobolevn opened this issue Dec 6, 2019 · 16 comments
Open

Add future and past providers to datetime #775

sobolevn opened this issue Dec 6, 2019 · 16 comments
Assignees
Labels
enhancement Enhancement proposals feature Feature request help wanted Nee help

Comments

@sobolevn
Copy link
Collaborator

sobolevn commented Dec 6, 2019

I would love to see the same feature from Datetime ported to both FutureDatetime and PastDatetime providers.

I hope that you will get the idea from the class names 🙂

@sobolevn sobolevn added enhancement Enhancement proposals help wanted Nee help feature Feature request labels Dec 6, 2019
@sobolevn
Copy link
Collaborator Author

sobolevn commented Dec 6, 2019

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

@lk-geimfari
Copy link
Owner

@ceccoemi Any chance you can work on it? I'm about to publish a new version and this feature will be a great addition in the changelog.

@sinecode
Copy link
Contributor

@lk-geimfari yes, I should be able to work on it. Give me 2/3 days

@lk-geimfari
Copy link
Owner

@ceccoemi Great! Thank you very much! Feel free to ask your questions about the feature to @sobolevn.

@sinecode
Copy link
Contributor

@sobolevn @lk-geimfari a couple of questions.

What do you think about adding the FutureDatetime and PastDatetime providers as subclass of the Datetime provider? In that case, is it ok if I include them in the same module date.py?

My idea is to override the methods that accepts the argument start and to set it to a moment in the future/past.

@sobolevn
Copy link
Collaborator Author

Sounds like a plan!

@stale
Copy link

stale bot commented Jan 30, 2020

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

@stale stale bot added the stale label Jan 30, 2020
@sobolevn sobolevn reopened this Dec 4, 2024
@stale stale bot removed the stale label Dec 4, 2024
@sobolevn
Copy link
Collaborator Author

sobolevn commented Dec 4, 2024

This was never implemented. I needed this today once again.

@lk-geimfari
Copy link
Owner

Wait, don't we have the ability to generate such dates?

@lk-geimfari
Copy link
Owner

Almost every Datetime method accepts ranges of years as I can see.

@lk-geimfari lk-geimfari assigned lk-geimfari and unassigned sinecode Dec 4, 2024
@sobolevn
Copy link
Collaborator Author

sobolevn commented Dec 4, 2024

not in an easy way, judging from the docs here: https://mimesis.name/master/api.html#datetime

Faker has future_datetime() and past_datetime that have the semantics that I want.
But, mimesis has no such feature. I have to manually add years in the past to get such days. Moreover, year sometimes is not enough. I want the datetime in the past this year. Or this month. Or this week, etc.

There are lots of business rules based on time. These things are 100% required. See how many of them exist here: https://faker.readthedocs.io/en/stable/providers/faker.providers.date_time.html

@lk-geimfari
Copy link
Owner

lk-geimfari commented Dec 5, 2024

not in an easy way, judging from the docs here: https://mimesis.name/master/api.html#datetime

Faker has future_datetime() and past_datetime that have the semantics that I want. But, mimesis has no such feature. I have to manually add years in the past to get such days. Moreover, year sometimes is not enough. I want the datetime in the past this year. Or this month. Or this week, etc.

There are lots of business rules based on time. These things are 100% required. See how many of them exist here: https://faker.readthedocs.io/en/stable/providers/faker.providers.date_time.html

Can't we just add an extra argument and implement something like this:

dt = Datetime(moment='PAST')
dt = Datetime(moment='FUTURE')

@sobolevn
Copy link
Collaborator Author

sobolevn commented Dec 5, 2024

Yes, this looks good to me. I would suggest to add more, like: PAST_YEAR, PAST_MONTH, PAST_WEEK, PAST_DAY. And the same for FUTURE

@lk-geimfari
Copy link
Owner

lk-geimfari commented Dec 6, 2024

@sobolevn Hey! I'm planning on providing something similar:

class Timeframe:
    PAST_YEAR = 'PAST_YEAR'
    PAST_MONTH = 'PAST_MONTH'
    PAST_WEEK = 'PAST_WEEK'
    PAST_DAY = 'PAST_DAY'
    FUTURE_YEAR = 'FUTURE_YEAR'
    FUTURE_MONTH = 'FUTURE_MONTH'
    FUTURE_WEEK = 'FUTURE_WEEK'
    FUTURE_DAY = 'FUTURE_DAY'
    ANY = 'ANY'
    

# Note: There are only 9 method of "Datetime" to which this feature is applicable:
dt = Datetime(timeframe=Timeframe.PAST_YEAR)
dt.bulk_create_datetimes()
dt.week_date()
dt.year()
dt.date()
dt.formatted_date()
dt.time()
dt.datetime()
dt.formatted_datetime()
dt.timestamp()

Depending on the Timeframe passed in, it will always generate dates for the given time. The default will be Timeframe.ANY.

I can implement this on the weekend if it suits your needs.

However, this can break backward compatibility.

@sobolevn
Copy link
Collaborator Author

sobolevn commented Dec 6, 2024

I also propose to add: FUTURE_THIS_DAY and PAST_THIS_DAY.
Other than that - looks good to me!

@lk-geimfari
Copy link
Owner

Turns out it's not as easy as I thought it would be. Nevertheless, I still plan to implement this feature, but couldn't give an accurate estimate as I'm very busy with work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement proposals feature Feature request help wanted Nee help
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants