-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d95096
commit 05741f0
Showing
2 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,40 @@ | ||
export function format(first: string, middle: string, last: string): string { | ||
return ( | ||
(first || '') + (middle ? ` ${middle}` : '') + (last ? ` ${last}` : '') | ||
); | ||
import { addDays, addMonths, addWeeks, addYears, subDays, subMonths, subWeeks, subYears } from 'date-fns'; | ||
import { CalendarView } from "../models/calendar.types"; | ||
|
||
export function getNextView(currentView: CalendarView, currentDate: Date): Date { | ||
switch (currentView) { | ||
case 'Day': { | ||
return addDays(currentDate, 1); | ||
} | ||
case 'Week': { | ||
return addWeeks(currentDate, 1); | ||
} | ||
case 'Month': { | ||
return addMonths(currentDate, 1); | ||
} | ||
case 'Year': { | ||
return addYears(currentDate, 1); | ||
} | ||
default: | ||
return undefined; | ||
} | ||
} | ||
|
||
export function getPrevView(currentView: CalendarView, currentDate: Date): Date { | ||
switch (currentView) { | ||
case 'Day': { | ||
return subDays(currentDate, 1); | ||
} | ||
case 'Week': { | ||
return subWeeks(currentDate, 1); | ||
} | ||
case 'Month': { | ||
return subMonths(currentDate, 1); | ||
} | ||
case 'Year': { | ||
return subYears(currentDate, 1); | ||
} | ||
default: | ||
return undefined; | ||
} | ||
} |