@wallarm-org/design-system 1.22.2 → 1.22.3-rc-fix-date-utils-honour-format-context.1

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.
@@ -2,6 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { isValid } from "date-fns";
3
3
  import { cn } from "../../utils/cn.js";
4
4
  import { formatAbsoluteDate, formatAbsoluteTime, formatRelativeTime, formatTimeOnly } from "../../utils/formatDateTime.js";
5
+ import { useDateFormat } from "../DateFormatProvider/useDateFormat.js";
5
6
  import { Text } from "../Text/index.js";
6
7
  import { Tooltip, TooltipContent, TooltipTrigger } from "../Tooltip/index.js";
7
8
  const toDate = (value)=>{
@@ -9,6 +10,7 @@ const toDate = (value)=>{
9
10
  return new Date(value);
10
11
  };
11
12
  const FormatDateTime = ({ value, format = 'relative', layout = 'stacked', showSeconds = true, ref, ...props })=>{
13
+ const dateFormat = useDateFormat();
12
14
  if (null == value) return /*#__PURE__*/ jsxs(Tooltip, {
13
15
  children: [
14
16
  /*#__PURE__*/ jsx(TooltipTrigger, {
@@ -42,7 +44,8 @@ const FormatDateTime = ({ value, format = 'relative', layout = 'stacked', showSe
42
44
  });
43
45
  const isoString = date.toISOString();
44
46
  const tooltipText = formatAbsoluteTime(date, {
45
- showSeconds
47
+ showSeconds,
48
+ ...dateFormat
46
49
  });
47
50
  if ('relative' === format) return /*#__PURE__*/ jsxs(Tooltip, {
48
51
  children: [
@@ -57,7 +60,7 @@ const FormatDateTime = ({ value, format = 'relative', layout = 'stacked', showSe
57
60
  size: "sm",
58
61
  children: /*#__PURE__*/ jsx("span", {
59
62
  className: cn('whitespace-nowrap border-b-1 border-dashed border-border-strong-primary'),
60
- children: formatRelativeTime(date)
63
+ children: formatRelativeTime(date, void 0, dateFormat)
61
64
  })
62
65
  })
63
66
  })
@@ -76,12 +79,12 @@ const FormatDateTime = ({ value, format = 'relative', layout = 'stacked', showSe
76
79
  children: [
77
80
  /*#__PURE__*/ jsx(Text, {
78
81
  size: "sm",
79
- children: formatAbsoluteDate(date)
82
+ children: formatAbsoluteDate(date, void 0, dateFormat)
80
83
  }),
81
84
  /*#__PURE__*/ jsx(Text, {
82
85
  size: "sm",
83
86
  color: "secondary",
84
- children: formatTimeOnly(date)
87
+ children: formatTimeOnly(date, dateFormat)
85
88
  })
86
89
  ]
87
90
  });
@@ -93,7 +96,7 @@ const FormatDateTime = ({ value, format = 'relative', layout = 'stacked', showSe
93
96
  ...props,
94
97
  children: /*#__PURE__*/ jsx(Text, {
95
98
  size: "sm",
96
- children: formatAbsoluteDate(date)
99
+ children: formatAbsoluteDate(date, void 0, dateFormat)
97
100
  })
98
101
  });
99
102
  };
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "1.22.1",
3
- "generatedAt": "2026-09-24T06:31:30.327Z",
2
+ "version": "1.22.2",
3
+ "generatedAt": "2026-09-24T08:10:05.373Z",
4
4
  "components": [
5
5
  {
6
6
  "name": "Accordion",
@@ -1,3 +1,16 @@
1
+ import type { DateOrder } from '../components/DateFormatProvider/context';
2
+ /**
3
+ * App-level date preferences, as `DateFormatProvider` models them.
4
+ *
5
+ * The formatters below take them as an argument rather than reading the
6
+ * context, so they stay pure and usable outside React; `FormatDateTime` is
7
+ * what feeds them the active values. Omitted, each falls back to the shape
8
+ * these functions have always produced — day-first, 24-hour.
9
+ */
10
+ export interface DateTimeFormatOptions {
11
+ order?: DateOrder;
12
+ hourCycle?: 12 | 24;
13
+ }
1
14
  /**
2
15
  * Format a date as relative time for table cells.
3
16
  *
@@ -15,13 +28,13 @@
15
28
  *
16
29
  * Future dates are treated as "Just now" (clock skew tolerance).
17
30
  */
18
- export declare const formatRelativeTime: (date: Date, now?: Date) => string;
31
+ export declare const formatRelativeTime: (date: Date, now?: Date, options?: DateTimeFormatOptions) => string;
19
32
  /**
20
33
  * Format a date as absolute time for tooltips.
21
34
  *
22
35
  * Output: "11 Feb, 2026 14:32:07 GMT+2"
23
36
  */
24
- export declare const formatAbsoluteTime: (date: Date, options?: {
37
+ export declare const formatAbsoluteTime: (date: Date, options?: DateTimeFormatOptions & {
25
38
  showSeconds?: boolean;
26
39
  }) => string;
27
40
  /**
@@ -29,13 +42,13 @@ export declare const formatAbsoluteTime: (date: Date, options?: {
29
42
  *
30
43
  * Output: "11 Feb, 2026"
31
44
  */
32
- export declare const formatAbsoluteDate: (date: Date, now?: Date) => string;
45
+ export declare const formatAbsoluteDate: (date: Date, now?: Date, options?: DateTimeFormatOptions) => string;
33
46
  /**
34
47
  * Format only the time portion for cells.
35
48
  *
36
49
  * Output: "14:32 GMT+2"
37
50
  */
38
- export declare const formatTimeOnly: (date: Date) => string;
51
+ export declare const formatTimeOnly: (date: Date, options?: DateTimeFormatOptions) => string;
39
52
  /**
40
53
  * Format timezone as "GMT+N" or "UTC".
41
54
  */
@@ -1,5 +1,11 @@
1
1
  import { differenceInDays, differenceInHours, differenceInMinutes, differenceInMonths, differenceInSeconds, differenceInWeeks, differenceInYears, format, isValid } from "date-fns";
2
- const formatRelativeTime = (date, now = new Date())=>{
2
+ const dayMonth = (order)=>'month-first' === order ? 'MMM d' : 'd MMM';
3
+ const dayMonthYear = (order)=>`${dayMonth(order)}, yyyy`;
4
+ const timePattern = (hourCycle, showSeconds)=>{
5
+ const seconds = showSeconds ? ':ss' : '';
6
+ return 12 === hourCycle ? `hh:mm${seconds} a` : `HH:mm${seconds}`;
7
+ };
8
+ const formatRelativeTime = (date, now = new Date(), options = {})=>{
3
9
  if (!isValid(date)) return '—';
4
10
  const seconds = differenceInSeconds(now, date);
5
11
  if (seconds < 0) return 'Just now';
@@ -9,32 +15,31 @@ const formatRelativeTime = (date, now = new Date())=>{
9
15
  const hours = differenceInHours(now, date);
10
16
  if (hours < 24) return 1 === hours ? '1 hour ago' : `${hours} hours ago`;
11
17
  const days = differenceInDays(now, date);
12
- if (days < 2) return `Yesterday, ${format(date, 'HH:mm')}`;
18
+ if (days < 2) return `Yesterday, ${format(date, timePattern(options.hourCycle, false))}`;
13
19
  if (days < 7) return `${days} days ago`;
14
20
  const weeks = differenceInWeeks(now, date);
15
21
  if (days < 14) return '1 week ago';
16
22
  if (days < 28) return `${weeks} weeks ago`;
17
23
  const months = differenceInMonths(now, date);
18
24
  if (days < 150) return 1 === months ? '1 month ago' : `${months} months ago`;
19
- if (differenceInYears(now, date) < 1) return format(date, 'd MMM');
20
- return format(date, 'd MMM, yyyy');
25
+ if (differenceInYears(now, date) < 1) return format(date, dayMonth(options.order));
26
+ return format(date, dayMonthYear(options.order));
21
27
  };
22
28
  const formatAbsoluteTime = (date, options = {})=>{
23
29
  if (!isValid(date)) return '—';
24
30
  const { showSeconds = true } = options;
25
- const timePattern = showSeconds ? 'HH:mm:ss' : 'HH:mm';
26
- const formatted = format(date, `d MMM, yyyy ${timePattern}`);
31
+ const formatted = format(date, `${dayMonthYear(options.order)} ${timePattern(options.hourCycle, showSeconds)}`);
27
32
  const tz = formatTimezone(date);
28
33
  return `${formatted} ${tz}`;
29
34
  };
30
- const formatAbsoluteDate = (date, now = new Date())=>{
35
+ const formatAbsoluteDate = (date, now = new Date(), options = {})=>{
31
36
  if (!isValid(date)) return '—';
32
- if (date.getFullYear() === now.getFullYear()) return format(date, 'd MMM');
33
- return format(date, 'd MMM, yyyy');
37
+ if (date.getFullYear() === now.getFullYear()) return format(date, dayMonth(options.order));
38
+ return format(date, dayMonthYear(options.order));
34
39
  };
35
- const formatTimeOnly = (date)=>{
40
+ const formatTimeOnly = (date, options = {})=>{
36
41
  if (!isValid(date)) return '—';
37
- return `${format(date, 'HH:mm')} ${formatTimezone(date)}`;
42
+ return `${format(date, timePattern(options.hourCycle, false))} ${formatTimezone(date)}`;
38
43
  };
39
44
  const formatTimezone = (date)=>{
40
45
  const offset = -date.getTimezoneOffset();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wallarm-org/design-system",
3
- "version": "1.22.2",
3
+ "version": "1.22.3-rc-fix-date-utils-honour-format-context.1",
4
4
  "description": "Core design system library with React components and Storybook documentation",
5
5
  "publishConfig": {
6
6
  "access": "public",