mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Refine date time range
This commit is contained in:
parent
a7fc5536c5
commit
9346a6b543
@ -8,14 +8,11 @@
|
|||||||
<div>
|
<div>
|
||||||
<base-icon name="clock" data-test="calendar" />
|
<base-icon name="clock" data-test="calendar" />
|
||||||
{{
|
{{
|
||||||
getStartTimeString +
|
getStartTimeString + (this.endDateAsDate && isSameDay ? '—' + getEndTimeString : '')
|
||||||
(this.endDateAsDate && isSameDateButMayHaveTimeDifference
|
|
||||||
? '—' + getEndTimeString
|
|
||||||
: '')
|
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<template v-if="!isSameDateButMayHaveTimeDifference">
|
<template v-if="!isSameDay">
|
||||||
—
|
—
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
@ -32,7 +29,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { format, isSameDay } from 'date-fns'
|
import { format, isSameDay, isSameYear } from 'date-fns'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DateRange',
|
name: 'DateRange',
|
||||||
@ -64,24 +61,17 @@ export default {
|
|||||||
endDateAsDate() {
|
endDateAsDate() {
|
||||||
return this.endDate ? new Date(this.endDate) : null
|
return this.endDate ? new Date(this.endDate) : null
|
||||||
},
|
},
|
||||||
isSameDateButMayHaveTimeDifference() {
|
isSameDay() {
|
||||||
return !this.endDateAsDate || isSameDay(this.endDateAsDate, this.startDateAsDate)
|
return !this.endDateAsDate || isSameDay(this.endDateAsDate, this.startDateAsDate)
|
||||||
},
|
},
|
||||||
|
isSameYear() {
|
||||||
|
return !this.endDateAsDate || isSameYear(this.endDateAsDate, this.startDateAsDate)
|
||||||
|
},
|
||||||
getStartDateString() {
|
getStartDateString() {
|
||||||
const isSameYear =
|
let startDateFormat = 'dd.MM.yyyy'
|
||||||
this.isSameDateButMayHaveTimeDifference ||
|
if (!this.isSameDay && this.isSameYear) {
|
||||||
!this.endDateAsDate ||
|
startDateFormat = 'dd.MM.'
|
||||||
this.endDateAsDate.getYear() === this.startDateAsDate.getYear()
|
}
|
||||||
const isSameMonth =
|
|
||||||
isSameYear &&
|
|
||||||
(!this.endDateAsDate || this.endDateAsDate.getMonth() === this.startDateAsDate.getMonth())
|
|
||||||
const startDateFormat = this.isSameDateButMayHaveTimeDifference
|
|
||||||
? 'dd.MM.yyyy'
|
|
||||||
: isSameMonth
|
|
||||||
? 'dd.'
|
|
||||||
: isSameYear
|
|
||||||
? 'dd.MM.'
|
|
||||||
: 'dd.MM.yyyy'
|
|
||||||
return format(this.startDateAsDate, startDateFormat)
|
return format(this.startDateAsDate, startDateFormat)
|
||||||
},
|
},
|
||||||
getStartTimeString() {
|
getStartTimeString() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user