本文整理汇总了TypeScript中date-fns.startOfWeek函数的典型用法代码示例。如果您正苦于以下问题:TypeScript startOfWeek函数的具体用法?TypeScript startOfWeek怎么用?TypeScript startOfWeek使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startOfWeek函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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,
};
}
示例2: _buildWeekDays
private _buildWeekDays(date: Date, startWithMonday: boolean, showWeekend: boolean): CalendarDay[] {
const days: CalendarDay[] = [];
const weekStartsOn = startWithMonday ? 1 : 0;
const firstDay = startOfWeek(date, {weekStartsOn: weekStartsOn});
let day = new Date(firstDay);
const amountDays = showWeekend ? 7 : 5;
times(amountDays, () => {
days.push(new CalendarDay(day, false, isSameDay(date, new Date())));
day = addDays(day, 1);
});
return days;
}
示例3: getWeekViewHeader
export function getWeekViewHeader({ viewDate, weekStartsOn, excluded = [] }:
{ viewDate: Date, weekStartsOn: number, excluded?: number[] }): WeekDay[] {
const start: Date = dateFns.startOfWeek(viewDate, { weekStartsOn });
const days: WeekDay[] = [];
for (let i: number = 0; i < DAYS_IN_WEEK; i++) {
const date: Date = dateFns.addDays(start, i);
if (!excluded.some(e => date.getDay() === e)) {
days.push(getWeekDay({ date }));
}
}
return days;
}
示例4: getWeekView
export function getWeekView({
events = [],
viewDate,
weekStartsOn,
excluded = [],
hourSegments,
segmentHeight,
dayStart,
dayEnd,
}: {
events?: CalendarEvent[];
viewDate: Date;
weekStartsOn: number;
excluded?: number[];
hourSegments: number;
segmentHeight: number;
dayStart: any;
dayEnd: any;
}): WeekViewEventRow[] {
if (!events) {
events = [];
}
const startOfViewWeek: Date = dateFns.startOfWeek(viewDate, { weekStartsOn });
const endOfViewWeek: Date = dateFns.endOfWeek(viewDate, { weekStartsOn });
const maxRange: number = DAYS_IN_WEEK - excluded.length;
const eventsMapped: WeekViewEvent[] = getEventsInTimeRange(
getEventsInPeriod({ events, periodStart: startOfViewWeek, periodEnd: endOfViewWeek }),
dayStart,
dayEnd,
)
.map((event) => {
const offset: number = getWeekViewEventOffset({ event, startOfWeek: startOfViewWeek, excluded });
const span: number = 1; // getWeekViewEventSpan({ event, offset, startOfWeek: startOfViewWeek, excluded });
return { event, offset, span };
})
.filter((e) => e.offset < maxRange)
.filter((e) => e.span > 0)
.map((entry) => ({
event: entry.event,
offset: entry.offset,
span: entry.span,
startsBeforeWeek: entry.event.start < startOfViewWeek,
endsAfterWeek: (entry.event.end || entry.event.start) > endOfViewWeek,
top: 0,
}))
.sort(
(itemA, itemB): number => {
const startSecondsDiff: number = dateFns.differenceInSeconds(itemA.event.start, itemB.event.start);
if (startSecondsDiff === 0) {
return dateFns.differenceInSeconds(itemB.event.end || itemB.event.start, itemA.event.end || itemA.event.start);
}
return startSecondsDiff;
},
)
.map((entry: WeekViewEvent) => {
const startOfView: Date = dateFns.setMinutes(dateFns.setHours(dateFns.startOfDay(entry.event.start), dayStart.hour), dayStart.minute);
const endOfView: Date = dateFns.setMinutes(
dateFns.setHours(dateFns.startOfMinute(dateFns.endOfDay(entry.event.start)), dayEnd.hour),
dayEnd.minute,
);
const eventStart: Date = entry.event.start;
const eventEnd: Date = entry.event.end || eventStart;
const hourHeightModifier: number = (hourSegments * segmentHeight) / MINUTES_IN_HOUR;
if (eventStart > startOfView) {
entry.top += dateFns.differenceInMinutes(eventStart, startOfView);
}
entry.top *= hourHeightModifier;
const startsBeforeDay: boolean = eventStart < startOfView;
const endsAfterDay: boolean = eventEnd > endOfView;
const startDate: Date = startsBeforeDay ? startOfView : eventStart;
const endDate: Date = endsAfterDay ? endOfView : eventEnd;
let height: number = dateFns.differenceInMinutes(endDate, startDate);
if (!entry.event.end) {
height = segmentHeight;
} else {
height *= hourHeightModifier;
}
entry.height = height;
return entry;
});
const eventRows: WeekViewEventRow[] = [];
const allocatedEvents: WeekViewEvent[] = [];
eventsMapped.forEach((event: WeekViewEvent, index: number) => {
if (allocatedEvents.indexOf(event) === -1) {
allocatedEvents.push(event);
//.........这里部分代码省略.........