hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import type { Exam, Homework, MealSlot, SchoolSettings } from "@/api/client"; |
| 2 | import type { PatchSettingsBody } from "@/api/settings"; |
| 3 | |
| 4 | export function formatTry(minor: number, locale: string): string { |
| 5 | return new Intl.NumberFormat(locale, { style: "currency", currency: "TRY" }).format(minor / 100); |
| 6 | } |
| 7 | |
| 8 | export function minuteToUtcTime(minute: number | null): string { |
| 9 | if (minute == null) return ""; |
| 10 | return `${String(Math.floor(minute / 60)).padStart(2, "0")}:${String(minute % 60).padStart(2, "0")}`; |
| 11 | } |
| 12 | |
| 13 | export function utcTimeToMinute(value: string): number | null { |
| 14 | const match = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(value); |
| 15 | return match ? Number(match[1]) * 60 + Number(match[2]) : null; |
| 16 | } |
| 17 | |
| 18 | export function mealCutoffAt(date: string, slot: MealSlot | undefined, minutes: number | null): number | null { |
| 19 | if (minutes == null) return null; |
| 20 | const servingMinute = slot?.serving_minute ?? 0; |
| 21 | return Date.parse(`${date}T00:00:00Z`) + servingMinute * 60_000 - minutes * 60_000; |
| 22 | } |
| 23 | |
| 24 | export function nextCourseWork(instanceId: string, exams: Exam[], homework: Homework[]) { |
| 25 | return [ |
| 26 | ...exams.filter((item) => item.class_course === instanceId).map((item) => ({ kind: "exam" as const, title: item.title, at: item.starts_at ?? item.ends_at })), |
| 27 | ...homework.filter((item) => item.class_course === instanceId).map((item) => ({ kind: "homework" as const, title: item.title, at: item.due_at })), |
| 28 | ] |
| 29 | .filter((item): item is { kind: "exam" | "homework"; title: string; at: number } => item.at != null) |
| 30 | .sort((a, b) => a.at - b.at)[0] ?? null; |
| 31 | } |
| 32 | |
| 33 | export function dirtySettingsPatch(before: SchoolSettings, after: SchoolSettings): PatchSettingsBody { |
| 34 | const patch: PatchSettingsBody = {}; |
| 35 | for (const key of [ |
| 36 | "exam_kinds", |
| 37 | "attendance_statuses", |
| 38 | "grade_bands", |
| 39 | "max_file_bytes", |
| 40 | "chatbot_history_turns", |
| 41 | "max_chatbot_threads", |
| 42 | "max_chatbot_message_len", |
| 43 | "meal_slots", |
| 44 | "dietary_tags", |
| 45 | "meal_cancel_cutoff_minutes", |
| 46 | "excuse_kinds", |
| 47 | "branches", |
| 48 | "max_excused_absent_days", |
| 49 | "max_unexcused_absent_days", |
| 50 | "timezone", |
| 51 | ] as const) { |
| 52 | if (JSON.stringify(before[key]) !== JSON.stringify(after[key])) patch[key] = after[key] as never; |
| 53 | } |
| 54 | return patch; |
| 55 | } |