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

feat: add between function to Date module #951

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

Mounayer
Copy link
Contributor

@Mounayer Mounayer commented Oct 8, 2024

Description

Closes #937

Added two between functions to the Date module, like: https://fakerjs.dev/api/date.html#between

One function to support two ISO Dates:

std::string between(std::string from, std::string to, DateFormat dateFormat)

One function to support two Timestamps:

std::string between(int64_t from, int64_t to, DateFormat dateFormat)

Made sure to write tests that cover edge cases, and added docs.

Testing

Automated

Run tests, and make sure they pass

Manual

Build and use faker in some cpp file and try out the new functions yourself, i.e.:

faker::date::between("2021-01-01T00:00:00Z", "2022-01-01T00:00:00Z", DateFormat::ISO); // Returns a random date between Jan 1, 2021, and Jan 1, 2022, formatted as "2021-06-15T12:34:56Z"
faker::date::between("2021-01-01T00:00:00Z", "2022-01-01T00:00:00Z", DateFormat::Timestamp); // Returns the Unix timestamp of a random date between Jan 1, 2021, and Jan 1, 2022

and

faker::date::between(1609459200, 1640995200, DateFormat::ISO); // Returns a random date between Jan 1, 2021, and Jan 1, 2022, formatted as "2021-06-15T12:34:56Z" 
faker::date::between(1609459200, 1640995200, DateFormat::Timestamp); // Returns the Unix timestamp of a random date between Jan 1, 2021, and Jan 1, 2022

Copy link
Owner

@cieslarmichal cieslarmichal left a comment

Choose a reason for hiding this comment

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

Great job! 😁

@cieslarmichal cieslarmichal merged commit f8fa805 into cieslarmichal:main Oct 8, 2024
14 checks passed
@Mounayer
Copy link
Contributor Author

Mounayer commented Oct 8, 2024

Great job! 😁

Thank you! It's my first contribution to a large project, and I gotta say, the code was very readable!

@cieslarmichal
Copy link
Owner

Feel free to contribute more and join discord channel 😎💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add between function to Date module
2 participants