diff --git a/packages/date/README.md b/packages/date/README.md index 2fc621c6fc4117..d5e0792395849d 100644 --- a/packages/date/README.md +++ b/packages/date/README.md @@ -117,7 +117,7 @@ _Parameters_ - _from_ `Moment | Date | string | undefined`: The timestamp to measure from. Defaults to the current time if undefined or invalid. - _to_ `Moment | Date | string | undefined`: The timestamp to measure to. Defaults to the current time if undefined or invalid. -- _includeAffix_ `boolean`: Whether to include the "ago" suffix in the comparison. +- _includeAffix_ `boolean`: Whether to include the "ago" or "to" affix in the comparison. _Returns_ diff --git a/packages/date/src/index.js b/packages/date/src/index.js index 3cf500c37cd80e..c0fe4705c5ff9c 100644 --- a/packages/date/src/index.js +++ b/packages/date/src/index.js @@ -565,10 +565,11 @@ export function getDate( dateString ) { * * @param {Moment | Date | string | undefined} from The timestamp to measure from. Defaults to the current time if undefined or invalid. * @param {Moment | Date | string | undefined} to The timestamp to measure to. Defaults to the current time if undefined or invalid. - * @param {boolean} includeAffix Whether to include the "ago" suffix in the comparison. + * @param {boolean} includeAffix Whether to include the "ago" or "to" affix in the comparison. * @return {string} The difference between the timestamps. */ export function humanTimeDiff( from, to, includeAffix ) { + // Normalize inputs to a moment object, defaults to current time. from = momentLib( from ); to = momentLib( to ); return from.from( to, ! includeAffix );