Skip to content
Open
24 changes: 19 additions & 5 deletions apps/web/core/components/home/user-greetings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,50 @@ export function UserGreetingsView(props: IUserGreetingsView) {
// store hooks
const { t } = useTranslation();

const userTimezone = (() => {
if (!user?.user_timezone) return undefined;
try {
Intl.DateTimeFormat(undefined, { timeZone: user.user_timezone });
return user.user_timezone;
} catch {
return undefined;
}
})();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const hour = new Intl.DateTimeFormat("en-US", {
hour12: false,
timeZone: userTimezone,
hourCycle: "h23",
hour: "numeric",
}).format(currentTime);

const date = new Intl.DateTimeFormat("en-US", {
timeZone: userTimezone,
month: "short",
day: "numeric",
}).format(currentTime);

const weekDay = new Intl.DateTimeFormat("en-US", {
timeZone: userTimezone,
weekday: "long",
}).format(currentTime);

const timeString = new Intl.DateTimeFormat("en-US", {
timeZone: user?.user_timezone,
hour12: false, // Use 24-hour format
timeZone: userTimezone,
hourCycle: "h23",
hour: "2-digit",
minute: "2-digit",
}).format(currentTime);

const greeting = parseInt(hour, 10) < 12 ? "morning" : parseInt(hour, 10) < 18 ? "afternoon" : "evening";
const hourNum = parseInt(hour, 10);
const greeting = hourNum < 5 ? "night" : hourNum < 12 ? "morning" : hourNum < 18 ? "afternoon" : "evening";

return (
<div className="my-6 flex flex-col items-center">
<h2 className="text-center text-20 font-semibold">
{t("good")} {t(greeting)}, {user?.first_name} {user?.last_name}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
</h2>
<h5 className="flex items-center gap-2 font-medium text-placeholder">
<div>{greeting === "morning" ? "🌤️" : greeting === "afternoon" ? "🌥️" : "🌙"}</div>
<div>{greeting === "morning" ? "🌤️" : greeting === "afternoon" ? "🌥️" : "🌙"}</div>
<div>
{weekDay}, {date} {timeString}
</div>
Expand Down
24 changes: 19 additions & 5 deletions apps/web/core/components/user/user-greetings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,50 @@ export function UserGreetingsView(props: IUserGreetingsView) {
// store hooks
const { t } = useTranslation();

const userTimezone = (() => {
if (!user?.user_timezone) return undefined;
try {
Intl.DateTimeFormat(undefined, { timeZone: user.user_timezone });
return user.user_timezone;
} catch {
return undefined;
}
})();

const hour = new Intl.DateTimeFormat("en-US", {
hour12: false,
timeZone: userTimezone,
hourCycle: "h23",
hour: "numeric",
}).format(currentTime);

const date = new Intl.DateTimeFormat("en-US", {
timeZone: userTimezone,
month: "short",
day: "numeric",
}).format(currentTime);

const weekDay = new Intl.DateTimeFormat("en-US", {
timeZone: userTimezone,
weekday: "long",
}).format(currentTime);

const timeString = new Intl.DateTimeFormat("en-US", {
timeZone: user?.user_timezone,
hour12: false, // Use 24-hour format
timeZone: userTimezone,
hourCycle: "h23",
hour: "2-digit",
minute: "2-digit",
}).format(currentTime);

const greeting = parseInt(hour, 10) < 12 ? "morning" : parseInt(hour, 10) < 18 ? "afternoon" : "evening";
const hourNum = parseInt(hour, 10);
const greeting = hourNum < 5 ? "night" : hourNum < 12 ? "morning" : hourNum < 18 ? "afternoon" : "evening";

return (
<div className="my-6 flex flex-col items-center">
<h2 className="text-center text-20 font-semibold">
{t("good")} {t(greeting)}, {user?.first_name} {user?.last_name}
</h2>
<h5 className="flex items-center gap-2 font-medium text-placeholder">
<div>{greeting === "morning" ? "🌤️" : greeting === "afternoon" ? "🌥️" : "🌙"}</div>
<div>{greeting === "morning" ? "🌤️" : greeting === "afternoon" ? "🌥️" : "🌙"}</div>
<div>
{weekDay}, {date} {timeString}
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/cs/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export default {
morning: "ráno",
afternoon: "odpoledne",
evening: "večer",
night: "noc",
show_all: "Zobrazit vše",
show_less: "Zobrazit méně",
no_data_yet: "Zatím žádná data",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/de/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ export default {
morning: "Morgen",
afternoon: "Nachmittag",
evening: "Abend",
night: "Nacht",
show_all: "Alle anzeigen",
show_less: "Weniger anzeigen",
no_data_yet: "Noch keine Daten",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export default {
morning: "morning",
afternoon: "afternoon",
evening: "evening",
night: "night",
show_all: "Show all",
show_less: "Show less",
no_data_yet: "No Data yet",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/es/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ export default {
morning: "días",
afternoon: "tardes",
evening: "noches",
night: "noche",
show_all: "Mostrar todo",
show_less: "Mostrar menos",
no_data_yet: "Aún no hay datos",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/fr/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ export default {
morning: "matin",
afternoon: "après-midi",
evening: "soir",
night: "nuit",
show_all: "Tout afficher",
show_less: "Afficher moins",
no_data_yet: "Pas encore de données",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/id/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export default {
morning: "pagi",
afternoon: "siang",
evening: "malam",
night: "dini hari",
show_all: "Tampilkan semua",
show_less: "Tampilkan lebih sedikit",
no_data_yet: "Belum ada data",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/it/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export default {
morning: "Mattina",
afternoon: "Pomeriggio",
evening: "Sera",
night: "notte",
show_all: "Mostra tutto",
show_less: "Mostra meno",
no_data_yet: "Nessun dato disponibile",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ja/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ export default {
morning: "ございます",
afternoon: "こんにちは",
evening: "こんばんは",
night: "夜",
show_all: "すべて表示",
show_less: "表示を減らす",
no_data_yet: "まだデータがありません",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ko/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export default {
morning: "아침",
afternoon: "오후",
evening: "저녁",
night: "밤",
show_all: "모두 보기",
show_less: "간략히 보기",
no_data_yet: "아직 데이터 없음",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/pl/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ export default {
morning: "rano",
afternoon: "po południu",
evening: "wieczorem",
night: "noc",
show_all: "Pokaż wszystko",
show_less: "Pokaż mniej",
no_data_yet: "Brak danych",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/pt-BR/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ export default {
morning: "manhã",
afternoon: "tarde",
evening: "noite",
night: "noite",
show_all: "Mostrar tudo",
show_less: "Mostrar menos",
no_data_yet: "Nenhum dado ainda",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ro/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export default {
morning: "dimineața",
afternoon: "după-amiaza",
evening: "seara",
night: "noapte",
show_all: "Arată tot",
show_less: "Arată mai puțin",
no_data_yet: "Nicio dată încă",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ru/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ export default {
morning: "утра",
afternoon: "дня",
evening: "вечера",
night: "ночи",
show_all: "Показать все",
show_less: "Свернуть",
no_data_yet: "Нет данных",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/sk/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export default {
morning: "ráno",
afternoon: "popoludnie",
evening: "večer",
night: "noc",
show_all: "Zobraziť všetko",
show_less: "Zobraziť menej",
no_data_yet: "Zatiaľ žiadne dáta",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/tr-TR/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ export default {
morning: "sabah",
afternoon: "öğleden sonra",
evening: "akşam",
night: "gece",
show_all: "Tümünü göster",
show_less: "Daha az göster",
no_data_yet: "Henüz veri yok",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/ua/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ export default {
morning: "ранку",
afternoon: "дня",
evening: "вечора",
night: "ночі",
show_all: "Показати все",
show_less: "Показати менше",
no_data_yet: "Поки що немає даних",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/vi-VN/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export default {
morning: "Buổi sáng",
afternoon: "Buổi chiều",
evening: "Buổi tối",
night: "Buổi đêm",
show_all: "Hiển thị tất cả",
show_less: "Hiển thị ít hơn",
no_data_yet: "Chưa có dữ liệu",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/zh-CN/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ export default {
morning: "早上",
afternoon: "下午",
evening: "晚上",
night: "晚安",
show_all: "显示全部",
show_less: "显示更少",
no_data_yet: "暂无数据",
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/zh-TW/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ export default {
morning: "早上",
afternoon: "下午",
evening: "晚上",
night: "晚安",
show_all: "顯示全部",
show_less: "顯示較少",
no_data_yet: "尚無資料",
Expand Down