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
}.slice(*attrs)
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
......@@ -73,6 +73,10 @@
= sprite_icon('location', css_class: 'fgray')
%span{ itemprop: 'addressLocality' }
= @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?
.profile-link-holder.middle-dot-divider-sm.d-block.d-sm-inline
= sprite_icon('work', css_class: 'fgray')
......
......@@ -44,15 +44,17 @@ gitlab-ctl restart
## 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).
1. Enable the feature flag:
This setting controls the local time displayed on a user's profile.
See [&280](https://gitlab.com/groups/gitlab-org/-/epics/280) for other planned features.
```ruby
Feature.enable(:user_time_settings)
```
NOTE:
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
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
let_it_be(:followee) { create(:user) }
let_it_be(:follower) { create(:user) }
......
......@@ -68,4 +68,24 @@ RSpec.describe TimeZoneHelper, :aggregate_failures do
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
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