fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

compareDatePart returning incorrect amount of days/ unclear value representation

Open BrianDeJesus opened this issue 5 years ago • 2 comments

Environment Information

  • Package version(s): (8.1.6)

Function test:

import { compareDatePart } from '@fluentui/date-time-utilities';

const start = "2021-03-01T07:00:00Z";
test('get days difference 1', () => {
	
	const end =  "2021-04-30T07:00:00Z";

	const comparison1 = compareDatePart(new Date(end), new Date(start));
	expect(comparison1).toBe(60);

});

test('get days difference 2', () => {

	const end2 = "2021-05-01T07:00:00Z";

	const comparison2 = compareDatePart(new Date(end2), new Date(start));

	expect(comparison2).toBe(61);
});

The tests both fail even though they shouldn't, assuming the number returned is difference in days.

Actual behavior:

compareDatePart does not return the correct amount of days in the difference between the two dates. If the two dates are in a different month, the return value will be around 1 - 4 days off. I know the documentation does not say it returns the amount of days but I feel like many people will assume this.

Expected behavior:

compareDatePart would helpfully return the exact amount of days between two dates OR this documentation could be worded better to clarify what the number it returns does not represent or whether or not it's talking about such as the amount of groups of 24 hours between, weekdays, or months etc.

Priorities and help requested:

Are you willing to submit a PR to fix? (Yes, No) Yes

Requested priority: Normal n

Products/sites affected: (if applicable)

BrianDeJesus avatar Mar 18 '21 00:03 BrianDeJesus

@BrianDeJesus - thank you for submitting this issue and I see you are will do submit a PR - that is great news!

  • Could you share it with us? We would appreciate the contribution. Thanks in advance.

gouttierre avatar Apr 12 '21 12:04 gouttierre

This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fluent UI!

msft-fluent-ui-bot avatar Apr 16 '21 14:04 msft-fluent-ui-bot