eletrotupi / tcc/ api/src/lib/appTime.tsdafa6f8a8e3b0e51605fc953a979d50ff6085b26
440 B | 13 lines Raw
1
import { tz } from "@date-fns/tz";
2
import { set } from "date-fns";
3

4
export const APP_TIMEZONE = tz("America/Sao_Paulo");
5

6
// The instant, on the app-timezone day containing `reference`, at "HH:MM"
7
export function appTimeToday(time: string, reference: Date = new Date()): Date {
8
  const [hours, minutes] = time.split(":").map(Number);
9

10
  return set(reference, { hours, minutes, seconds: 0, milliseconds: 0 }, {
11
    in: APP_TIMEZONE,
12
  });
13
}