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>
|
||||
<base-icon name="clock" data-test="calendar" />
|
||||
{{
|
||||
getStartTimeString +
|
||||
(this.endDateAsDate && isSameDateButMayHaveTimeDifference
|
||||
? '—' + getEndTimeString
|
||||
: '')
|
||||
getStartTimeString + (this.endDateAsDate && isSameDay ? '—' + getEndTimeString : '')
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="!isSameDateButMayHaveTimeDifference">
|
||||
<template v-if="!isSameDay">
|
||||
—
|
||||
<div>
|
||||
<div>
|
||||
@ -32,7 +29,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { format, isSameDay } from 'date-fns'
|
||||
import { format, isSameDay, isSameYear } from 'date-fns'
|
||||
|
||||
export default {
|
||||
name: 'DateRange',
|
||||
@ -64,24 +61,17 @@ export default {
|
||||
endDateAsDate() {
|
||||
return this.endDate ? new Date(this.endDate) : null
|
||||
},
|
||||
isSameDateButMayHaveTimeDifference() {
|
||||
isSameDay() {
|
||||
return !this.endDateAsDate || isSameDay(this.endDateAsDate, this.startDateAsDate)
|
||||
},
|
||||
isSameYear() {
|
||||
return !this.endDateAsDate || isSameYear(this.endDateAsDate, this.startDateAsDate)
|
||||
},
|
||||
getStartDateString() {
|
||||
const isSameYear =
|
||||
this.isSameDateButMayHaveTimeDifference ||
|
||||
!this.endDateAsDate ||
|
||||
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'
|
||||
let startDateFormat = 'dd.MM.yyyy'
|
||||
if (!this.isSameDay && this.isSameYear) {
|
||||
startDateFormat = 'dd.MM.'
|
||||
}
|
||||
return format(this.startDateAsDate, startDateFormat)
|
||||
},
|
||||
getStartTimeString() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user