本文整理汇总了TypeScript中date-fns.startOfDay函数的典型用法代码示例。如果您正苦于以下问题:TypeScript startOfDay函数的具体用法?TypeScript startOfDay怎么用?TypeScript startOfDay使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startOfDay函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: it
it('dayViewHour', () => {
expect(
dateFormatter.dayViewHour({
date: startOfDay(new Date('2016-01-01')),
locale: 'en'
})
).to.equal('12 AM');
});
示例4:
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);
});
示例5: getWeekDay
function getWeekDay({ date }: { date: Date }): WeekDay {
const today: Date = dateFns.startOfDay(new Date());
return {
date,
isPast: date < today,
isToday: dateFns.isSameDay(date, today),
isFuture: date > today,
isWeekend: WEEKEND_DAY_NUMBERS.indexOf(dateFns.getDay(date)) > -1,
};
}
示例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: createPartialTransaction
function createPartialTransaction(props: Partial<Transaction | SplitTransactionChild>): Partial<Transaction | SplitTransactionChild> {
id++;
return Object.assign({
id,
memo: "",
flag: null,
balance: 0,
transaction_date: subDays(startOfDay(new Date()), 1),
status: "" as TransactionStatus
}, props);
}
示例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,
};
}
示例9: it
it('should set the view date to the start of today', () => {
const fixture: ComponentFixture<TestComponent> = TestBed.createComponent(
TestComponent
);
fixture.componentInstance.viewDate = new Date('2017-01-28');
fixture.detectChanges();
fixture.nativeElement.querySelector('button').click();
fixture.detectChanges();
expect(fixture.componentInstance.viewDate).to.deep.equal(
startOfDay(new Date())
);
fixture.destroy();
});
示例10: constructor
/**
* Constructor
*
* @param data
*/
constructor(data?)
{
data = data || {};
this.start = new Date(data.start) || startOfDay(new Date());
this.end = new Date(data.end) || endOfDay(new Date());
this.title = data.title || '';
this.color = {
primary : data.color && data.color.primary || '#1e90ff',
secondary: data.color && data.color.secondary || '#D1E8FF'
};
this.draggable = data.draggable;
this.resizable = {
beforeStart: data.resizable && data.resizable.beforeStart || true,
afterEnd : data.resizable && data.resizable.afterEnd || true
};
this.actions = data.actions || [];
this.allDay = data.allDay || false;
this.cssClass = data.cssClass || '';
this.meta = {
location: data.meta && data.meta.location || '',
notes : data.meta && data.meta.notes || ''
};
}