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

Ability to ignore time when wanting to check diff between two dates #155

Open
MarkOSullivan94 opened this issue Apr 8, 2022 · 0 comments

Comments

@MarkOSullivan94
Copy link

MarkOSullivan94 commented Apr 8, 2022

Is your feature request related to a problem? Please describe.
In the current project I'm working on, we have logs which are submitted every day at different times, we don't care at all what time they are submitted, as long as they are submitted every day.

When using the diff method, it was returning a value which was unexpected.

final firstDateTime = DateTime(2022, 4, 1, 11, 20, 46);
final secondDateTime = DateTime(2022, 3, 30, 17, 56, 54);

final start = Jiffy(firstDateTime);
final end = Jiffy(secondDateTime);
final diff = start.diff(end, Units.DAY);

print('First: $first');
print('Second: $second');
print('Diff: $diff');

Result

First: 2022-04-01 11:20:46.000
Second: 2022-03-30 17:56:54.000
Diff: 1

Describe the solution you'd like

It'd be great if we could have another method which would give the option to ignore the time when considering the difference of two dates.

Describe alternatives you've considered

For now, I've created two new instances of DateTime ignoring the time fields from the real values and passed into Jiffy's constructor and this returns the expected value of 2 days difference.

final firstDateTime = DateTime(2022, 4, 1, 11, 20, 46);
final secondDateTime = DateTime(2022, 3, 30, 17, 56, 54);
final firstFormatted = DateTime(firstDateTime.year, firstDateTime.month, firstDateTime.day);
final secondFormatted = DateTime(secondDateTime.year, secondDateTime.month, secondDateTime.day);
final start = Jiffy(firstFormatted);
final end = Jiffy(secondFormatted);
final diff = start.diff(end, Units.DAY);

print('Diff: $diff');

Result

Diff: 2

Additional context

jiffy: 5.0.0

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

No branches or pull requests

1 participant