本文整理汇总了TypeScript中date-fns.addDays函数的典型用法代码示例。如果您正苦于以下问题:TypeScript addDays函数的具体用法?TypeScript addDays怎么用?TypeScript addDays使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addDays函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
async(inject([MatDialogRef], (dialogRef: MatDialogRef<any>) => {
const originalEventsLength = component.events.length;
const sortEventsSpy = spyOn(component, 'sortEvents');
component.repeatLesson(component.events[0]);
dialogRef.close({ repeatCount: 2, repeatInterval: 100 });
fixture.detectChanges();
const newEventsLength = component.events.length;
expect(newEventsLength).toBe(originalEventsLength + 2);
expect(component.events[newEventsLength - 1].start).toEqual(addDays(component.events[0].start, 200));
expect(component.events[newEventsLength - 2].start).toEqual(addDays(component.events[0].start, 100));
expect(sortEventsSpy).toHaveBeenCalled();
})));
示例2: times
times(getDaysInMonth(date), () => {
const day = new Date(monthDate);
if (showWeekend === true || !isWeekend(day)) {
days.push(new CalendarDay(day, false, isSameDay(monthDate, new Date())));
}
monthDate = addDays(monthDate, 1);
});
示例3: minDate
(weekRange) => {
const end = minDate([parseISO(weekRange.end), date]);
for (let current = parseISO(weekRange.start); current <= end; current = addDays(current, 7)) {
if (isEqual(current, date)) return true;
}
return false;
},
示例4: flow
loadWeek: flow(function* loadWeek() {
self.loading = true;
const start = new Date();
const end = addDays(start, 5);
const query = (fetchPolicy: FetchPolicy = 'network-only') => new Promise((resolve) => {
client.query({
fetchPolicy,
query: fetchMoviesForWeekQuery,
variables: {
start: start.toISOString().substr(0, 10),
end: end.toISOString().substr(0, 10),
},
})
.then(resolve);
if (fetchPolicy === 'network-only') {
setTimeout(() => resolve({ error: { message: 'Network error' } }), 5000);
}
});
let result = yield query();
const isNetworkError = result.error && result.error.message.includes('Network error');
if (isNetworkError) {
result = yield query('cache-only');
}
self.isOffline = isNetworkError;
self.isCache = isNetworkError && result.data;
if (!result.data) {
return;
}
result.data.allMovies.map(Movies.addPartialMovie);
result.data.allMovies.forEach((movie: IMovieFromDb) => {
movie.showtimes.forEach((showtime) => {
const dateKey = addHours(showtime.playingAt, -4).toISOString().substr(0, 10);
if (!self.dates.has(dateKey)) {
self.dates.put({
date: dateKey,
movies: {},
});
}
const dateOf = self.dates.get(dateKey);
if (dateOf) {
dateOf.movies.put({ id: movie.id, movie: movie.id });
}
});
});
self.loaded = true;
self.loading = false;
}),
示例5: Date
() => {
const viewDate = new Date(2018, 6, 1);
const newDate = addDays(viewDate, 1);
component.activeDayIsOpen = true;
component.viewDate = viewDate;
component.selectDay({ date: newDate, events: [] });
expect(component.activeDayIsOpen).toBeFalsy();
});
示例6: createSchedule
function createSchedule(props: Partial<Schedule> & {transaction_date: Date} = {transaction_date: new Date()}): Schedule & {transaction_date: Date} {
return Object.assign({
transaction_date: new Date(),
frequency: "Monthly" as ScheduleFrequency,
next_due_date: addDays(startOfDay(new Date()), 3),
auto_enter: false,
autoFlag: false,
overdue_count: 0,
estimate: false
}, props);
}
示例7: test
function test() {
addDays(new Date(), 5);
closestIndexTo(new Date(), [new Date(), new Date()]);
addHours(new Date(), 5);
differenceInCalendarWeeks(new Date(), new Date());
differenceInCalendarWeeks(new Date(), new Date(), {weekStartsOn: 1});
max(new Date(), new Date());
isDate({});
}
示例8: getMonthView
export function getMonthView({
events = [],
viewDate,
weekStartsOn,
excluded = [],
}: {
events?: CalendarEvent[];
viewDate: Date;
weekStartsOn: number;
excluded?: number[];
}): MonthView {
if (!events) {
events = [];
}
const start: Date = dateFns.startOfWeek(dateFns.startOfMonth(viewDate), { weekStartsOn });
const end: Date = dateFns.endOfWeek(dateFns.endOfMonth(viewDate), { weekStartsOn });
const eventsInMonth: CalendarEvent[] = getEventsInPeriod({
events,
periodStart: start,
periodEnd: end,
});
const days: MonthViewDay[] = [];
for (let i: number = 0; i < dateFns.differenceInDays(end, start) + 1; i++) {
const date: Date = dateFns.addDays(start, i);
if (!excluded.some((e) => date.getDay() === e)) {
const day: MonthViewDay = getWeekDay({ date }) as MonthViewDay;
const calEvents: CalendarEvent[] = getEventsInPeriod({
events: eventsInMonth,
periodStart: dateFns.startOfDay(date),
periodEnd: dateFns.endOfDay(date),
});
day.inMonth = dateFns.isSameMonth(date, viewDate);
day.events = calEvents;
day.badgeTotal = calEvents.length;
days.push(day);
}
}
const totalDaysVisibleInWeek: number = DAYS_IN_WEEK - excluded.length;
const rows: number = Math.floor(days.length / totalDaysVisibleInWeek);
const rowOffsets: number[] = [];
for (let i: number = 0; i < rows; i++) {
rowOffsets.push(i * totalDaysVisibleInWeek);
}
return {
rowOffsets,
totalDaysVisibleInWeek,
days,
};
}