/**
 * @param input A date string
 * @returns a UNIX timestamp, or the original `input` if a UNIX timestamp could not be created from the `input`.
 */
export function toUnixTimestamp(input: string | unknown): number | unknown {
  if (typeof input !== 'string') {
    return input;
  }

  const jsTime = new Date(input).getTime();

  if (Number.isNaN(jsTime)) {
    // Input could not be converted to a UNIX timestamp.
    //
    // NOTE: we can expect `jsTime` to be `NaN` when provided
    // any invalid string `input` (e.g. 'not-a-date').
    return input;
  }

  return Math.floor(jsTime / 1000);
}
