MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / parseMaxParts

Function parseMaxParts

core/src/components/datetime/utils/parse.ts:158–195  ·  view source on GitHub ↗
(max: string, todayParts: DatetimeParts)

Source from the content-addressed store, hash-verified

156 * month, day, hour, and minute information.
157 */
158export const parseMaxParts = (max: string, todayParts: DatetimeParts): DatetimeParts | undefined => {
159 const result = parseDate(max);
160
161 /**
162 * If min was not a valid date then return undefined.
163 */
164 if (result === undefined) {
165 return;
166 }
167
168 const { month, day, year, hour, minute } = result;
169
170 /**
171 * When passing in `max` or `min`, developers
172 * can pass in any ISO-8601 string. This means
173 * that not all of the date/time fields are defined.
174 * For example, passing max="2012" is valid even though
175 * there is no month, day, hour, or minute data.
176 * However, all of this data is required when clamping the date
177 * so that the correct initial value can be selected. As a result,
178 * we need to fill in any omitted data with the min or max values.
179 */
180
181 const yearValue = year ?? todayParts.year;
182 const monthValue = month ?? 12;
183 return {
184 month: monthValue,
185 day: day ?? getNumDaysInMonth(monthValue, yearValue),
186 /**
187 * Passing in "HH:mm" is a valid ISO-8601
188 * string, so we just default to the current year
189 * in this case.
190 */
191 year: yearValue,
192 hour: hour ?? 23,
193 minute: minute ?? 59,
194 };
195};
196
197/**
198 * Takes a min date string and creates a DatetimeParts

Callers 2

DatetimeClass · 0.90
parse.spec.tsFile · 0.90

Calls 2

getNumDaysInMonthFunction · 0.90
parseDateFunction · 0.85

Tested by

no test coverage detected