vikunja-frontend/src/helpers/time/calculateDayInterval.ts

27 lines
675 B
TypeScript
Raw Normal View History

Better reminders (#308) Fix setting the new reminder component to null after adding a new date Add "close on change" event which only fires if the component closed and the value actually changed Hide the "today" option after 21:00 Add "confirm" button to close the component Use disabled in reminders Add a disabled property to the datepicker Cleanup workarounds for flatpickr Use the new datepicker for end dates Use the new datepicker for start date Use the new datepicker for due dates Mobile styling Format Sync flatpickr when clicking on choose a date Make sure to only hide the popup when not clicked something inside of it Make flatpickr dates work Use datepicker component for reminders Merge branch 'master' into feature/better-reminders Fix bottom padding of inline flatpickr Set time Add method to calculate the neares time Move time helpers in separate folder Remove separate flatpickr date Cleanup Set the flatpickr date when setting changing the date Better formatting of the chosen date Bubble Set date when choosing one Fix test Show correct weekday in preview Change hover background color Make label to show if selected date is null configurable Use a different icon for weekend Ignore test files when linting Add tests to dron Move day interval calculation to separate file and test it Add next date calculation Add basic date picker component Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/308 Co-Authored-By: konrad <konrad@kola-entertainments.de> Co-Committed-By: konrad <konrad@kola-entertainments.de>
2020-11-28 14:59:27 +01:00
export function calculateDayInterval(date, currentDay = (new Date().getDay())) {
switch (date) {
case 'today':
return 0
case 'tomorrow':
return 1
case 'nextMonday':
// Monday is 1, so we calculate the distance to the next 1
return (currentDay + (8 - currentDay * 2)) % 7
case 'thisWeekend':
// Saturday is 6 so we calculate the distance to the next 6
return (6 - currentDay) % 6
case 'laterThisWeek':
if (currentDay === 5 || currentDay === 6 || currentDay === 0) {
return 0
}
return 2
case 'laterNextWeek':
return calculateDayInterval('laterThisWeek', currentDay) + 7
case 'nextWeek':
return 7
default:
return 0
}
}