/**
 * The Knex connection runs with `timezone: 'Z'` + `dateStrings: true`, so the
 * DB session clock is UTC and DATETIME values come back as plain strings.
 *
 * Passing a JS `Date` straight into an insert/update lets mysql2 apply its own
 * timezone conversion and land the value hours off (a 60-minute reset token then
 * reads as already expired). Always store a UTC wall-clock string instead.
 */
export function toSqlUtc(date: Date): string {
  return date.toISOString().slice(0, 19).replace('T', ' ');
}

/** Parse a DB DATETEXT string (UTC session) back to a Date. */
export function fromSqlUtc(value: string): Date {
  return new Date(`${value.replace(' ', 'T')}Z`);
}
