function difference(from, to, options) {
  const uniqueUnits = options?.units
    ? [
      ...new Set(options?.units),
    ]
    : [
      "miliseconds",
      "seconds",
      "minutes",
      "hours",
      "days",
      "weeks",
      "months",
      "quarters",
      "years",
    ];
  const bigger = Math.max(from.getTime(), to.getTime());
  const smaller = Math.min(from.getTime(), to.getTime());
  const differenceInMs = bigger - smaller;
  const differences = {};
  for (const uniqueUnit of uniqueUnits) {
    switch (uniqueUnit) {
      case "miliseconds":
        differences.miliseconds = differenceInMs;
        break;
      case "seconds":
        differences.seconds = Math.floor(differenceInMs / SECOND);
        break;
      case "minutes":
        differences.minutes = Math.floor(differenceInMs / MINUTE);
        break;
      case "hours":
        differences.hours = Math.floor(differenceInMs / HOUR);
        break;
      case "days":
        differences.days = Math.floor(differenceInMs / DAY);
        break;
      case "weeks":
        differences.weeks = Math.floor(differenceInMs / WEEK);
        break;
      case "months":
        differences.months = calculateMonthsDifference(bigger, smaller);
        break;
      case "quarters":
        differences.quarters = Math.floor(
          typeof differences.months !== "undefined" && differences.months / 4 ||
            calculateMonthsDifference(bigger, smaller) / 4,
        );
        break;
      case "years":
        differences.years = Math.floor(
          typeof differences.months !== "undefined" &&
              differences.months / 12 ||
            calculateMonthsDifference(bigger, smaller) / 12,
        );
        break;
    }
  }
  return differences;
}
/**
 * Calculate difference between two dates.
 * @param from Year to calculate difference
 * @param to Year to calculate difference with
 * @param options Options for determining how to respond
 *
 * example :
 *
 * ```typescript
 * datetime.difference(new Date("2020/1/1"),new Date("2020/2/2"),{ units : ["days","months"] })
 * ```
 */
Calculate difference between two dates.
@param from Year to calculate difference
@param to Year to calculate difference with
@param options Options for determining how to respond

example .


Calculate difference between two dates . @param from Year to calculate difference @param to Year to calculate difference with @param options Options for determining how to respond example .
function difference(from, to, options) {
  const uniqueUnits = options?.units
    ? [
      ...new Set(options?.units),
    ]
    : [
      "miliseconds",
      "seconds",
      "minutes",
      "hours",
      "days",
      "weeks",
      "months",
      "quarters",
      "years",
    ];
  const bigger = Math.max(from.getTime(), to.getTime());
  const smaller = Math.min(from.getTime(), to.getTime());
  const differenceInMs = bigger - smaller;
  const differences = {};
  for (const uniqueUnit of uniqueUnits) {
    switch (uniqueUnit) {
      case "miliseconds":
        differences.miliseconds = differenceInMs;
        break;
      case "seconds":
        differences.seconds = Math.floor(differenceInMs / SECOND);
        break;
      case "minutes":
        differences.minutes = Math.floor(differenceInMs / MINUTE);
        break;
      case "hours":
        differences.hours = Math.floor(differenceInMs / HOUR);
        break;
      case "days":
        differences.days = Math.floor(differenceInMs / DAY);
        break;
      case "weeks":
        differences.weeks = Math.floor(differenceInMs / WEEK);
        break;
      case "months":
        differences.months = calculateMonthsDifference(bigger, smaller);
        break;
      case "quarters":
        differences.quarters = Math.floor(
          typeof differences.months !== "undefined" && differences.months / 4 ||
            calculateMonthsDifference(bigger, smaller) / 4,
        );
        break;
      case "years":
        differences.years = Math.floor(
          typeof differences.months !== "undefined" &&
              differences.months / 12 ||
            calculateMonthsDifference(bigger, smaller) / 12,
        );
        break;
    }
  }
  return differences;
}
function difference ( from , to , options ) { const uniqueUnits = options ?. units ? [ ... new Set ( options ?. units ) , ] : [ "miliseconds" , "seconds" , "minutes" , "hours" , "days" , "weeks" , "months" , "quarters" , "years" , ] ; const bigger = Math . max ( from . getTime ( ) , to . getTime ( ) ) ; const smaller = Math . min ( from . getTime ( ) , to . getTime ( ) ) ; const differenceInMs = bigger - smaller ; const differences = { } ; for ( const uniqueUnit of uniqueUnits ) { switch ( uniqueUnit ) { case "miliseconds" : differences . miliseconds = differenceInMs ; break ; case "seconds" : differences . seconds = Math . floor ( differenceInMs / SECOND ) ; break ; case "minutes" : differences . minutes = Math . floor ( differenceInMs / MINUTE ) ; break ; case "hours" : differences . hours = Math . floor ( differenceInMs / HOUR ) ; break ; case "days" : differences . days = Math . floor ( differenceInMs / DAY ) ; break ; case "weeks" : differences . weeks = Math . floor ( differenceInMs / WEEK ) ; break ; case "months" : differences . months = calculateMonthsDifference ( bigger , smaller ) ; break ; case "quarters" : differences . quarters = Math . floor ( typeof differences . months !== "undefined" && differences . months / 4 || calculateMonthsDifference ( bigger , smaller ) / 4 , ) ; break ; case "years" : differences . years = Math . floor ( typeof differences . months !== "undefined" && differences . months / 12 || calculateMonthsDifference ( bigger , smaller ) / 12 , ) ; break ; } } return differences ; }
Calculate difference between two dates.
Calculate difference between two dates .