diff --git a/libs/pandautils/src/main/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModel.kt b/libs/pandautils/src/main/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModel.kt index 434d80b653..2d39e215f4 100644 --- a/libs/pandautils/src/main/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModel.kt +++ b/libs/pandautils/src/main/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModel.kt @@ -21,7 +21,7 @@ import android.content.res.Resources import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.google.ical.values.DateValueImpl +import com.google.ical.values.DateTimeValueImpl import com.google.ical.values.Frequency import com.google.ical.values.RRule import com.google.ical.values.Weekday @@ -644,7 +644,7 @@ class CreateUpdateEventViewModel @Inject constructor( } if (customFrequencyUiState.selectedDate != null) { val date = customFrequencyUiState.selectedDate - until = DateValueImpl(date.year, date.monthValue, date.dayOfMonth) + until = DateTimeValueImpl(date.year, date.monthValue, date.dayOfMonth, 0, 0, 0) } else { count = customFrequencyUiState.selectedOccurrences } diff --git a/libs/pandautils/src/test/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModelTest.kt b/libs/pandautils/src/test/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModelTest.kt index 4246555d49..4b9bda474a 100644 --- a/libs/pandautils/src/test/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModelTest.kt +++ b/libs/pandautils/src/test/java/com/instructure/pandautils/features/calendarevent/createupdate/CreateUpdateEventViewModelTest.kt @@ -536,6 +536,33 @@ class CreateUpdateEventViewModelTest { } } + @Test + fun `Frequency updates correctly - Custom with date until`() = runTest { + every { savedStateHandle.get(CreateUpdateEventFragment.INITIAL_DATE) } returns "2024-04-10" + + createViewModel() + + viewModel.handleAction(CreateUpdateEventAction.UpdateCustomFrequencyQuantity(2)) + viewModel.handleAction(CreateUpdateEventAction.UpdateCustomFrequencySelectedTimeUnitIndex(1)) + viewModel.handleAction(CreateUpdateEventAction.UpdateCustomFrequencySelectedDays(setOf(DayOfWeek.MONDAY, DayOfWeek.TUESDAY))) + viewModel.handleAction(CreateUpdateEventAction.UpdateCustomFrequencyEndDate(LocalDate.of(2024, 10, 7))) + viewModel.handleAction(CreateUpdateEventAction.SaveCustomFrequency) + viewModel.handleAction(CreateUpdateEventAction.Save(CalendarEventAPI.ModifyEventScope.ONE)) + + coVerify(exactly = 1) { + repository.createEvent( + any(), + any(), + any(), + "FREQ=WEEKLY;UNTIL=20241007T000000Z;INTERVAL=2;BYDAY=MO,TU", + any(), + any(), + any(), + any() + ) + } + } + private fun createViewModel() { viewModel = CreateUpdateEventViewModel(savedStateHandle, resources, repository, apiPrefs) }