FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

24 lines
768 B

  1. import dayjs from "dayjs";
  2. import { arrayToDateString } from "@/app/utils/formatUtil";
  3. /** Normalize API targetDate (string or date array) to YYYY-MM-DD for search / URL. */
  4. export function normalizeTargetDateInput(value: unknown): string | null {
  5. if (value == null || value === "") {
  6. return null;
  7. }
  8. try {
  9. if (Array.isArray(value)) {
  10. const s = arrayToDateString(value, "input");
  11. return dayjs(s).isValid() ? dayjs(s).format("YYYY-MM-DD") : null;
  12. }
  13. const d = dayjs(String(value));
  14. return d.isValid() ? d.format("YYYY-MM-DD") : null;
  15. } catch {
  16. return null;
  17. }
  18. }
  19. export function resolveWorkbenchRecordTargetDate(initial?: string | null): string {
  20. return normalizeTargetDateInput(initial) ?? dayjs().format("YYYY-MM-DD");
  21. }