Commit 2d0aaadd authored by Peter Hegman's avatar Peter Hegman Committed by Brandon Labuschagne

Display local time in user's profile

parent 4ad862fa
...@@ -31,4 +31,9 @@ module TimeZoneHelper ...@@ -31,4 +31,9 @@ module TimeZoneHelper
}.slice(*attrs) }.slice(*attrs)
end end
end end
def local_time(timezone)
time_zone_instance = ActiveSupport::TimeZone.new(timezone) || Time.zone
time_zone_instance.now.strftime("%-l:%M %p")
end
end end
...@@ -73,6 +73,10 @@ ...@@ -73,6 +73,10 @@
= sprite_icon('location', css_class: 'fgray') = sprite_icon('location', css_class: 'fgray')
%span{ itemprop: 'addressLocality' } %span{ itemprop: 'addressLocality' }
= @user.location = @user.location
.profile-link-holder.middle-dot-divider-sm.d-block.d-sm-inline.mb-1.mb-sm-0
= sprite_icon('clock', css_class: 'fgray')
%span
= local_time(@user.timezone)
- unless work_information(@user).blank? - unless work_information(@user).blank?
.profile-link-holder.middle-dot-divider-sm.d-block.d-sm-inline .profile-link-holder.middle-dot-divider-sm.d-block.d-sm-inline
= sprite_icon('work', css_class: 'fgray') = sprite_icon('work', css_class: 'fgray')
......
...@@ -44,15 +44,17 @@ gitlab-ctl restart ...@@ -44,15 +44,17 @@ gitlab-ctl restart
## Changing time zone per user ## Changing time zone per user
To allow users to change the time zone in their profile, the feature flag `user_time_settings` should be enabled: > - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/57654) in GitLab 11.11, disabled by default behind `user_time_settings` [feature flag](feature_flags.md).
> - [Enabled by default](https://gitlab.com/gitlab-org/gitlab/-/issues/29669) in GitLab 13.9.
> - [Feature flag removed](https://gitlab.com/gitlab-org/gitlab/-/issues/29669) in GitLab 14.1.
1. [Start a Rails console session](operations/rails_console.md). This setting controls the local time displayed on a user's profile.
1. Enable the feature flag: See [&280](https://gitlab.com/groups/gitlab-org/-/epics/280) for other planned features.
```ruby NOTE:
Feature.enable(:user_time_settings) If a user has not set their time zone, it defaults to the time zone [configured at the instance level](#changing-your-time-zone). On GitLab.com, the default time zone is UTC.
```
1. You should now be able to see the timezone dropdown in the users' **Settings > Profile** page. 1. Navigate to [your user settings](../user/profile/index.md#access-your-user-settings).
1. Select your time zone from the dropdown.
![User Time Zone Settings](img/time_zone_settings.png) ![User Time Zone Settings](img/time_zone_settings.png)
...@@ -57,6 +57,56 @@ RSpec.describe 'User page' do ...@@ -57,6 +57,56 @@ RSpec.describe 'User page' do
end end
end end
context 'location' do
let_it_be(:location) { 'San Francisco, CA' }
context 'when location is set' do
let_it_be(:user) { create(:user, location: location) }
it 'shows location' do
subject
expect(page).to have_content(location)
end
end
context 'when location is not set' do
it 'does not show location' do
subject
expect(page).not_to have_content(location)
end
end
end
context 'timezone' do
let_it_be(:timezone) { 'America/Los_Angeles' }
before do
travel_to Time.find_zone(timezone).local(2021, 7, 20, 15, 30, 45)
end
context 'when timezone is set' do
let_it_be(:user) { create(:user, timezone: timezone) }
it 'shows local time' do
subject
expect(page).to have_content('3:30 PM')
end
end
context 'when timezone is invalid' do
let_it_be(:user) { create(:user, timezone: 'Foo/Bar') }
it 'shows local time using the configured default timezone (UTC in this case)' do
subject
expect(page).to have_content('10:30 PM')
end
end
end
context 'follow/unfollow and followers/following' do context 'follow/unfollow and followers/following' do
let_it_be(:followee) { create(:user) } let_it_be(:followee) { create(:user) }
let_it_be(:follower) { create(:user) } let_it_be(:follower) { create(:user) }
......
...@@ -68,4 +68,24 @@ RSpec.describe TimeZoneHelper, :aggregate_failures do ...@@ -68,4 +68,24 @@ RSpec.describe TimeZoneHelper, :aggregate_failures do
end end
end end
end end
describe '#local_time' do
let_it_be(:timezone) { 'America/Los_Angeles' }
before do
travel_to Time.find_zone(timezone).local(2021, 7, 20, 15, 30, 45)
end
context 'when a valid timezone is passed' do
it 'returns local time' do
expect(helper.local_time(timezone)).to eq('3:30 PM')
end
end
context 'when an invalid timezone is passed' do
it 'returns local time using the configured default timezone (UTC in this case)' do
expect(helper.local_time('Foo/Bar')).to eq('10:30 PM')
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment