{{
- to.toLocaleString(
- DateTime.now().year === dateTime.year
+ optionDateTimes.optionEnd.toLocaleString(
+ DateTime.now().year === startDate.year
? { month: 'short' }
: { month: 'short', year: '2-digit' },
)
}}
- {{ dateTime.toLocaleString({ weekday: 'short', day: 'numeric' }) }}
+
+ {{ startDate.toLocaleString({ weekday: 'short', day: 'numeric' }) }}
-
–
+
–
-
- {{ to.toLocaleString({ weekday: 'short', day: 'numeric' }) }}
+
+ {{
+ optionDateTimes.optionEnd.toLocaleString({
+ weekday: 'short',
+ day: 'numeric',
+ })
+ }}
-
+
{{
- isSameDay && !isSameTime
- ? interval.toLocaleString(DateTime.TIME_SIMPLE)
- : dateTime.toLocaleString(DateTime.TIME_SIMPLE)
+ optionDateTimes.isSameDay && !optionDateTimes.isSameTime
+ ? optionDateTimes.optionInterval.toLocaleString(
+ DateTime.TIME_SIMPLE,
+ )
+ : startDate.toLocaleString(DateTime.TIME_SIMPLE)
}}
-
- {{ isSameDay ? '-' : ' ' }}
+
+ {{ optionDateTimes.isSameDay ? '-' : ' ' }}
-
- {{ to.toLocaleString(DateTime.TIME_SIMPLE) }}
+
+ {{ optionDateTimes.optionEnd.toLocaleString(DateTime.TIME_SIMPLE) }}
diff --git a/src/components/Options/OptionItem.vue b/src/components/Options/OptionItem.vue
index ff5758034f..0f0692dc16 100644
--- a/src/components/Options/OptionItem.vue
+++ b/src/components/Options/OptionItem.vue
@@ -57,7 +57,7 @@ const pollStore = usePollStore()
diff --git a/src/components/Options/OptionItemDateBox.vue b/src/components/Options/OptionItemDateBox.vue
index 92ea44a623..c8ae9debef 100644
--- a/src/components/Options/OptionItemDateBox.vue
+++ b/src/components/Options/OptionItemDateBox.vue
@@ -22,7 +22,7 @@ const duration = Duration.fromMillis(durationSeconds * 1000)
-
+
diff --git a/src/components/Options/OptionsDateAddDialog.vue b/src/components/Options/OptionsDateAddDialog.vue
index 36d644ea84..482b7657e2 100644
--- a/src/components/Options/OptionsDateAddDialog.vue
+++ b/src/components/Options/OptionsDateAddDialog.vue
@@ -279,7 +279,7 @@ async function addOption(): Promise {
diff --git a/src/composables/optionDateTime.ts b/src/composables/optionDateTime.ts
new file mode 100644
index 0000000000..941b70db62
--- /dev/null
+++ b/src/composables/optionDateTime.ts
@@ -0,0 +1,73 @@
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import { DateTime, Duration, Interval } from 'luxon'
+import { ref, toValue, watchEffect } from 'vue'
+
+/**
+ * returns the width of the element with the given id
+ *
+ * @param elementId the id of the element whose width should be checked
+ * @param elWidthOffset the width offset to check against
+ */
+
+export const dateFrom = ref()
+
+export function getDates(optionStart: DateTime, optionDuration: Duration | null) {
+ const endDate = ref(optionStart)
+ const localDuration = ref(null as Duration | null)
+ const interval = ref(Interval.fromDateTimes(optionStart, optionStart))
+
+ const fullDays = ref(false)
+ const isSameMonth = ref(false)
+ const isSameDay = ref(false)
+ const isSameTime = ref(false)
+
+ const calculateValues = () => {
+ endDate.value = toValue(optionStart)
+ localDuration.value = toValue(optionDuration)
+ fullDays.value = false
+
+ if (!localDuration.value) {
+ // without duration, no further calculation is possible
+ // end date remains the same as from date
+ return
+ }
+
+ // Check if the duration represents full days
+ fullDays.value =
+ optionStart.valueOf() === optionStart.startOf('day').valueOf()
+ && localDuration.value.hours + localDuration.value.minutes === 0
+
+ // If full days are selected and duration is 0 days, set duration to 1 day
+ if (fullDays.value && localDuration.value.as('days') === 0) {
+ optionDuration = Duration.fromObject({ days: 1 })
+ }
+
+ endDate.value = optionStart.plus(localDuration.value)
+ // If full days are selected, subtract 1 millisecond for display purposes
+ if (fullDays.value) {
+ endDate.value = endDate.value.minus({ milliseconds: 1 })
+ }
+ isSameMonth.value = optionStart.hasSame(endDate.value, 'month')
+ isSameDay.value = optionStart.hasSame(endDate.value, 'day')
+ isSameTime.value = localDuration.value.as('minutes') === 0
+ interval.value = Interval.fromDateTimes(optionStart, endDate.value)
+ }
+
+ watchEffect(() => {
+ calculateValues()
+ })
+
+ return {
+ optionStart,
+ optionEnd: endDate.value,
+ isFullDays: fullDays.value,
+ isSameMonth: isSameMonth.value,
+ isSameDay: isSameDay.value,
+ isSameTime: isSameTime.value,
+ optionInterval: interval.value,
+ }
+}