@dxos/react-ui-calendar 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8

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,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type Day } from 'date-fns';
5
+ import { type Day, differenceInCalendarDays } from 'date-fns';
6
6
 
7
7
  export const getDate = (start: Date, weekNumber: number, dayOfWeek: number, weekStartsOn: Day): Date => {
8
8
  const result = new Date(start);
@@ -12,6 +12,24 @@ export const getDate = (start: Date, weekNumber: number, dayOfWeek: number, week
12
12
  return result;
13
13
  };
14
14
 
15
+ /**
16
+ * Inverse of {@link getDate}: returns the row index for a given date, matching
17
+ * the grid layout (which respects `weekStartsOn`).
18
+ *
19
+ * Uses `differenceInCalendarDays` (DST-safe) — naive ms subtraction silently
20
+ * loses an hour each DST transition, which accumulates over decades and
21
+ * eventually shifts the row boundary by one day. `differenceInWeeks` is also
22
+ * unsuitable because it computes raw 7-day chunks anchored at the start
23
+ * date's weekday rather than the grid's `weekStartsOn` column.
24
+ */
25
+ export const getRowIndex = (start: Date, date: Date, weekStartsOn: Day): number => {
26
+ const startDayOfWeek = start.getDay();
27
+ const adjustedStartDay = (startDayOfWeek === 0 ? 7 : startDayOfWeek) - weekStartsOn;
28
+ const row0Start = new Date(start);
29
+ row0Start.setDate(start.getDate() - adjustedStartDay);
30
+ return Math.floor(differenceInCalendarDays(date, row0Start) / 7);
31
+ };
32
+
15
33
  export const isSameDay = (date1: Date, date2: Date | undefined): boolean => {
16
34
  return (
17
35
  !!date2 &&
@@ -4,13 +4,13 @@
4
4
 
5
5
  import { type Resource } from '@dxos/react-ui';
6
6
 
7
- export const translationKey = 'react-ui-calendar';
7
+ export const translationKey = '@dxos/react-ui-calendar';
8
8
 
9
9
  export const translations = [
10
10
  {
11
11
  'en-US': {
12
12
  [translationKey]: {
13
- 'today button': 'Today',
13
+ 'today.button': 'Today',
14
14
  },
15
15
  },
16
16
  },