本文整理汇总了TypeScript中date-fns.setHours函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setHours函数的具体用法?TypeScript setHours怎么用?TypeScript setHours使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setHours函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getDayViewHourGrid
export function getDayViewHourGrid(
{ viewDate, hourSegments, dayStart, dayEnd }:
{ viewDate: Date, hourSegments: number, dayStart: any, dayEnd: any }
): DayViewHour[] {
const hours: DayViewHour[] = [];
const startOfView: Date = dateFns.setMinutes(dateFns.setHours(dateFns.startOfDay(viewDate), dayStart.hour), dayStart.minute);
const endOfView: Date = dateFns.setMinutes(dateFns.setHours(dateFns.startOfMinute(dateFns.endOfDay(viewDate)), dayEnd.hour), dayEnd.minute);
const segmentDuration: number = MINUTES_IN_HOUR / hourSegments;
const startOfViewDay: Date = dateFns.startOfDay(viewDate);
for (let i: number = 0; i < HOURS_IN_DAY; i++) {
const segments: DayViewHourSegment[] = [];
for (let j: number = 0; j < hourSegments; j++) {
const date: Date = dateFns.addMinutes(dateFns.addHours(startOfViewDay, i), j * segmentDuration);
if (date >= startOfView && date < endOfView) {
segments.push({
date,
isStart: j === 0
});
}
}
if (segments.length > 0) {
hours.push({ segments });
}
}
return hours;
}
示例2:
}).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;
});
示例3:
return events.filter((event) => {
const eventStart: Date = event.start;
const eventEnd: Date = event.end || eventStart;
const startOfView: Date = dateFns.setMinutes(dateFns.setHours(dateFns.startOfDay(eventStart), dayStart.hour), dayStart.minute);
const endOfView: Date = dateFns.setMinutes(dateFns.setHours(dateFns.startOfMinute(eventStart), dayEnd.hour), dayEnd.minute);
return dateFns.isAfter(eventEnd, startOfView) && dateFns.isBefore(eventStart, endOfView);
});
示例4: it
it('should call addLesson when handleCalendarClick is called with a target containing a class without cal- prefix and a day', () => {
const selectDaySpy = spyOn(component, 'selectDay');
const addLessonSpy = spyOn(component, 'addLesson');
const day = {
inMonth: true,
events: [],
badgeTotal: 0,
date: new Date(),
isPast: true,
isToday: true,
isFuture: false,
isWeekend: true
};
const evt = { target: { className: 'icon-button--shake' } };
component.handleCalendarClick(evt, day);
expect(addLessonSpy).toHaveBeenCalledWith(startOfHour(setHours(day.date, environment.defaultLessonStartHour)));
expect(selectDaySpy).not.toHaveBeenCalled();
});
示例5: getDayView
export function getDayView({ events = [], viewDate, hourSegments, dayStart, dayEnd, eventWidth, segmentHeight }: GetDayViewArgs): DayView {
if (!events) {
events = [];
}
const startOfView: Date = dateFns.setMinutes(dateFns.setHours(dateFns.startOfDay(viewDate), dayStart.hour), dayStart.minute);
const endOfView: Date = dateFns.setMinutes(
dateFns.setHours(dateFns.startOfMinute(dateFns.endOfDay(viewDate)), dayEnd.hour),
dayEnd.minute,
);
const previousDayEvents: DayViewEvent[] = [];
const dayViewEvents: DayViewEvent[] = getEventsInTimeRange(
getEventsInPeriod({
events: events.filter((event: CalendarEvent) => !event.allDay),
periodStart: startOfView,
periodEnd: endOfView,
}),
dayStart,
dayEnd,
)
.sort((eventA: CalendarEvent, eventB: CalendarEvent) => {
return eventA.start.valueOf() - eventB.start.valueOf();
})
.map((event: CalendarEvent) => {
const eventStart: Date = event.start;
const eventEnd: Date = event.end || eventStart;
const startsBeforeDay: boolean = eventStart < startOfView;
const endsAfterDay: boolean = eventEnd > endOfView;
const hourHeightModifier: number = (hourSegments * segmentHeight) / MINUTES_IN_HOUR;
let top: number = 0;
if (eventStart > startOfView) {
top += dateFns.differenceInMinutes(eventStart, startOfView);
}
top *= hourHeightModifier;
const startDate: Date = startsBeforeDay ? startOfView : eventStart;
const endDate: Date = endsAfterDay ? endOfView : eventEnd;
let height: number = dateFns.differenceInMinutes(endDate, startDate);
if (!event.end) {
height = segmentHeight;
} else {
height *= hourHeightModifier;
}
const bottom: number = top + height;
const overlappingPreviousEvents: DayViewEvent[] = previousDayEvents.filter((previousEvent: DayViewEvent) => {
const previousEventTop: number = previousEvent.top;
const previousEventBottom: number = previousEvent.top + previousEvent.height;
if (top < previousEventBottom && previousEventBottom < bottom) {
return true;
} else if (previousEventTop <= top && bottom <= previousEventBottom) {
return true;
}
return false;
});
let left: number = 0;
while (overlappingPreviousEvents.some((previousEvent) => previousEvent.left === left)) {
left += eventWidth;
}
const dayEvent: DayViewEvent = {
event,
height,
width: eventWidth,
top,
left,
startsBeforeDay,
endsAfterDay,
};
if (height > 0) {
previousDayEvents.push(dayEvent);
}
return dayEvent;
})
.filter((dayEvent: DayViewEvent) => dayEvent.height > 0);
const width: number = Math.max(...dayViewEvents.map((event: DayViewEvent) => event.left + event.width));
const allDayEvents: CalendarEvent[] = getEventsInPeriod({
events: events.filter((event: CalendarEvent) => event.allDay),
periodStart: dateFns.startOfDay(startOfView),
periodEnd: dateFns.endOfDay(endOfView),
});
return {
events: dayViewEvents,
width,
allDayEvents,
//.........这里部分代码省略.........
示例6: setTime
export function setTime(date: Date, time: Date): Date {
return setHours(setMinutes(setSeconds(date, getSeconds(time)), getMinutes(time)), getHours(time));
}
示例7: getTimeAsDate
export function getTimeAsDate(time: string | number, date: Date = new Date()): Date {
const dateNumber = typeof time === 'string' ? parseInt(time, 10) : time;
return setHours(setMinutes(startOfDay(date), dateNumber % 100), Math.floor(dateNumber / 100));
}
示例8: setTime
export function setTime(date: Date, hours: number, minutes: number, seconds: number): Date {
return setHours(setMinutes(setSeconds(date, seconds), minutes), hours);
}