Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to change time formats (12/24-hour clock) #9093

Merged
merged 10 commits into from Oct 29, 2015
Merged

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Oct 25, 2015

Add possibility to change time formats in user settings.

Besides the language it's now possible to choose the time format:

image

That will make 12- and 24-hour time formats available for all languages.

24-hour clock format will always be the default for every user.

fixes #9082

@sgiehl sgiehl added Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. c: i18n For issues around internationalisation and localisation. labels Oct 25, 2015
@sgiehl sgiehl self-assigned this Oct 25, 2015
@sgiehl sgiehl added this to the 2.15.1 milestone Oct 25, 2015
@sgiehl sgiehl removed the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label Oct 25, 2015
@sgiehl sgiehl removed their assignment Oct 25, 2015
protected function getTimeFormat()
{
if (is_null(self::$use12HourClock)) {
self::$use12HourClock = LanguagesManager::uses12HourClockForCurrentUser();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, core would not know about anything implemented by plugins and not access any code from plugins directly. I know it's sometimes not really possible though or it is possible but doesn't make it much better. @diosmosis should we maybe use DI in such a case? Like by default core would always return true for date.uses12HourClockForCurrentUser DI setting (global.php) and LanguagesManager plugin would overwrite it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using DI to store setting info, since settings can change in the middle of a request while DI is meant to be static for the whole request. Ie, if we change this setting in the middle of a request, there's no way to re-inject the objects that have already been created.

Instead, what I'd do is:

  1. Create a DateTimeFormatProvider service class in core to return individual formats. This class would provide default translations w/o going through the translator.
  2. Create a new DateTimeFormatProvider in the Intl/LanguagesManager plugin (whichever provides the best behavior when one of the plugins is not loaded) which uses the Translator to provide the formats.
  3. Override the DateTimeFormatProvider key in the plugin's config.php to use the plugin's DateTimeFormatProvider.
  4. Use the DateTimeFormatProvider here.

I'd probably also move the date/time formatting to MetricsFormatter (& move MetricsFormatter to DI as well), however that's not really required at the moment. And I'll have to do something like that to get rid of StaticContainer eventually, anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I don't think it would be a problem here if it changes during the request but for some things it can be a problem for sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to implement something similar now (see db969cd), feels better that way :)

@sgiehl
Copy link
Member Author

sgiehl commented Oct 28, 2015

Ready for another review. I've changed the mentioned stuff...

@diosmosis
Copy link
Member

DI related code looks ok to me

@tsteur
Copy link
Member

tsteur commented Oct 29, 2015

👍

mattab pushed a commit that referenced this pull request Oct 29, 2015
Allow user to change time formats (12/24-hour clock)
@mattab mattab merged commit fe36f93 into master Oct 29, 2015
@mattab mattab deleted the timeformats branch October 29, 2015 23:42
@mattab
Copy link
Member

mattab commented Oct 29, 2015

👍

mattab added a commit that referenced this pull request Oct 30, 2015
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Oct 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. c: i18n For issues around internationalisation and localisation. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants