@linktr.ee/messaging-react 3.30.0-rc-1785753549 → 3.30.0-rc-1785813043

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.
@@ -68,59 +68,61 @@ describe('formatRelativeTime', () => {
68
68
  mockDate('2024-01-15T12:00:00Z')
69
69
  const date = new Date('2024-01-13T12:00:00Z')
70
70
  expect(formatRelativeTime(date)).not.toBe('Yesterday')
71
- expect(formatRelativeTime(date)).toBe('2d')
72
71
  })
73
72
  })
74
73
 
75
- describe('Days ago', () => {
76
- it('should return "2d" for messages 2 days ago', () => {
74
+ describe('2-6 days ago (short weekday)', () => {
75
+ // The weekday branch uses the runtime locale
76
+ // (toLocaleDateString(undefined, …)), so assertions avoid fixed
77
+ // strings that would depend on the test runner's ambient ICU locale.
78
+ // A short weekday name is purely alphabetic with no digits.
79
+ const weekdayPattern = /^\p{L}+$/u
80
+
81
+ it('should return a short weekday name for messages 2 days ago', () => {
77
82
  mockDate('2024-01-15T12:00:00Z')
78
- const date = new Date('2024-01-13T12:00:00Z')
79
- expect(formatRelativeTime(date)).toBe('2d')
83
+ const date = new Date('2024-01-13T12:00:00Z') // Saturday
84
+ const result = formatRelativeTime(date)
85
+ expect(result).toMatch(weekdayPattern)
86
+ expect(result).toBe(date.toLocaleDateString(undefined, { weekday: 'short' }))
80
87
  })
81
88
 
82
- it('should return "6d" for messages 6 days ago (boundary before weeks)', () => {
89
+ it('should return a short weekday name for messages 6 days ago (boundary before dates)', () => {
83
90
  mockDate('2024-01-15T12:00:00Z')
84
- const date = new Date('2024-01-09T12:00:00Z')
85
- expect(formatRelativeTime(date)).toBe('6d')
91
+ const date = new Date('2024-01-09T12:00:00Z') // Tuesday
92
+ const result = formatRelativeTime(date)
93
+ expect(result).toMatch(weekdayPattern)
94
+ expect(result).toBe(date.toLocaleDateString(undefined, { weekday: 'short' }))
86
95
  })
87
96
  })
88
97
 
89
- describe('Weeks ago', () => {
90
- it('should return "1w" for messages 1 week ago', () => {
98
+ describe('7+ days ago, same year (month and day)', () => {
99
+ it('should return month + day without year for messages 7 days ago', () => {
91
100
  mockDate('2024-01-15T12:00:00Z')
92
101
  const date = new Date('2024-01-08T12:00:00Z')
93
- expect(formatRelativeTime(date)).toBe('1w')
102
+ const result = formatRelativeTime(date)
103
+ expect(result).toMatch(/\p{L}/u) // spelled-out month
104
+ expect(result).toMatch(/\b8\b/) // day
105
+ expect(result).not.toMatch(/2024|24/) // no year
94
106
  })
95
- })
96
107
 
97
- describe('Date format', () => {
98
- // The absolute-date branch intentionally uses the runtime locale
99
- // (toLocaleDateString(undefined, …)), so assertions avoid a fixed
100
- // string that would depend on the test runner's ambient ICU locale.
101
- // Instead we assert the locale-independent behaviour: a spelled-out
102
- // month (alphabetic) rather than the old all-numeric M/D/YY, plus the
103
- // day and 2-digit year in any order.
104
- const numericDatePattern = /^\d{1,2}\/\d{1,2}\/\d{2}$/
105
-
106
- it('should return a spelled-month date for messages more than 4 weeks ago', () => {
108
+ it('should return month + day without year for messages more than 4 weeks ago in the same year', () => {
107
109
  mockDate('2024-02-15T12:00:00Z')
108
110
  const date = new Date('2024-01-01T12:00:00Z')
109
111
  const result = formatRelativeTime(date)
110
- expect(result).not.toMatch(numericDatePattern)
111
112
  expect(result).toMatch(/\p{L}/u) // spelled-out month
112
113
  expect(result).toMatch(/\b1\b/) // day
113
- expect(result).toMatch(/24/) // 2-digit year
114
+ expect(result).not.toMatch(/2024|24/) // no year
114
115
  })
116
+ })
115
117
 
116
- it('should return a spelled-month date for messages from last year', () => {
118
+ describe('Previous years (month, day and year)', () => {
119
+ it('should include the full year for messages from a previous year', () => {
117
120
  mockDate('2024-01-15T12:00:00Z')
118
121
  const date = new Date('2023-12-01T12:00:00Z')
119
122
  const result = formatRelativeTime(date)
120
- expect(result).not.toMatch(numericDatePattern)
121
123
  expect(result).toMatch(/\p{L}/u) // spelled-out month
122
124
  expect(result).toMatch(/\b1\b/) // day
123
- expect(result).toMatch(/23/) // 2-digit year
125
+ expect(result).toMatch(/2023/) // full year
124
126
  })
125
127
  })
126
128
 
@@ -15,7 +15,9 @@ const getDaysDifference = (date1: Date, date2: Date): number => {
15
15
 
16
16
  /**
17
17
  * Format a date - shows time for today, relative time for older messages
18
- * (e.g., "Just now", "2:08 PM" for today, "Yesterday" for yesterday, "2d" for 2 days ago)
18
+ * (e.g., "Just now", "2:08 PM" for today, "Yesterday" for yesterday,
19
+ * "Mon" for 2-6 days ago, "Jul 14" for older dates this year,
20
+ * "Jul 14, 2025" for previous years)
19
21
  */
20
22
  export const formatRelativeTime = (date: Date): string => {
21
23
  const now = new Date()
@@ -43,21 +45,23 @@ export const formatRelativeTime = (date: Date): string => {
43
45
  return 'Yesterday'
44
46
  }
45
47
 
46
- // Less than 7 days - show days
48
+ // 2-6 days ago - show short weekday name (e.g., "Mon")
47
49
  if (daysDiff < 7) {
48
- return `${daysDiff}d`
50
+ return date.toLocaleDateString(undefined, { weekday: 'short' })
49
51
  }
50
52
 
51
- // Less than 4 weeks - show weeks
52
- if (daysDiff < 28) {
53
- const weeks = Math.floor(daysDiff / 7)
54
- return `${weeks}w`
53
+ // 7+ days ago, same year - show month and day (e.g., "Jul 14")
54
+ if (date.getFullYear() === now.getFullYear()) {
55
+ return date.toLocaleDateString(undefined, {
56
+ month: 'short',
57
+ day: 'numeric',
58
+ })
55
59
  }
56
60
 
57
- // More than 4 weeks - show locale-aware date with spelled-out month
61
+ // Previous years - include the year (e.g., "Jul 14, 2025")
58
62
  return date.toLocaleDateString(undefined, {
59
- day: 'numeric',
60
63
  month: 'short',
61
- year: '2-digit',
64
+ day: 'numeric',
65
+ year: 'numeric',
62
66
  })
63
67
  }