Download code/web/src/lib/ticks.ts from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/61db3dcff00709b0c7af75b417f98ea7d6f08366/code/web/src/lib/ticks.ts
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@61db3dcff00709b0c7af75b417f98ea7d6f08366/code/web/src/lib/ticks.ts
-
curl -L -o ticks.ts https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/61db3dcff00709b0c7af75b417f98ea7d6f08366/code/web/src/lib/ticks.ts
857 Bytes
| import { DAY, isoDay, md, my } from "@/lib/format" | |
| /** Month ticks between two times, every one to three months by span (January shows the year); | |
| * weekly ticks when the span is under two months. */ | |
| export function timeTicks(a: number, b: number) { | |
| const span = (b - a) / DAY | |
| const every = span > 400 ? 3 : span > 150 ? 2 : 1 | |
| const out: number[] = [] | |
| const d = new Date(a) | |
| d.setUTCDate(1) | |
| d.setUTCMonth(d.getUTCMonth() + 1) | |
| for (; d.getTime() <= b; d.setUTCMonth(d.getUTCMonth() + 1)) if (d.getUTCMonth() % every === 0) out.push(d.getTime()) | |
| if (out.length >= 2) | |
| return { ticks: out, label: (t: number) => (isoDay(t).slice(5, 7) === "01" ? isoDay(t).slice(0, 4) : my(isoDay(t)).split(" ")[0]) } | |
| const wk: number[] = [] | |
| for (let t = a; t <= b; t += 7 * DAY) wk.push(t) | |
| return { ticks: wk, label: (t: number) => md(isoDay(t)) } | |
| } | |