date-fns#getDate TypeScript Examples
The following examples show how to use
date-fns#getDate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FakeAppointmentsRepository.ts From gobarber-api with MIT License | 6 votes |
public async findAllInDayFromProvider({
provider_id,
day,
month,
year,
}: IFindAllInDayFromProviderDTO): Promise<Appointment[]> {
const appointments = this.appointments.filter(appointment => {
return (
appointment.provider_id === provider_id &&
getDate(appointment.date) === day &&
getMonth(appointment.date) + 1 === month &&
getYear(appointment.date) === year
);
});
return appointments;
}
Example #2
Source File: ListProviderMonthAvailabilityService.ts From gobarber-api with MIT License | 6 votes |
public async execute({
provider_id,
month,
year,
}: IRequest): Promise<IResponse> {
const appointments = await this.appointmentsRepository.findAllInMonthFromProvider(
{
provider_id,
month,
year,
},
);
const numberOfDaysInMonth = getDaysInMonth(new Date(year, month - 1));
const eachDayArray = Array.from(
{ length: numberOfDaysInMonth },
(_, index) => index + 1,
);
const availability = eachDayArray.map(day => {
const compareDate = new Date(year, month - 1, day, 23, 59, 59);
const appointmentsInDay = appointments.filter(appointment => {
return getDate(appointment.date) === day;
});
return {
day,
available:
isAfter(compareDate, new Date()) && appointmentsInDay.length < 10,
};
});
return availability;
}
Example #3
Source File: FakeAppointmentsRepository.ts From hotseat-api with MIT License | 6 votes |
public async findByDayFromProvider({
provider_id,
day,
month,
year,
}: IFindByDayFromProviderDTO): Promise<Appointment[]> {
const appointments = this.appointments.filter(
appointment =>
appointment.provider_id === provider_id &&
getDate(appointment.date) === day &&
getMonth(appointment.date) === month &&
getYear(appointment.date) === year,
);
return appointments;
}
Example #4
Source File: FakeAppointmentsRepository.ts From gobarber-project with MIT License | 6 votes |
public async findAllInDayFromProvider({
provider_id,
day,
month,
year,
}: IFindAllInDayFromProviderDTO): Promise<Appointment[]> {
const appointments = this.appointments.filter(appointment => {
return (
appointment.provider_id === provider_id &&
getDate(appointment.date) === day &&
getMonth(appointment.date) + 1 === month &&
getYear(appointment.date) === year
);
});
return appointments;
}
Example #5
Source File: ListProviderMonthAvailabilityService.ts From gobarber-project with MIT License | 6 votes |
public async execute({
provider_id,
month,
year,
}: IRequest): Promise<IResponse> {
const appointments = await this.appointmentsRepository.findAllInMonthFromProvider(
{
provider_id,
month,
year,
},
);
const numberOfDaysInMonth = getDaysInMonth(new Date(year, month - 1));
const eachDayArray = Array.from(
{ length: numberOfDaysInMonth },
(_, index) => index + 1,
);
const availability = eachDayArray.map(day => {
const compareDate = new Date(year, month - 1, day, 23, 59, 59);
const appointmentsInDay = appointments.filter(appointment => {
return getDate(appointment.date) === day;
});
return {
day,
available:
isAfter(compareDate, new Date()) && appointmentsInDay.length < 10,
};
});
return availability;
}
Example #6
Source File: FakeAppointmentsRepository.ts From GoBarber with MIT License | 6 votes |
public async findAllInDayFromProvider({
provider_id,
day,
month,
year,
}: IFindAllInDayFromProviderDTO): Promise<Appointment[]> {
const appointments = this.appointments.filter(
appointment =>
appointment.provider_id === provider_id &&
getDate(appointment.date) === day &&
getMonth(appointment.date) + 1 === month &&
getYear(appointment.date) === year,
);
return appointments;
}
Example #7
Source File: ListProviderMonthAvailabilityService.ts From GoBarber with MIT License | 6 votes |
public async execute({
provider_id,
month,
year,
}: IRequest): Promise<IResponse> {
const appointments = await this.appointmentsRepository.findAllInMonthFromProvider(
{
provider_id,
month,
year,
},
);
const numberOfDaysInMonth = getDaysInMonth(new Date(year, month - 1));
const eachDayArray = Array.from(
{ length: numberOfDaysInMonth },
(_, index) => index + 1,
);
const availability = eachDayArray.map(day => {
const compareDate = endOfDay(new Date(year, month - 1, day));
const appointmentsInDay = appointments.filter(appointment => {
return getDate(appointment.date) === day;
});
return {
day,
available:
isAfter(compareDate, new Date()) && appointmentsInDay.length < 10,
};
});
return availability;
}
Example #8
Source File: ListProviderMonthAvailabilityService.ts From hotseat-api with MIT License | 5 votes |
async execute({ provider_id, month, year }: IRequest): Promise<IResponse> {
const provider = await this.usersRepository.findById(provider_id);
if (!provider) {
throw new AppError('Provider not found', 404);
}
const appointments = await this.appointmentsRepository.findByMonthFromProvider(
{
year,
month,
provider_id,
},
);
const numberOfDaysInMonth = getDaysInMonth(month - 1);
const daysInMonth = Array.from(
{ length: numberOfDaysInMonth },
(_, index) => index + 1,
);
const availability = daysInMonth.map(day => {
const numberOfAppointmentsInDay = appointments.filter(
appointment => getDate(appointment.date) === day,
).length;
const availabilityDate = new Date(
year,
parseMonthToJSMonth(month),
day,
23,
59,
59,
);
const isPast = isAfter(new Date(Date.now()), availabilityDate);
return {
day,
isPast,
available:
!isPast && numberOfAppointmentsInDay < MAX_APPOINTMENTS_PER_DAY,
};
});
return availability;
}
Example #9
Source File: ngx-mat-datefns-date-adapter.ts From ngx-mat-datefns-date-adapter with MIT License | 5 votes |
getDate(date: Date): number {
return getDate(date);
}
Example #10
Source File: ngx-mat-datefns-date-adapter.ts From ngx-mat-datefns-date-adapter with MIT License | 5 votes |
today(): Date {
const d = new Date();
return this._createDateWithOverflow(
d.getFullYear(),
d.getMonth(),
d.getDate()
);
}
Example #11
Source File: DateSelect.tsx From UUI with MIT License | 4 votes |
DateSelect = UUIFunctionComponent({
name: 'DateSelect',
nodes: {
Root: 'div',
Calendar: 'div',
WeekGrid: 'div',
WeekItem: 'div',
DayGrid: 'div',
DayItem: 'div',
},
propTypes: DateSelectPropTypes,
}, (props: DateSelectFeatureProps, { nodes, NodeDataProps }) => {
const {
Root, Calendar,
WeekGrid, WeekItem,
DayGrid, DayItem,
} = nodes
const betweenIncludeDates = useCallback((date: Date, range: [Date, Date] | Date[]) => {
return !isBefore(date, range[0]) && !isAfter(date, range[1])
}, [])
const dateInfo = useMemo(() => {
const firstDayInMonth = startOfMonth(props.yearMonth)
const weekdayOfFirstDayInMonth = getDay(firstDayInMonth)
const weekdays = range(0, 7).map((i) => {
let date = new Date(props.yearMonth)
date = startOfWeek(date)
date = add(date, { days: i })
return {
key: format(date, 'yyyy-MM-dd'),
date: date,
label: format(date, 'EEEEEE', { locale: zhCN }),
};
});
const days = range(
1 - weekdayOfFirstDayInMonth,
1 - weekdayOfFirstDayInMonth + 6*7,
).map((i) => {
const date = add(firstDayInMonth, { days: i - 1 })
const selected = props.selectedDates.findIndex((i) => isSameDay(date, i)) !== -1
const inSelectedRange = (() => {
if (props.selectedDates.length >= 2) {
return betweenIncludeDates(date, props.selectedDates)
}
return false;
})()
return {
key: format(date, 'yyyy-MM-dd'),
date: date,
label: getDate(date),
active: isSameMonth(props.yearMonth, date),
selected: selected,
inSelectedRange: inSelectedRange,
}
})
return {
weekdays,
days
}
}, [props.yearMonth, props.selectedDates, betweenIncludeDates])
return (
<Root>
<Calendar>
<WeekGrid>
{dateInfo.weekdays.map((weekday) => {
return (
<WeekItem key={weekday.key}>
{weekday.label}
</WeekItem>
);
})}
</WeekGrid>
<DayGrid
onMouseLeave={() => {
props.onHoverDateChange && props.onHoverDateChange(undefined)
}}
>
{dateInfo.days.map((day) => {
const hovering = props.hoverDate ? isSameDay(day.date, props.hoverDate) : false
const inHoverRange = (() => {
if (props.selectedDates.length === 1 && props.hoverDate) {
return betweenIncludeDates(day.date, [props.selectedDates[0], props.hoverDate].sort((i, j) => Number(i) - Number(j)))
}
return false
})()
return (
<DayItem
{...NodeDataProps({
'active': day.active,
'selected': day.selected,
'in-selected-range': day.inSelectedRange,
'in-hover-range': inHoverRange,
'hovering': hovering,
})}
key={day.key}
onClick={() => {
props.onSelect(day.date)
}}
onMouseEnter={() => {
props.onHoverDateChange && props.onHoverDateChange(day.date)
}}
onMouseLeave={() => {
props.onHoverDateChange && props.onHoverDateChange(undefined)
}}
>
{day.label}
</DayItem>
)
})}
</DayGrid>
</Calendar>
</Root>
)
})