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

Function addDays

core/src/components/datetime/utils/manipulation.ts:189–223  ·  view source on GitHub ↗
(refParts: DatetimeParts, numDays: number)

Source from the content-addressed store, hash-verified

187 * Currently can only go forward at most 1 month.
188 */
189export const addDays = (refParts: DatetimeParts, numDays: number) => {
190 const { month, day, year } = refParts;
191 if (day === null) {
192 throw new Error('No day provided');
193 }
194
195 const workingParts = {
196 month,
197 day,
198 year,
199 };
200
201 const daysInMonth = getNumDaysInMonth(month, year);
202 workingParts.day = day + numDays;
203
204 /**
205 * If wrapping to next month
206 * update days and increment month
207 */
208 if (workingParts.day > daysInMonth) {
209 workingParts.day -= daysInMonth;
210 workingParts.month += 1;
211 }
212
213 /**
214 * If moving to next year, reset
215 * month to January and increment year
216 */
217 if (workingParts.month > 12) {
218 workingParts.month = 1;
219 workingParts.year += 1;
220 }
221
222 return workingParts;
223};
224
225/**
226 * Given DatetimeParts, generate the previous month.

Callers 4

getEndOfWeekFunction · 0.85
getNextDayFunction · 0.85
getNextWeekFunction · 0.85

Calls 1

getNumDaysInMonthFunction · 0.90

Tested by

no test coverage detected