hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import type { Term } from "@/api/client"; |
| 2 | |
| 3 | /** |
| 4 | * The dönem a new record most likely belongs to: the open term whose date |
| 5 | * range contains `now`, else the nearest one still to come, else the first |
| 6 | * listed. Archived terms are only considered when every term is archived. |
| 7 | */ |
| 8 | export function pickCurrentTerm(terms: readonly Term[], now: number): Term | undefined { |
| 9 | const open = terms.filter((term) => term.archived_at == null); |
| 10 | const pool = open.length > 0 ? open : terms; |
| 11 | const current = pool.find((term) => term.starts_at <= now && now <= term.ends_at); |
| 12 | if (current) return current; |
| 13 | const upcoming = pool |
| 14 | .filter((term) => term.starts_at > now) |
| 15 | .sort((a, b) => a.starts_at - b.starts_at)[0]; |
| 16 | return upcoming ?? pool[0]; |
| 17 | } |