@ccusage/amp 18.0.2 → 18.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +67 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ var __require$1 = /* @__PURE__ */ createRequire(import.meta.url);
48
48
  /**
49
49
  * The default locale string, which format is BCP 47 language tag.
50
50
  */
51
- const DEFAULT_LOCALE = "en-US";
51
+ const DEFAULT_LOCALE$1 = "en-US";
52
52
  const BUILT_IN_PREFIX = "_";
53
53
  const ARG_PREFIX = "arg";
54
54
  const BUILT_IN_KEY_SEPARATOR = ":";
@@ -211,15 +211,15 @@ async function createCommandContext({ args, values, positionals, rest, argv: arg
211
211
  const localeStr = locale.toString();
212
212
  const adapter = (cliOptions.translationAdapterFactory || createTranslationAdapter)({
213
213
  locale: localeStr,
214
- fallbackLocale: DEFAULT_LOCALE
214
+ fallbackLocale: DEFAULT_LOCALE$1
215
215
  });
216
216
  const localeResources = /* @__PURE__ */ new Map();
217
217
  let builtInLoadedResources;
218
218
  /**
219
219
  * load the built-in locale resources
220
220
  */
221
- localeResources.set(DEFAULT_LOCALE, mapResourceWithBuiltinKey(en_US_default));
222
- if (DEFAULT_LOCALE !== localeStr) try {
221
+ localeResources.set(DEFAULT_LOCALE$1, mapResourceWithBuiltinKey(en_US_default));
222
+ if (DEFAULT_LOCALE$1 !== localeStr) try {
223
223
  builtInLoadedResources = (await import(`./locales/${localeStr}.json`, { with: { type: "json" } })).default;
224
224
  localeResources.set(localeStr, mapResourceWithBuiltinKey(builtInLoadedResources));
225
225
  } catch {}
@@ -229,7 +229,7 @@ async function createCommandContext({ args, values, positionals, rest, argv: arg
229
229
  */
230
230
  function translate(key, values$1 = create()) {
231
231
  const strKey = key;
232
- if (strKey.codePointAt(0) === BUILT_IN_PREFIX_CODE) return (localeResources.get(localeStr) || localeResources.get(DEFAULT_LOCALE))[strKey] || strKey;
232
+ if (strKey.codePointAt(0) === BUILT_IN_PREFIX_CODE) return (localeResources.get(localeStr) || localeResources.get(DEFAULT_LOCALE$1))[strKey] || strKey;
233
233
  else return adapter.translate(locale.toString(), strKey, values$1) || "";
234
234
  }
235
235
  /**
@@ -270,7 +270,7 @@ async function createCommandContext({ args, values, positionals, rest, argv: arg
270
270
  }, create());
271
271
  defaultCommandResource.description = command.description || "";
272
272
  defaultCommandResource.examples = await resolveExamples(ctx, command.examples);
273
- adapter.setResource(DEFAULT_LOCALE, defaultCommandResource);
273
+ adapter.setResource(DEFAULT_LOCALE$1, defaultCommandResource);
274
274
  const originalResource = await loadCommandResource(ctx, command);
275
275
  if (originalResource) {
276
276
  const resource = Object.assign(create(), originalResource, { examples: await resolveExamples(ctx, originalResource.examples) });
@@ -288,7 +288,7 @@ function getCommandName(cmd) {
288
288
  else return ANONYMOUS_COMMAND_NAME;
289
289
  }
290
290
  function resolveLocale(locale) {
291
- return locale instanceof Intl.Locale ? locale : typeof locale === "string" ? new Intl.Locale(locale) : new Intl.Locale(DEFAULT_LOCALE);
291
+ return locale instanceof Intl.Locale ? locale : typeof locale === "string" ? new Intl.Locale(locale) : new Intl.Locale(DEFAULT_LOCALE$1);
292
292
  }
293
293
  async function loadCommandResource(ctx, command) {
294
294
  let resource;
@@ -1143,7 +1143,7 @@ async function executeCommand(cmd, ctx, name$1) {
1143
1143
  //#endregion
1144
1144
  //#region package.json
1145
1145
  var name = "@ccusage/amp";
1146
- var version = "18.0.2";
1146
+ var version = "18.0.4";
1147
1147
  var description = "Usage analysis tool for Amp CLI sessions";
1148
1148
 
1149
1149
  //#endregion
@@ -2958,6 +2958,37 @@ function stringWidth$2(string$1, options = {}) {
2958
2958
  //#endregion
2959
2959
  //#region ../../packages/terminal/src/table.ts
2960
2960
  /**
2961
+ * Default locale used for date formatting when not specified
2962
+ * en-CA provides YYYY-MM-DD ISO format
2963
+ */
2964
+ const DEFAULT_LOCALE = "en-CA";
2965
+ /**
2966
+ * Creates a date parts formatter with the specified timezone and locale
2967
+ * @param timezone - Timezone to use
2968
+ * @param locale - Locale to use for formatting
2969
+ * @returns Intl.DateTimeFormat instance
2970
+ */
2971
+ function createDatePartsFormatter(timezone, locale) {
2972
+ return new Intl.DateTimeFormat(locale, {
2973
+ year: "numeric",
2974
+ month: "2-digit",
2975
+ day: "2-digit",
2976
+ timeZone: timezone
2977
+ });
2978
+ }
2979
+ /**
2980
+ * Formats a date string to compact format with year on first line and month-day on second
2981
+ * @param dateStr - Input date string (YYYY-MM-DD or ISO timestamp)
2982
+ * @param timezone - Timezone to use for formatting (pass undefined to use system timezone)
2983
+ * @param locale - Locale to use for formatting (defaults to sv-SE for YYYY-MM-DD format)
2984
+ * @returns Formatted date string with newline separator (YYYY\nMM-DD)
2985
+ */
2986
+ function formatDateCompact(dateStr, timezone, locale) {
2987
+ const date = /^\d{4}-\d{2}-\d{2}$/.test(dateStr) ? timezone != null ? /* @__PURE__ */ new Date(`${dateStr}T00:00:00Z`) : /* @__PURE__ */ new Date(`${dateStr}T00:00:00`) : new Date(dateStr);
2988
+ const parts = createDatePartsFormatter(timezone, locale ?? DEFAULT_LOCALE).formatToParts(date);
2989
+ return `${parts.find((p$1) => p$1.type === "year")?.value ?? ""}\n${parts.find((p$1) => p$1.type === "month")?.value ?? ""}-${parts.find((p$1) => p$1.type === "day")?.value ?? ""}`;
2990
+ }
2991
+ /**
2961
2992
  * Responsive table class that adapts column widths based on terminal size
2962
2993
  * Automatically adjusts formatting and layout for different screen sizes
2963
2994
  */
@@ -3716,6 +3747,28 @@ if (import.meta.vitest != null) {
3716
3747
  expect(formatModelsDisplayMultiline(["[pi] anthropic/claude-opus-4.5"])).toBe("- [pi] opus-4.5");
3717
3748
  });
3718
3749
  });
3750
+ describe("formatDateCompact", () => {
3751
+ it("should format date to compact format with newline", () => {
3752
+ const result = formatDateCompact("2024-08-04", void 0, "en-US");
3753
+ expect(result).toBe("2024\n08-04");
3754
+ });
3755
+ it("should handle timezone parameter", () => {
3756
+ const result = formatDateCompact("2024-08-04T12:00:00Z", "UTC", "en-US");
3757
+ expect(result).toBe("2024\n08-04");
3758
+ });
3759
+ it("should handle YYYY-MM-DD format dates", () => {
3760
+ const result = formatDateCompact("2024-08-04", void 0, "en-US");
3761
+ expect(result).toBe("2024\n08-04");
3762
+ });
3763
+ it("should handle timezone with YYYY-MM-DD format", () => {
3764
+ const result = formatDateCompact("2024-08-04", "UTC", "en-US");
3765
+ expect(result).toBe("2024\n08-04");
3766
+ });
3767
+ it("should use default locale when not specified", () => {
3768
+ const result = formatDateCompact("2024-08-04");
3769
+ expect(result).toBe("2024\n08-04");
3770
+ });
3771
+ });
3719
3772
  }
3720
3773
 
3721
3774
  //#endregion
@@ -8723,7 +8776,8 @@ const dailyCommand = define({
8723
8776
  ],
8724
8777
  compactThreshold: 100,
8725
8778
  forceCompact: Boolean(ctx.values.compact),
8726
- style: { head: ["cyan"] }
8779
+ style: { head: ["cyan"] },
8780
+ dateFormatter: (dateStr) => formatDateCompact(dateStr)
8727
8781
  });
