Open History to see the last commit
1import type { UsageSource } from "@t3tools/contracts";
2import { mFallback, msg, plural, part } from "gt-i18n";
3import type { M } from "gt-i18n";
4
5import {
6 formatRelativeHourShort as formatRelativeHourShortWith,
7 usageSourceMessages as usageSourceMessagesWith,
8} from "./usageFormat.ts";
9import type { UsageContractMismatch } from "./usageMerge.ts";
10
11/** @public */
12export function usageSourceMessages(
13 sources: readonly UsageSource[],
14 resolve: M = mFallback,
15): readonly string[] {
16 return usageSourceMessagesWith(sources, (count) =>
17 resolve(
18 msg`${plural(
19 { count },
20 {
21 one: part`${{ count }} malformed or inconsistent usage record was skipped; usage may be incomplete.`,
22 other: part`${{ count }} malformed or inconsistent usage records were skipped; usage may be incomplete.`,
23 },
24 )}`,
25 ),
26 );
27}
28
29/** @public */
30export function formatUsageContractMismatch(
31 environmentLabel: string,
32 mismatch: Pick<UsageContractMismatch, "direction">,
33 resolve: M = mFallback,
34): string {
35 return mismatch.direction === "serverBehind"
36 ? resolve(
37 msg`${{ environment: environmentLabel }} runs an older server version and is excluded from totals.`,
38 )
39 : resolve(
40 msg`This client is older than the server on ${{ environment: environmentLabel }}; its usage is excluded from totals.`,
41 );
42}
43
44/** @public */
45export function formatRelativeHourShort(
46 hourStart: string,
47 relativeTo: string,
48 timeZone?: string,
49 hour12 = true,
50 resolve: M = mFallback,
51 locale?: string,
52): string {
53 return formatRelativeHourShortWith(
54 hourStart,
55 relativeTo,
56 timeZone,
57 hour12,
58 (hour, daysAgo) =>
59 daysAgo === 0 ? resolve(msg`${{ hour }} today`) : resolve(msg`${{ hour }} yesterday`),
60 locale,
61 );
62}