MCPcopy Create free account
hub / github.com/adobe/react-spectrum / alignCenter

Function alignCenter

packages/react-stately/src/calendar/utils.ts:35–52  ·  view source on GitHub ↗
(
  date: CalendarDate,
  duration: DateDuration,
  locale: string,
  minValue?: DateValue | null,
  maxValue?: DateValue | null
)

Source from the content-addressed store, hash-verified

33}
34
35export function alignCenter(
36 date: CalendarDate,
37 duration: DateDuration,
38 locale: string,
39 minValue?: DateValue | null,
40 maxValue?: DateValue | null
41): CalendarDate {
42 let halfDuration: DateDuration = {};
43 for (let key in duration) {
44 halfDuration[key] = Math.floor(duration[key] / 2);
45 if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
46 halfDuration[key]--;
47 }
48 }
49
50 let aligned = alignStart(date, duration, locale).subtract(halfDuration);
51 return constrainStart(date, aligned, duration, locale, minValue, maxValue);
52}
53
54export function alignStart(
55 date: CalendarDate,

Callers 3

getStartDateFunction · 0.90
useCalendarStateFunction · 0.90
useRangeCalendarStateFunction · 0.90

Calls 3

alignStartFunction · 0.85
constrainStartFunction · 0.85
subtractMethod · 0.45

Tested by

no test coverage detected