date-fns#setDay TypeScript Examples

The following examples show how to use date-fns#setDay. 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: ngx-mat-datefns-date-adapter.ts    From ngx-mat-datefns-date-adapter with MIT License 6 votes vote down vote up
getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): string[] {
    const map = {
      long: 'EEEE',
      short: 'EEE',
      narrow: 'EEEEE',
    };

    const formatStr = map[style];
    const date = new Date();

    return range(0, 6).map((day) =>
      format(setDay(date, day), formatStr, {
        locale: this._dateFnsLocale,
      })
    );
  }
Example #2
Source File: WeeklyCalendar.tsx    From react-calendar with MIT License 6 votes vote down vote up
DayButton = ({ day }: DayButtonProps) => {
  let { locale, week, selectedDay, changeSelectedDay } = useWeeklyCalendar();
  let isSelected = selectedDay ? getDay(selectedDay) === day.day : false;
  let currentDate = setDay(week, day.day, { locale });
  return (
    <li
      onClick={() => changeSelectedDay(isSelected ? undefined : currentDate)}
      className="rc-bg-white rc-cursor-pointer"
      aria-label="Day of Week"
    >
      <div
        className={`rc-rounded-lg rc-border sm:rc-w-36 rc-text-center rc-py-4 ${
          isSelected
            ? 'rc-border-indigo-600'
            : 'rc-border-gray-300 hover:rc-border-gray-500'
        }`}
      >
        <p className="rc-font-medium rc-text-sm rc-text-gray-800">
          {day.label} {format(currentDate, 'do', { locale })}
        </p>
      </div>
    </li>
  );
}