2019-10-05 21:17:18 +02:00
|
|
|
<docs>
|
|
|
|
#### Give a translated and localized text that give the starting and ending datetime for an event.
|
|
|
|
|
|
|
|
##### Start date with no ending
|
|
|
|
```vue
|
|
|
|
<EventFullDate beginsOn="2015-10-06T18:41:11.720Z" />
|
|
|
|
```
|
|
|
|
|
|
|
|
##### Start date with an ending the same day
|
|
|
|
```vue
|
|
|
|
<EventFullDate beginsOn="2015-10-06T18:41:11.720Z" endsOn="2015-10-06T20:41:11.720Z" />
|
|
|
|
```
|
|
|
|
|
|
|
|
##### Start date with an ending on a different day
|
|
|
|
```vue
|
|
|
|
<EventFullDate beginsOn="2015-10-06T18:41:11.720Z" endsOn="2032-10-06T18:41:11.720Z" />
|
|
|
|
```
|
|
|
|
</docs>
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
<template>
|
2021-10-10 16:25:50 +02:00
|
|
|
<p v-if="!endsOn">
|
|
|
|
<span>{{
|
|
|
|
formatDateTimeString(beginsOn, timezoneToShow, showStartTime)
|
|
|
|
}}</span>
|
|
|
|
<br />
|
|
|
|
<b-switch
|
|
|
|
size="is-small"
|
|
|
|
v-model="showLocalTimezone"
|
|
|
|
v-if="differentFromUserTimezone"
|
|
|
|
>
|
|
|
|
{{ singleTimeZone }}
|
|
|
|
</b-switch>
|
|
|
|
</p>
|
|
|
|
<p v-else-if="isSameDay() && showStartTime && showEndTime">
|
|
|
|
<span>{{
|
2020-02-18 08:57:00 +01:00
|
|
|
$t("On {date} from {startTime} to {endTime}", {
|
|
|
|
date: formatDate(beginsOn),
|
2021-10-10 16:25:50 +02:00
|
|
|
startTime: formatTime(beginsOn, timezoneToShow),
|
|
|
|
endTime: formatTime(endsOn, timezoneToShow),
|
2020-02-18 08:57:00 +01:00
|
|
|
})
|
2021-10-10 16:25:50 +02:00
|
|
|
}}</span>
|
|
|
|
<br />
|
|
|
|
<b-switch
|
|
|
|
size="is-small"
|
|
|
|
v-model="showLocalTimezone"
|
|
|
|
v-if="differentFromUserTimezone"
|
|
|
|
>
|
|
|
|
{{ singleTimeZone }}
|
|
|
|
</b-switch>
|
|
|
|
</p>
|
|
|
|
<p v-else-if="isSameDay() && showStartTime && !showEndTime">
|
2020-02-18 08:57:00 +01:00
|
|
|
{{
|
|
|
|
$t("On {date} starting at {startTime}", {
|
|
|
|
date: formatDate(beginsOn),
|
|
|
|
startTime: formatTime(beginsOn),
|
|
|
|
})
|
|
|
|
}}
|
2021-10-10 16:25:50 +02:00
|
|
|
</p>
|
|
|
|
<p v-else-if="isSameDay()">
|
|
|
|
{{ $t("On {date}", { date: formatDate(beginsOn) }) }}
|
|
|
|
</p>
|
|
|
|
<p v-else-if="endsOn && showStartTime && showEndTime">
|
|
|
|
<span>
|
|
|
|
{{
|
|
|
|
$t(
|
|
|
|
"From the {startDate} at {startTime} to the {endDate} at {endTime}",
|
|
|
|
{
|
|
|
|
startDate: formatDate(beginsOn),
|
|
|
|
startTime: formatTime(beginsOn, timezoneToShow),
|
|
|
|
endDate: formatDate(endsOn),
|
|
|
|
endTime: formatTime(endsOn, timezoneToShow),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</span>
|
|
|
|
<br />
|
|
|
|
<b-switch
|
|
|
|
size="is-small"
|
|
|
|
v-model="showLocalTimezone"
|
|
|
|
v-if="differentFromUserTimezone"
|
|
|
|
>
|
|
|
|
{{ multipleTimeZones }}
|
|
|
|
</b-switch>
|
|
|
|
</p>
|
|
|
|
<p v-else-if="endsOn && showStartTime">
|
|
|
|
<span>
|
|
|
|
{{
|
|
|
|
$t("From the {startDate} at {startTime} to the {endDate}", {
|
|
|
|
startDate: formatDate(beginsOn),
|
|
|
|
startTime: formatTime(beginsOn, timezoneToShow),
|
|
|
|
endDate: formatDate(endsOn),
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
</span>
|
|
|
|
<br />
|
|
|
|
<b-switch
|
|
|
|
size="is-small"
|
|
|
|
v-model="showLocalTimezone"
|
|
|
|
v-if="differentFromUserTimezone"
|
|
|
|
>
|
|
|
|
{{ singleTimeZone }}
|
|
|
|
</b-switch>
|
|
|
|
</p>
|
|
|
|
<p v-else-if="endsOn">
|
2020-02-18 08:57:00 +01:00
|
|
|
{{
|
|
|
|
$t("From the {startDate} to the {endDate}", {
|
|
|
|
startDate: formatDate(beginsOn),
|
|
|
|
endDate: formatDate(endsOn),
|
|
|
|
})
|
|
|
|
}}
|
2021-10-10 16:25:50 +02:00
|
|
|
</p>
|
2019-04-03 17:29:03 +02:00
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
2021-11-10 20:39:44 +01:00
|
|
|
import { getTimezoneOffset } from "date-fns-tz";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
2019-04-03 17:29:03 +02:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class EventFullDate extends Vue {
|
|
|
|
@Prop({ required: true }) beginsOn!: string;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
@Prop({ required: false }) endsOn!: string;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-10-14 19:29:18 +02:00
|
|
|
@Prop({ required: false, default: true }) showStartTime!: boolean;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-10-14 19:29:18 +02:00
|
|
|
@Prop({ required: false, default: true }) showEndTime!: boolean;
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2021-10-10 16:25:50 +02:00
|
|
|
@Prop({ required: false }) timezone!: string;
|
|
|
|
|
|
|
|
@Prop({ required: false }) userTimezone!: string;
|
|
|
|
|
|
|
|
showLocalTimezone = true;
|
|
|
|
|
|
|
|
get timezoneToShow(): string {
|
|
|
|
if (this.showLocalTimezone) {
|
|
|
|
return this.timezone;
|
|
|
|
}
|
|
|
|
return this.userActualTimezone;
|
|
|
|
}
|
|
|
|
|
|
|
|
get userActualTimezone(): string {
|
|
|
|
if (this.userTimezone) {
|
|
|
|
return this.userTimezone;
|
|
|
|
}
|
|
|
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
formatDate(value: Date): string | undefined {
|
|
|
|
if (!this.$options.filters) return undefined;
|
2019-09-09 09:31:08 +02:00
|
|
|
return this.$options.filters.formatDateString(value);
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
|
2021-10-10 16:25:50 +02:00
|
|
|
formatTime(value: Date, timezone: string): string | undefined {
|
2020-02-18 08:57:00 +01:00
|
|
|
if (!this.$options.filters) return undefined;
|
2021-10-10 16:25:50 +02:00
|
|
|
return this.$options.filters.formatTimeString(value, timezone || undefined);
|
|
|
|
}
|
|
|
|
|
|
|
|
formatDateTimeString(
|
|
|
|
value: Date,
|
|
|
|
timezone: string,
|
|
|
|
showTime: boolean
|
|
|
|
): string | undefined {
|
|
|
|
if (!this.$options.filters) return undefined;
|
|
|
|
return this.$options.filters.formatDateTimeString(
|
|
|
|
value,
|
|
|
|
timezone,
|
|
|
|
showTime
|
|
|
|
);
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
isSameDay(): boolean {
|
2020-11-30 10:24:11 +01:00
|
|
|
const sameDay =
|
|
|
|
new Date(this.beginsOn).toDateString() ===
|
|
|
|
new Date(this.endsOn).toDateString();
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.endsOn !== undefined && sameDay;
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
2021-10-10 16:25:50 +02:00
|
|
|
|
|
|
|
get differentFromUserTimezone(): boolean {
|
|
|
|
return (
|
|
|
|
!!this.timezone &&
|
|
|
|
!!this.userActualTimezone &&
|
2021-11-10 20:39:44 +01:00
|
|
|
getTimezoneOffset(this.timezone) !==
|
|
|
|
getTimezoneOffset(this.userActualTimezone) &&
|
2021-10-10 16:25:50 +02:00
|
|
|
this.timezone !== this.userActualTimezone
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get singleTimeZone(): string {
|
|
|
|
if (this.showLocalTimezone) {
|
|
|
|
return this.$t("Local time ({timezone})", {
|
|
|
|
timezone: this.timezoneToShow,
|
|
|
|
}) as string;
|
|
|
|
}
|
|
|
|
return this.$t("Time in your timezone ({timezone})", {
|
|
|
|
timezone: this.timezoneToShow,
|
|
|
|
}) as string;
|
|
|
|
}
|
|
|
|
|
|
|
|
get multipleTimeZones(): string {
|
|
|
|
if (this.showLocalTimezone) {
|
|
|
|
return this.$t("Local time ({timezone})", {
|
|
|
|
timezone: this.timezoneToShow,
|
|
|
|
}) as string;
|
|
|
|
}
|
|
|
|
return this.$t("Times in your timezone ({timezone})", {
|
|
|
|
timezone: this.timezoneToShow,
|
|
|
|
}) as string;
|
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
</script>
|