From bb4e965a6694710069cb11b509ebbd1c32847a5c Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Tue, 28 Apr 2020 10:13:59 +1000 Subject: [PATCH] FEATURE: Optionally show local time for user in card (#9527) This adds a site setting (default off) to optionally show a user's local time and timezone in their user card. For example, I live in Brisbane, and if at 3:30PM my time I were to open a user who lives in California's card I would see 22:30 (PST). --- .../app/components/user-card-contents.js | 20 ++++++++- .../javascripts/discourse/app/models/user.js | 5 +++ .../components/user-card-contents.hbs | 20 ++++++--- .../common/components/user-card.scss | 4 +- app/serializers/user_card_serializer.rb | 11 ++++- config/locales/client.ar.yml | 1 + config/locales/client.be.yml | 1 + config/locales/client.bg.yml | 1 + config/locales/client.bs_BA.yml | 1 + config/locales/client.ca.yml | 1 + config/locales/client.cs.yml | 1 + config/locales/client.da.yml | 1 + config/locales/client.de.yml | 1 + config/locales/client.el.yml | 1 + config/locales/client.en.yml | 2 + config/locales/client.en_US.yml | 2 + config/locales/client.es.yml | 1 + config/locales/client.et.yml | 1 + config/locales/client.fa_IR.yml | 1 + config/locales/client.fi.yml | 1 + config/locales/client.fr.yml | 1 + config/locales/client.gl.yml | 1 + config/locales/client.he.yml | 1 + config/locales/client.hu.yml | 1 + config/locales/client.hy.yml | 1 + config/locales/client.id.yml | 1 + config/locales/client.it.yml | 1 + config/locales/client.ja.yml | 1 + config/locales/client.ko.yml | 1 + config/locales/client.lt.yml | 1 + config/locales/client.lv.yml | 1 + config/locales/client.nb_NO.yml | 1 + config/locales/client.nl.yml | 1 + config/locales/client.pl_PL.yml | 1 + config/locales/client.pt.yml | 1 + config/locales/client.pt_BR.yml | 1 + config/locales/client.ro.yml | 1 + config/locales/client.ru.yml | 1 + config/locales/client.sk.yml | 1 + config/locales/client.sl.yml | 1 + config/locales/client.sq.yml | 1 + config/locales/client.sr.yml | 1 + config/locales/client.sv.yml | 1 + config/locales/client.sw.yml | 1 + config/locales/client.te.yml | 1 + config/locales/client.th.yml | 1 + config/locales/client.tr_TR.yml | 1 + config/locales/client.uk.yml | 1 + config/locales/client.ur.yml | 1 + config/locales/client.vi.yml | 1 + config/locales/client.zh_CN.yml | 1 + config/locales/client.zh_TW.yml | 1 + config/locales/server.en.yml | 1 + config/site_settings.yml | 3 ++ test/javascripts/acceptance/user-card-test.js | 45 +++++++++++++++++++ 55 files changed, 148 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/user-card-contents.js b/app/assets/javascripts/discourse/app/components/user-card-contents.js index 655c97fc28..2feb813dac 100644 --- a/app/assets/javascripts/discourse/app/components/user-card-contents.js +++ b/app/assets/javascripts/discourse/app/components/user-card-contents.js @@ -38,7 +38,12 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, { showMoreBadges: gt("moreBadgesCount", 0), showDelete: and("viewingAdmin", "showName", "user.canBeDeleted"), linkWebsite: not("user.isBasic"), - hasLocationOrWebsite: or("user.location", "user.website_name"), + + @discourseComputed("user") + hasLocaleOrWebsite(user) { + return user.location || user.website_name || this.userTimezone; + }, + isSuspendedOrHasBio: or("user.suspend_reason", "user.bio_excerpt"), showCheckEmail: and("user.staged", "canCheckEmails"), @@ -52,6 +57,8 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, { "siteSettings.allow_featured_topic_on_user_profiles" ), + showUserLocalTime: setting("display_local_time_in_user_card"), + @discourseComputed("user.staff") staff: isStaff => (isStaff ? "staff" : ""), @@ -63,6 +70,17 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, { return prioritizeNameInUx(name, this.siteSettings); }, + @discourseComputed("user") + userTimezone(user) { + return user.resolvedTimezone(); + }, + + @discourseComputed() + formattedUserLocalTime() { + const timezone = this.userTimezone; + return moment.tz(timezone).format(I18n.t("dates.time_with_zone")); + }, + @discourseComputed("username") usernameClass: username => (username ? `user-card-${username}` : ""), diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js index 9fff14f4f8..dc118c0892 100644 --- a/app/assets/javascripts/discourse/app/models/user.js +++ b/app/assets/javascripts/discourse/app/models/user.js @@ -597,6 +597,11 @@ const User = RestModel.extend({ json.user.card_badge = Badge.create(json.user.card_badge); } + if (!json.user._timezone) { + json.user._timezone = json.user.timezone; + delete json.user.timezone; + } + user.setProperties(json.user); return user; }); diff --git a/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs b/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs index 3be60e856c..3148fc95d3 100644 --- a/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs @@ -149,15 +149,9 @@ {{/if}} - {{#if this.hasLocationOrWebsite}} + {{#if this.hasLocaleOrWebsite}}
- {{#if this.user.location}} - - {{d-icon "map-marker-alt"}} - {{this.user.location}} - - {{/if}} {{#if this.user.website_name}} {{d-icon "globe"}} @@ -170,6 +164,18 @@ {{/if}} {{/if}} + {{#if this.user.location}} + + {{d-icon "map-marker-alt"}} + {{this.user.location}} + + {{/if}} + {{#if showUserLocalTime}} + + {{d-icon "far-clock"}} + {{this.formattedUserLocalTime}} + + {{/if}} {{plugin-outlet name="user-card-location-and-website" args=(hash user=this.user)}}
diff --git a/app/assets/stylesheets/common/components/user-card.scss b/app/assets/stylesheets/common/components/user-card.scss index c5dad5d089..92ca3a5af0 100644 --- a/app/assets/stylesheets/common/components/user-card.scss +++ b/app/assets/stylesheets/common/components/user-card.scss @@ -212,7 +212,9 @@ $avatar_margin: -50px; // negative margin makes avatars extend above cards @include ellipsis; color: $primary; } - .location { + .location, + .local-time, + .website-name { margin-right: 0.5em; } .website-name a { diff --git a/app/serializers/user_card_serializer.rb b/app/serializers/user_card_serializer.rb index 6b7f59cd40..c453dff2e4 100644 --- a/app/serializers/user_card_serializer.rb +++ b/app/serializers/user_card_serializer.rb @@ -60,7 +60,8 @@ class UserCardSerializer < BasicUserSerializer :primary_group_flair_url, :primary_group_flair_bg_color, :primary_group_flair_color, - :featured_topic + :featured_topic, + :timezone untrusted_attributes :bio_excerpt, :website, @@ -194,6 +195,14 @@ class UserCardSerializer < BasicUserSerializer object.user_profile.featured_topic end + def include_timezone? + SiteSetting.display_local_time_in_user_card? + end + + def timezone + object.user_option.timezone + end + def card_background_upload_url object.card_background_upload&.url end diff --git a/config/locales/client.ar.yml b/config/locales/client.ar.yml index d2551f34b9..dd74199911 100644 --- a/config/locales/client.ar.yml +++ b/config/locales/client.ar.yml @@ -31,6 +31,7 @@ ar: millions: "{{number}} مليون" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" diff --git a/config/locales/client.be.yml b/config/locales/client.be.yml index c9c33e1117..67247aea1a 100644 --- a/config/locales/client.be.yml +++ b/config/locales/client.be.yml @@ -25,6 +25,7 @@ be: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" long_no_year_no_time: "D MMM" long_with_year_no_time: "D МММ, YYYY" long_date_with_year_without_time: "D MMM YYYY" diff --git a/config/locales/client.bg.yml b/config/locales/client.bg.yml index 298f6fc63d..addc3fdbac 100644 --- a/config/locales/client.bg.yml +++ b/config/locales/client.bg.yml @@ -27,6 +27,7 @@ bg: millions: "{{number}}M " dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" diff --git a/config/locales/client.bs_BA.yml b/config/locales/client.bs_BA.yml index e99e72dc0f..93e103c993 100644 --- a/config/locales/client.bs_BA.yml +++ b/config/locales/client.bs_BA.yml @@ -28,6 +28,7 @@ bs_BA: millions: "{{number}} miliona" dates: time: "HH: mm" + time_with_zone: "HH: mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.ca.yml b/config/locales/client.ca.yml index d3c05e308f..80f47fb2df 100644 --- a/config/locales/client.ca.yml +++ b/config/locales/client.ca.yml @@ -27,6 +27,7 @@ ca: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.cs.yml b/config/locales/client.cs.yml index 84c4b405fd..1faece6fa4 100644 --- a/config/locales/client.cs.yml +++ b/config/locales/client.cs.yml @@ -29,6 +29,7 @@ cs: millions: "{{number}}M" dates: time: "H:mm" + time_with_zone: "H:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "D. MMMM" full_no_year_no_time: "D. MMMM" diff --git a/config/locales/client.da.yml b/config/locales/client.da.yml index cfb52a677a..c75122c70b 100644 --- a/config/locales/client.da.yml +++ b/config/locales/client.da.yml @@ -27,6 +27,7 @@ da: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "D. MMM" full_no_year_no_time: "D. MMMM" diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml index 9cc356de43..64e90d534f 100644 --- a/config/locales/client.de.yml +++ b/config/locales/client.de.yml @@ -27,6 +27,7 @@ de: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "D. MMM" diff --git a/config/locales/client.el.yml b/config/locales/client.el.yml index 0dbe63981f..94d50da992 100644 --- a/config/locales/client.el.yml +++ b/config/locales/client.el.yml @@ -27,6 +27,7 @@ el: millions: "{{number}}εκατ." dates: time: "ΗΗ:mm" + time_with_zone: "HH:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "DD MMM" full_no_year_no_time: "Do MMMM" diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index af4c1549b1..3180d66d2f 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -40,6 +40,8 @@ en: # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/ time: "HH:mm" # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/ + time_with_zone: "HH:mm (z)" + # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/ time_short_day: "ddd, HH:mm" # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/ timeline_date: "MMM YYYY" diff --git a/config/locales/client.en_US.yml b/config/locales/client.en_US.yml index 96cf5c211d..889e8c66c9 100644 --- a/config/locales/client.en_US.yml +++ b/config/locales/client.en_US.yml @@ -4,6 +4,8 @@ en_US: # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/ time: "h:mm a" # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/ + time_with_zone: "hh:mm a (z)" + # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/ time_short_day: "ddd, h:mm a" # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/ timeline_date: "MMM YYYY" diff --git a/config/locales/client.es.yml b/config/locales/client.es.yml index f9649f5725..63ebcf23f5 100644 --- a/config/locales/client.es.yml +++ b/config/locales/client.es.yml @@ -27,6 +27,7 @@ es: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year: "D MMM, HH:mm" diff --git a/config/locales/client.et.yml b/config/locales/client.et.yml index 8c185b0f9d..cf67e2d4aa 100644 --- a/config/locales/client.et.yml +++ b/config/locales/client.et.yml @@ -27,6 +27,7 @@ et: millions: "{{number}}M" dates: time: "hh:mm" + time_with_zone: "hh:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "D. MMMM" full_no_year_no_time: "Do MMMM" diff --git a/config/locales/client.fa_IR.yml b/config/locales/client.fa_IR.yml index 57efc8e041..3e3d664341 100644 --- a/config/locales/client.fa_IR.yml +++ b/config/locales/client.fa_IR.yml @@ -27,6 +27,7 @@ fa_IR: millions: "{{number}} میلیون" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" diff --git a/config/locales/client.fi.yml b/config/locales/client.fi.yml index 0f5e360629..a66782aa50 100644 --- a/config/locales/client.fi.yml +++ b/config/locales/client.fi.yml @@ -27,6 +27,7 @@ fi: millions: "{{number}}M" dates: time: "H:mm" + time_with_zone: "H:mm (z)" time_short_day: "ddd HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "D. MMMM[ta]" diff --git a/config/locales/client.fr.yml b/config/locales/client.fr.yml index db522c2b26..2a764de244 100644 --- a/config/locales/client.fr.yml +++ b/config/locales/client.fr.yml @@ -27,6 +27,7 @@ fr: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd [à] HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" diff --git a/config/locales/client.gl.yml b/config/locales/client.gl.yml index 1e6bb87c66..8a8624aba3 100644 --- a/config/locales/client.gl.yml +++ b/config/locales/client.gl.yml @@ -27,6 +27,7 @@ gl: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" full_no_year_no_time: "D MMMM" diff --git a/config/locales/client.he.yml b/config/locales/client.he.yml index 450b1167ea..cd388cc382 100644 --- a/config/locales/client.he.yml +++ b/config/locales/client.he.yml @@ -29,6 +29,7 @@ he: millions: "{{number}} מיליון" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year: "D MMM, HH:mm" diff --git a/config/locales/client.hu.yml b/config/locales/client.hu.yml index f843aad5c8..6500e02233 100644 --- a/config/locales/client.hu.yml +++ b/config/locales/client.hu.yml @@ -27,6 +27,7 @@ hu: millions: "{{number}} millió" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" timeline_date: "YYYY MMMM" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMM DD" diff --git a/config/locales/client.hy.yml b/config/locales/client.hy.yml index b446663a91..b5e6fa470c 100644 --- a/config/locales/client.hy.yml +++ b/config/locales/client.hy.yml @@ -27,6 +27,7 @@ hy: millions: "{{number}}մլն" dates: time: "h:mm" + time_with_zone: "h:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.id.yml b/config/locales/client.id.yml index 410f902df7..21b6f48c6e 100644 --- a/config/locales/client.id.yml +++ b/config/locales/client.id.yml @@ -26,6 +26,7 @@ id: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" time_short_day: "ddd, HH: mm" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" diff --git a/config/locales/client.it.yml b/config/locales/client.it.yml index ac69f908f3..b3232e2d8c 100644 --- a/config/locales/client.it.yml +++ b/config/locales/client.it.yml @@ -27,6 +27,7 @@ it: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year: "D MMM, HH:mm" diff --git a/config/locales/client.ja.yml b/config/locales/client.ja.yml index 59291ac65d..4fb8795c6b 100644 --- a/config/locales/client.ja.yml +++ b/config/locales/client.ja.yml @@ -26,6 +26,7 @@ ja: millions: "{{number}}M" dates: time: "H:mm" + time_with_zone: "H:mm (z)" timeline_date: "YYYY年M月" long_no_year_no_time: "M月D日" full_no_year_no_time: "M月D日" diff --git a/config/locales/client.ko.yml b/config/locales/client.ko.yml index 9e2ede793b..22cdf967c5 100644 --- a/config/locales/client.ko.yml +++ b/config/locales/client.ko.yml @@ -26,6 +26,7 @@ ko: millions: "{{number}}백만" dates: time: "a h:mm" + time_with_zone: "a h:mm (z)" timeline_date: "YYYY MMM" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.lt.yml b/config/locales/client.lt.yml index fc7f0bc130..c04e5b9d4e 100644 --- a/config/locales/client.lt.yml +++ b/config/locales/client.lt.yml @@ -29,6 +29,7 @@ lt: millions: "{{number}}M" dates: time: "H:mm" + time_with_zone: "H:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.lv.yml b/config/locales/client.lv.yml index 2552f541c3..5e021880d6 100644 --- a/config/locales/client.lv.yml +++ b/config/locales/client.lv.yml @@ -28,6 +28,7 @@ lv: millions: "{{number}} milj." dates: time: "hh:mm" + time_with_zone: "hh:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.nb_NO.yml b/config/locales/client.nb_NO.yml index 62b0e76a05..9782c2233e 100644 --- a/config/locales/client.nb_NO.yml +++ b/config/locales/client.nb_NO.yml @@ -27,6 +27,7 @@ nb_NO: millions: "{{number}}M" dates: time: "LT" + time_with_zone: "LT (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" full_no_year_no_time: "D. MMMM" diff --git a/config/locales/client.nl.yml b/config/locales/client.nl.yml index 27240c9afc..e69cca0469 100644 --- a/config/locales/client.nl.yml +++ b/config/locales/client.nl.yml @@ -27,6 +27,7 @@ nl: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year: "D MMM, HH:mm" diff --git a/config/locales/client.pl_PL.yml b/config/locales/client.pl_PL.yml index f558984e7a..2db63526d8 100644 --- a/config/locales/client.pl_PL.yml +++ b/config/locales/client.pl_PL.yml @@ -29,6 +29,7 @@ pl_PL: millions: "{{number}}M" dates: time: "H:mm" + time_with_zone: "H:mm (z)" time_short_day: "ddd, GG: mm" timeline_date: "MMM YYYY" long_no_year: "D MMM, GG: mm" diff --git a/config/locales/client.pt.yml b/config/locales/client.pt.yml index 29bedc2d68..67fcbe27a9 100644 --- a/config/locales/client.pt.yml +++ b/config/locales/client.pt.yml @@ -27,6 +27,7 @@ pt: millions: "{{number}}M" dates: time: "hh:mm" + time_with_zone: "hh:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "DD MMM" full_no_year_no_time: "Do MMMM" diff --git a/config/locales/client.pt_BR.yml b/config/locales/client.pt_BR.yml index d95190318d..bf673507c1 100644 --- a/config/locales/client.pt_BR.yml +++ b/config/locales/client.pt_BR.yml @@ -27,6 +27,7 @@ pt_BR: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" diff --git a/config/locales/client.ro.yml b/config/locales/client.ro.yml index a26fed9e10..51d21ec82b 100644 --- a/config/locales/client.ro.yml +++ b/config/locales/client.ro.yml @@ -28,6 +28,7 @@ ro: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "DD MMM" full_no_year_no_time: "Do MMMM " diff --git a/config/locales/client.ru.yml b/config/locales/client.ru.yml index 20eac7a0e7..540448bc35 100644 --- a/config/locales/client.ru.yml +++ b/config/locales/client.ru.yml @@ -29,6 +29,7 @@ ru: millions: "{{number}} млн." dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year: "D MMM, HH:mm" diff --git a/config/locales/client.sk.yml b/config/locales/client.sk.yml index 4c9a45d361..2fec5c9696 100644 --- a/config/locales/client.sk.yml +++ b/config/locales/client.sk.yml @@ -29,6 +29,7 @@ sk: millions: "{{number}}mil" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.sl.yml b/config/locales/client.sl.yml index 2cd21fe199..4f707df6d0 100644 --- a/config/locales/client.sl.yml +++ b/config/locales/client.sl.yml @@ -29,6 +29,7 @@ sl: millions: "{{number}}M" dates: time: "H:mm" + time_with_zone: "H:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" full_no_year_no_time: "D. MMMM" diff --git a/config/locales/client.sq.yml b/config/locales/client.sq.yml index 71a48fb415..f4e4997c20 100644 --- a/config/locales/client.sq.yml +++ b/config/locales/client.sq.yml @@ -27,6 +27,7 @@ sq: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.sr.yml b/config/locales/client.sr.yml index c5dc6248f4..ddf56cf62c 100644 --- a/config/locales/client.sr.yml +++ b/config/locales/client.sr.yml @@ -28,6 +28,7 @@ sr: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.sv.yml b/config/locales/client.sv.yml index 0b8e573f90..0a5078294b 100644 --- a/config/locales/client.sv.yml +++ b/config/locales/client.sv.yml @@ -27,6 +27,7 @@ sv: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year: "D MMM, HH:mm" diff --git a/config/locales/client.sw.yml b/config/locales/client.sw.yml index 0279890254..3bab45669c 100644 --- a/config/locales/client.sw.yml +++ b/config/locales/client.sw.yml @@ -27,6 +27,7 @@ sw: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.te.yml b/config/locales/client.te.yml index ff17c45be2..a6e245faf5 100644 --- a/config/locales/client.te.yml +++ b/config/locales/client.te.yml @@ -24,6 +24,7 @@ te: tb: టీబీ dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" long_no_year_no_time: "MMM D" long_with_year: "MMM D, YYYY h:mm a" long_with_year_no_time: "MMM D, YYYY" diff --git a/config/locales/client.th.yml b/config/locales/client.th.yml index 273bcc27c8..a9c73f525d 100644 --- a/config/locales/client.th.yml +++ b/config/locales/client.th.yml @@ -26,6 +26,7 @@ th: millions: "{{number}}ล้าน" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.tr_TR.yml b/config/locales/client.tr_TR.yml index e0554c02f3..066a38b339 100644 --- a/config/locales/client.tr_TR.yml +++ b/config/locales/client.tr_TR.yml @@ -27,6 +27,7 @@ tr_TR: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" time_short_day: "ggg, SS:dd" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" diff --git a/config/locales/client.uk.yml b/config/locales/client.uk.yml index 10fdd74b48..6930870cf4 100644 --- a/config/locales/client.uk.yml +++ b/config/locales/client.uk.yml @@ -29,6 +29,7 @@ uk: millions: "{{number}} млн." dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" diff --git a/config/locales/client.ur.yml b/config/locales/client.ur.yml index b99357bb5a..fe817015db 100644 --- a/config/locales/client.ur.yml +++ b/config/locales/client.ur.yml @@ -27,6 +27,7 @@ ur: millions: "{{number}}M" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" timeline_date: "MMM YYYY" long_no_year_no_time: "MMM D" full_no_year_no_time: "MMMM Do" diff --git a/config/locales/client.vi.yml b/config/locales/client.vi.yml index 616c335137..7ddbc48055 100644 --- a/config/locales/client.vi.yml +++ b/config/locales/client.vi.yml @@ -26,6 +26,7 @@ vi: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "MMM YYYY" long_no_year_no_time: "D MMM" diff --git a/config/locales/client.zh_CN.yml b/config/locales/client.zh_CN.yml index 6a301be078..b54822a862 100644 --- a/config/locales/client.zh_CN.yml +++ b/config/locales/client.zh_CN.yml @@ -26,6 +26,7 @@ zh_CN: millions: "{{number}}M" dates: time: "HH:mm" + time_with_zone: "HH:mm (z)" time_short_day: "ddd, HH:mm" timeline_date: "YYYY[年]M[月]" long_no_year: "M[月]D[日] HH:mm" diff --git a/config/locales/client.zh_TW.yml b/config/locales/client.zh_TW.yml index bb5ef5ed45..1d5b3ce010 100644 --- a/config/locales/client.zh_TW.yml +++ b/config/locales/client.zh_TW.yml @@ -26,6 +26,7 @@ zh_TW: millions: "{{number}} 百萬" dates: time: "h:mm a" + time_with_zone: "h:mm a (z)" timeline_date: "YYYY年 M月" long_no_year_no_time: "M月 D日" full_no_year_no_time: "M月 D日" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index d38b0caeab..baf137f94b 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1407,6 +1407,7 @@ en: watched_word_regexp_error: "The regular expression for %{action} watched words is invalid. Please check your Watched Word settings, or disable the 'watched words regular expressions' site setting." site_settings: + display_local_time_in_user_card: "Display the local time based on a user's timezone when their user card is opened." censored_words: "Words that will be automatically replaced with ■■■■" delete_old_hidden_posts: "Auto-delete any hidden posts that stay hidden for more than 30 days." default_locale: "The default language of this Discourse instance. You can replace the text of system generated categories and topics at Customize / Text." diff --git a/config/site_settings.yml b/config/site_settings.yml index 8037237c2a..7d9fd0fd86 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -124,6 +124,9 @@ branding: default: "" basic: + display_local_time_in_user_card: + client: true + default: false allow_user_locale: client: true default: false diff --git a/test/javascripts/acceptance/user-card-test.js b/test/javascripts/acceptance/user-card-test.js index 8ced970f99..ecf9870612 100644 --- a/test/javascripts/acceptance/user-card-test.js +++ b/test/javascripts/acceptance/user-card-test.js @@ -1,6 +1,46 @@ import { acceptance } from "helpers/qunit-helpers"; import DiscourseURL from "discourse/lib/url"; +import pretender from "helpers/create-pretender"; +import userFixtures from "fixtures/user_fixtures"; +import User from "discourse/models/user"; + +acceptance("User Card - Show Local Time", { + loggedIn: true, + settings: { display_local_time_in_user_card: true } +}); + +QUnit.test("user card local time", async assert => { + User.current().changeTimezone("Australia/Brisbane"); + let cardResponse = _.clone(userFixtures["/u/eviltrout/card.json"]); + cardResponse.user.timezone = "Australia/Perth"; + + pretender.get("/u/eviltrout/card.json", () => [ + 200, + { "Content-Type": "application/json" }, + cardResponse + ]); + + await visit("/t/internationalization-localization/280"); + assert.ok(invisible(".user-card"), "user card is invisible by default"); + await click("a[data-user-card=eviltrout]:first"); + + let expectedTime = + moment + .tz("Australia/Brisbane") + .add(-2, "hours") + .format("hh:mm a") + " (AWST)"; + + assert.ok(visible(".user-card"), "card should appear"); + assert.equal( + find(".user-card .local-time") + .text() + .trim(), + expectedTime, + "user card contains the user's local time" + ); +}); + acceptance("User Card", { loggedIn: true }); QUnit.test("user card", async assert => { @@ -34,6 +74,11 @@ QUnit.test("user card", async assert => { "user card contains the data" ); + assert.ok( + !visible(".user-card .local-time"), + "local time with zone does not show by default" + ); + await click(".card-content .compose-pm button"); assert.ok( invisible(".user-card"),