8728
8782
  for (const data of dailyData) table.push([
8729
8783
  data.date,
@@ -8900,7 +8954,8 @@ const monthlyCommand = define({
8900
8954
  ],
8901
8955
  compactThreshold: 100,
8902
8956
  forceCompact: Boolean(ctx.values.compact),
8903
- style: { head: ["cyan"] }
8957
+ style: { head: ["cyan"] },
8958
+ dateFormatter: (dateStr) => formatDateCompact(dateStr)
8904
8959
  });
8905
8960
  for (const data of monthlyData) table.push([
8906
8961
  data.month,
@@ -9081,7 +9136,8 @@ const sessionCommand = define({
9081
9136
  ],
9082
9137
  compactThreshold: 100,
9083
9138
  forceCompact: Boolean(ctx.values.compact),
9084
- style: { head: ["cyan"] }
9139
+ style: { head: ["cyan"] },
9140
+ dateFormatter: (dateStr) => formatDateCompact(dateStr)
9085
9141
  });
9086
9142
  for (const data of sessionData) {
9087
9143
  const displayTitle = data.title.length > 30 ? `${data.title.slice(0, 27)}...` : data.title;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ccusage/amp",
3
3
  "type": "module",
4
- "version": "18.0.2",
4
+ "version": "18.0.4",
5
5
  "description": "Usage analysis tool for Amp CLI sessions",
6
6
  "author": "ryoppippi",
7
7
  "license": "MIT",