2021-10-10 16:25:50 +02:00
|
|
|
<template>
|
2021-11-07 14:59:20 +01:00
|
|
|
<address dir="auto">
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-icon
|
2021-10-10 16:25:50 +02:00
|
|
|
v-if="showIcon"
|
2022-07-12 10:55:28 +02:00
|
|
|
:icon="poiInfos?.poiIcon.icon"
|
2021-10-10 16:25:50 +02:00
|
|
|
size="is-medium"
|
|
|
|
class="icon"
|
|
|
|
/>
|
|
|
|
<p>
|
|
|
|
<span
|
|
|
|
class="addressDescription"
|
2022-07-12 10:55:28 +02:00
|
|
|
:title="poiInfos.name"
|
|
|
|
v-if="poiInfos?.name"
|
2021-10-10 16:25:50 +02:00
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
{{ poiInfos.name }}
|
2021-10-10 16:25:50 +02:00
|
|
|
</span>
|
2022-07-12 10:55:28 +02:00
|
|
|
<br v-if="poiInfos?.name" />
|
|
|
|
<span>
|
|
|
|
{{ poiInfos?.alternativeName }}
|
2021-10-10 16:25:50 +02:00
|
|
|
</span>
|
|
|
|
<br />
|
|
|
|
<small
|
|
|
|
v-if="
|
|
|
|
userTimezoneDifferent &&
|
|
|
|
longShortTimezoneNamesDifferent &&
|
|
|
|
timezoneLongNameValid
|
|
|
|
"
|
|
|
|
>
|
|
|
|
🌐
|
|
|
|
{{
|
|
|
|
$t("{timezoneLongName} ({timezoneShortName})", {
|
|
|
|
timezoneLongName,
|
|
|
|
timezoneShortName,
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
</small>
|
2022-07-12 10:55:28 +02:00
|
|
|
<small v-else-if="userTimezoneDifferent" class="">
|
2021-10-10 16:25:50 +02:00
|
|
|
🌐 {{ timezoneShortName }}
|
|
|
|
</small>
|
|
|
|
</p>
|
|
|
|
</address>
|
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { addressToPoiInfos, IAddress } from "@/types/address.model";
|
|
|
|
import { computed } from "vue";
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
address: IAddress;
|
|
|
|
showIcon?: boolean;
|
|
|
|
showTimezone?: boolean;
|
|
|
|
userTimezone?: string;
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
showIcon: false,
|
|
|
|
showTimezone: false,
|
|
|
|
}
|
|
|
|
);
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const poiInfos = computed(() => addressToPoiInfos(props.address));
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const userTimezoneDifferent = computed((): boolean => {
|
|
|
|
return (
|
|
|
|
props.userTimezone != undefined &&
|
|
|
|
props.address.timezone != undefined &&
|
|
|
|
props.userTimezone !== props.address.timezone
|
|
|
|
);
|
|
|
|
});
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const longShortTimezoneNamesDifferent = computed((): boolean => {
|
|
|
|
return (
|
|
|
|
timezoneLongName.value != undefined &&
|
|
|
|
timezoneShortName.value != undefined &&
|
|
|
|
timezoneLongName.value !== timezoneShortName.value
|
|
|
|
);
|
|
|
|
});
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const timezoneLongName = computed((): string | undefined => {
|
|
|
|
return timezoneName("long");
|
|
|
|
});
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const timezoneShortName = computed((): string | undefined => {
|
|
|
|
return timezoneName("short");
|
|
|
|
});
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const timezoneLongNameValid = computed((): boolean => {
|
|
|
|
return (
|
|
|
|
timezoneLongName.value != undefined && !timezoneLongName.value.match(/UTC/)
|
|
|
|
);
|
|
|
|
});
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const timezoneName = (format: "long" | "short"): string | undefined => {
|
|
|
|
return extractTimezone(
|
|
|
|
new Intl.DateTimeFormat(undefined, {
|
|
|
|
timeZoneName: format,
|
|
|
|
timeZone: props.address.timezone,
|
|
|
|
}).formatToParts()
|
|
|
|
);
|
|
|
|
};
|
2021-10-10 16:25:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const extractTimezone = (
|
|
|
|
parts: Intl.DateTimeFormatPart[]
|
|
|
|
): string | undefined => {
|
|
|
|
return parts.find((part) => part.type === "timeZoneName")?.value;
|
|
|
|
};
|
2021-10-10 16:25:50 +02:00
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
2021-11-04 18:14:36 +01:00
|
|
|
@use "@/styles/_mixins" as *;
|
2021-10-10 16:25:50 +02:00
|
|
|
address {
|
|
|
|
font-style: normal;
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
|
|
span.addressDescription {
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
flex: 1 0 auto;
|
|
|
|
min-width: 100%;
|
|
|
|
max-width: 4rem;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
span.icon {
|
2021-11-04 18:14:36 +01:00
|
|
|
@include padding-right(1rem);
|
2021-10-10 16:25:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|