All files / utils articleDateUtils.js

100% Statements 3/3
100% Branches 2/2
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16              15x         8x 8x    
// The backend stores an article's dateAdded as a ZonedDateTime. Depending on
// the server's time zone, the API returns it in UTC ("2026-10-29T10:30:00Z")
// or with an offset ("2026-10-29T03:30:00-07:00"). A datetime-local input
// can't show a zone, so forms convert the value to UTC, show that date and
// time, and add the "Z" back on submit.
 
export function toDateTimeLocal(dateAdded) {
  return new Date(dateAdded).toISOString().slice(0, 19);
}
 
export function toUtcIsoString(dateTimeLocal) {
  const withSeconds =
    dateTimeLocal.length === 16 ? dateTimeLocal + ":00" : dateTimeLocal;
  return withSeconds + "Z";
}