66<script setup lang="ts">
77import { computed } from ' vue'
88import { DateTime , Duration , Interval } from ' luxon'
9- import { useSessionStore } from ' ../../../stores/session.ts'
109
1110interface Props {
1211 dateTime: DateTime
1312 duration? : Duration
1413}
15- const { dateTime : luxonDate, duration : luxonDuration = Duration .fromMillis (0 ) } =
16- defineProps <Props >()
14+ const { dateTime, duration = Duration .fromMillis (0 ) } = defineProps <Props >()
1715
18- const from = computed (() =>
19- luxonDate .setLocale (sessionStore .currentUser .languageCodeIntl ),
20- )
21-
22- const sessionStore = useSessionStore ()
2316// the dates span one or more entire days
2417// do not display the time in this case
2518const allDay = computed (
2619 () =>
27- from . value . startOf (' day' ).toSeconds () === from . value .toSeconds ()
28- && luxonDuration .as (' seconds' ) % 86400 === 0 ,
20+ dateTime . startOf (' day' ).toSeconds () === dateTime .toSeconds ()
21+ && duration .as (' seconds' ) % 86400 === 0 ,
2922)
3023
3124// 'to' is 'from' plus the duration
3225// subtract a day if allDay is true and luxonDuration is greater than 0 to match the
3326// end of the day after the duration instead of the beginning of the next day
3427const to = computed (() =>
35- from . value
36- .plus (luxonDuration )
37- .minus ({ day: allDay .value && luxonDuration .as (' seconds' ) > 0 ? 1 : 0 }),
28+ dateTime
29+ .plus (duration )
30+ .minus ({ day: allDay .value && duration .as (' seconds' ) > 0 ? 1 : 0 }),
3831)
3932
4033// to and from dates have the same month (and year)
4134// suppress the 'to' month if they are the same
4235const isSameMonth = computed (
43- () => from . value . month === to .value .month && from . value .year === to .value .year ,
36+ () => dateTime . month === to .value .month && dateTime .year === to .value .year ,
4437)
4538
4639// to and from dates have the same day (in the same month and year)
4740// suppress the 'to' day if they are the same
4841// display the interval as timespan inside the same day
49- const isSameDay = computed (
50- () => from .value .day === to .value .day && isSameMonth .value ,
51- )
42+ const isSameDay = computed (() => dateTime .day === to .value .day && isSameMonth .value )
5243
5344// Shortcut: 'to' and 'from' are identical
5445// suppress the 'to' time if they are the same
55- const isSameTime = computed (() => luxonDuration .as (' seconds' ) === 0 )
46+ const isSameTime = computed (() => duration .as (' seconds' ) === 0 )
5647
57- const interval = computed (() =>
58- Interval .fromDateTimes (from .value .toUTC (), to .value .toUTC ()),
59- )
48+ const interval = computed (() => Interval .fromDateTimes (dateTime , to .value ))
6049 </script >
6150
6251<template >
6352 <div :title =" interval.toISO()" class =" datebox" >
6453 <div class =" month from" :class =" { span: isSameMonth }" >
6554 {{
66- from .toLocaleString(
67- DateTime.now().year === from .year
55+ dateTime .toLocaleString(
56+ DateTime.now().year === dateTime .year
6857 ? { month: 'short' }
6958 : { month: 'short', year: '2-digit' },
7059 )
@@ -74,15 +63,15 @@ const interval = computed(() =>
7463 <div v-if =" !isSameMonth" class =" month to" >
7564 {{
7665 to.toLocaleString(
77- DateTime.now().year === from .year
66+ DateTime.now().year === dateTime .year
7867 ? { month: 'short' }
7968 : { month: 'short', year: '2-digit' },
8069 )
8170 }}
8271 </div >
8372
8473 <div class =" day from" :class =" { span: isSameDay }" >
85- {{ from .toLocaleString({ weekday: 'short', day: 'numeric' }) }}
74+ {{ dateTime .toLocaleString({ weekday: 'short', day: 'numeric' }) }}
8675 </div >
8776
8877 <span v-if =" !isSameDay" class =" day divider" >–</span >
@@ -95,7 +84,7 @@ const interval = computed(() =>
9584 {{
9685 isSameDay && !isSameTime
9786 ? interval.toLocaleString(DateTime.TIME_SIMPLE)
98- : from .toLocaleString(DateTime.TIME_SIMPLE)
87+ : dateTime .toLocaleString(DateTime.TIME_SIMPLE)
9988 }}
10089 </div >
10190
0 commit comments