@igstack/app-catalog-frontend-core 2.0.0-alpha-20260914211846 → 2.0.0-alpha-20260914220838

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.
@@ -11,7 +11,7 @@ function formatRelativeTime(iso, now = Date.now()) {
11
11
  const then = Date.parse(iso);
12
12
  if (Number.isNaN(then)) return "";
13
13
  const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
14
- let duration = (then - now) / 1e3;
14
+ let duration = Math.min(0, (then - now) / 1e3);
15
15
  for (const division of DIVISIONS) {
16
16
  if (Math.abs(duration) < division.amount) {
17
17
  return rtf.format(Math.round(duration), division.unit);
@@ -1 +1 @@
1
- {"version":3,"file":"formatRelativeTime.js","sources":["../../../../../src/modules/appCatalog/utils/formatRelativeTime.ts"],"sourcesContent":["/**\n * Format an ISO timestamp as a short, human relative phrase (\"2 days ago\").\n * Used for the muted \"Last checked …\" line on the app detail view.\n *\n * Kept tiny and dependency-free (Intl.RelativeTimeFormat) — the frontend has no\n * date library and this is the only place that needs relative time.\n */\nconst DIVISIONS: { amount: number; unit: Intl.RelativeTimeFormatUnit }[] = [\n { amount: 60, unit: 'second' },\n { amount: 60, unit: 'minute' },\n { amount: 24, unit: 'hour' },\n { amount: 7, unit: 'day' },\n { amount: 4.34524, unit: 'week' },\n { amount: 12, unit: 'month' },\n { amount: Number.POSITIVE_INFINITY, unit: 'year' },\n]\n\nexport function formatRelativeTime(\n iso: string,\n now: number = Date.now(),\n): string {\n const then = Date.parse(iso)\n if (Number.isNaN(then)) return ''\n const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })\n let duration = (then - now) / 1000 // seconds, negative for the past\n for (const division of DIVISIONS) {\n if (Math.abs(duration) < division.amount) {\n return rtf.format(Math.round(duration), division.unit)\n }\n duration /= division.amount\n }\n return rtf.format(Math.round(duration), 'year')\n}\n"],"names":[],"mappings":"AAOA,MAAM,YAAqE;AAAA,EACzE,EAAE,QAAQ,IAAI,MAAM,SAAA;AAAA,EACpB,EAAE,QAAQ,IAAI,MAAM,SAAA;AAAA,EACpB,EAAE,QAAQ,IAAI,MAAM,OAAA;AAAA,EACpB,EAAE,QAAQ,GAAG,MAAM,MAAA;AAAA,EACnB,EAAE,QAAQ,SAAS,MAAM,OAAA;AAAA,EACzB,EAAE,QAAQ,IAAI,MAAM,QAAA;AAAA,EACpB,EAAE,QAAQ,OAAO,mBAAmB,MAAM,OAAA;AAC5C;AAEO,SAAS,mBACd,KACA,MAAc,KAAK,OACX;AACR,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,OAAO,MAAM,IAAI,EAAG,QAAO;AAC/B,QAAM,MAAM,IAAI,KAAK,mBAAmB,MAAM,EAAE,SAAS,QAAQ;AACjE,MAAI,YAAY,OAAO,OAAO;AAC9B,aAAW,YAAY,WAAW;AAChC,QAAI,KAAK,IAAI,QAAQ,IAAI,SAAS,QAAQ;AACxC,aAAO,IAAI,OAAO,KAAK,MAAM,QAAQ,GAAG,SAAS,IAAI;AAAA,IACvD;AACA,gBAAY,SAAS;AAAA,EACvB;AACA,SAAO,IAAI,OAAO,KAAK,MAAM,QAAQ,GAAG,MAAM;AAChD;"}
1
+ {"version":3,"file":"formatRelativeTime.js","sources":["../../../../../src/modules/appCatalog/utils/formatRelativeTime.ts"],"sourcesContent":["/**\n * Format an ISO timestamp as a short, human relative phrase (\"2 days ago\").\n * Used for the muted \"Last checked …\" line on the app detail view.\n *\n * Kept tiny and dependency-free (Intl.RelativeTimeFormat) — the frontend has no\n * date library and this is the only place that needs relative time.\n */\nconst DIVISIONS: { amount: number; unit: Intl.RelativeTimeFormatUnit }[] = [\n { amount: 60, unit: 'second' },\n { amount: 60, unit: 'minute' },\n { amount: 24, unit: 'hour' },\n { amount: 7, unit: 'day' },\n { amount: 4.34524, unit: 'week' },\n { amount: 12, unit: 'month' },\n { amount: Number.POSITIVE_INFINITY, unit: 'year' },\n]\n\nexport function formatRelativeTime(\n iso: string,\n now: number = Date.now(),\n): string {\n const then = Date.parse(iso)\n if (Number.isNaN(then)) return ''\n const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })\n // Every timestamp we render already happened, so clamp the future away: a\n // server clock a few seconds ahead of the browser otherwise turns a comment\n // posted a moment ago into \"in 4 seconds\".\n let duration = Math.min(0, (then - now) / 1000) // seconds, negative for the past\n for (const division of DIVISIONS) {\n if (Math.abs(duration) < division.amount) {\n return rtf.format(Math.round(duration), division.unit)\n }\n duration /= division.amount\n }\n return rtf.format(Math.round(duration), 'year')\n}\n"],"names":[],"mappings":"AAOA,MAAM,YAAqE;AAAA,EACzE,EAAE,QAAQ,IAAI,MAAM,SAAA;AAAA,EACpB,EAAE,QAAQ,IAAI,MAAM,SAAA;AAAA,EACpB,EAAE,QAAQ,IAAI,MAAM,OAAA;AAAA,EACpB,EAAE,QAAQ,GAAG,MAAM,MAAA;AAAA,EACnB,EAAE,QAAQ,SAAS,MAAM,OAAA;AAAA,EACzB,EAAE,QAAQ,IAAI,MAAM,QAAA;AAAA,EACpB,EAAE,QAAQ,OAAO,mBAAmB,MAAM,OAAA;AAC5C;AAEO,SAAS,mBACd,KACA,MAAc,KAAK,OACX;AACR,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,OAAO,MAAM,IAAI,EAAG,QAAO;AAC/B,QAAM,MAAM,IAAI,KAAK,mBAAmB,MAAM,EAAE,SAAS,QAAQ;AAIjE,MAAI,WAAW,KAAK,IAAI,IAAI,OAAO,OAAO,GAAI;AAC9C,aAAW,YAAY,WAAW;AAChC,QAAI,KAAK,IAAI,QAAQ,IAAI,SAAS,QAAQ;AACxC,aAAO,IAAI,OAAO,KAAK,MAAM,QAAQ,GAAG,SAAS,IAAI;AAAA,IACvD;AACA,gBAAY,SAAS;AAAA,EACvB;AACA,SAAO,IAAI,OAAO,KAAK,MAAM,QAAQ,GAAG,MAAM;AAChD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igstack/app-catalog-frontend-core",
3
- "version": "2.0.0-alpha-20260914211846",
3
+ "version": "2.0.0-alpha-20260914220838",
4
4
  "description": "Frontend core library for App Catalog",
5
5
  "homepage": "https://github.com/lislon/app-catalog",
6
6
  "repository": {
@@ -113,7 +113,7 @@
113
113
  "tailwindcss": "^4.1.7",
114
114
  "tiptap-markdown": "^0.8.0",
115
115
  "tslib": "^2.3.0",
116
- "@igstack/app-catalog-shared-core": "2.0.0-alpha-20260914211846"
116
+ "@igstack/app-catalog-shared-core": "2.0.0-alpha-20260914220838"
117
117
  },
118
118
  "devDependencies": {
119
119
  "@tailwindcss/vite": "^4.0.5",
@@ -140,7 +140,7 @@
140
140
  "vite-plugin-static-copy": "^3.1.4",
141
141
  "vite-plugin-svgr": "^4.2.0",
142
142
  "vitest": "^4.1.2",
143
- "@igstack/app-catalog-backend-core": "2.0.0-alpha-20260914211846"
143
+ "@igstack/app-catalog-backend-core": "2.0.0-alpha-20260914220838"
144
144
  },
145
145
  "peerDependencies": {
146
146
  "react": "19.1.2",
@@ -149,7 +149,7 @@
149
149
  "vite": "^6.3.5",
150
150
  "vite-plugin-svgr": "^4.2.0"
151
151
  },
152
- "gitHead": "3f9a92b589949710c57e594dd5856b85821e5c0c",
152
+ "gitHead": "ce99b1bc970f7d70497ce0eda46dbd41f5a9c248",
153
153
  "scripts": {
154
154
  "build": "vite build",
155
155
  "build:lenient": "vite build --mode lenient",
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { formatRelativeTime } from '../../../../modules/appCatalog/utils/formatRelativeTime'
3
+
4
+ describe('formatRelativeTime', () => {
5
+ const now = Date.parse('2026-09-14T12:00:00.000Z')
6
+
7
+ it('formats past instants', () => {
8
+ expect(formatRelativeTime('2026-09-14T11:59:38.000Z', now)).toBe(
9
+ '22 seconds ago',
10
+ )
11
+ expect(formatRelativeTime('2026-09-12T12:00:00.000Z', now)).toBe(
12
+ '2 days ago',
13
+ )
14
+ })
15
+
16
+ it('reads a future instant as "now"', () => {
17
+ // The server writes the timestamp and the browser renders it; a clock a few
18
+ // seconds apart must not produce "in 4 seconds" for something just posted.
19
+ expect(formatRelativeTime('2026-09-14T12:00:04.000Z', now)).toBe('now')
20
+ })
21
+
22
+ it('returns an empty string for an unparseable value', () => {
23
+ expect(formatRelativeTime('not a date', now)).toBe('')
24
+ })
25
+ })
@@ -22,7 +22,10 @@ export function formatRelativeTime(
22
22
  const then = Date.parse(iso)
23
23
  if (Number.isNaN(then)) return ''
24
24
  const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
25
- let duration = (then - now) / 1000 // seconds, negative for the past
25
+ // Every timestamp we render already happened, so clamp the future away: a
26
+ // server clock a few seconds ahead of the browser otherwise turns a comment
27
+ // posted a moment ago into "in 4 seconds".
28
+ let duration = Math.min(0, (then - now) / 1000) // seconds, negative for the past
26
29
  for (const division of DIVISIONS) {
27
30
  if (Math.abs(duration) < division.amount) {
28
31
  return rtf.format(Math.round(duration), division.unit)