Skip to content

Feature/internationalize date formatting of charts #3381

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

Merged

Conversation

deligence-dharmendra
Copy link
Contributor

@deligence-dharmendra deligence-dharmendra commented Feb 5, 2018

Closes #2900

Changes

  • change in format date helper file
  • add getLocaleDateFormat method

Developer checklist

This checklist is to be completed by the PR developer:

  • Alternative solutions were compared/discussed before writing code
    • trade-offs with this solution are considered acceptable
  • Code in this PR adheres to the project styleguide
  • This pull request does not decrease project test coverage
  • If the code changes existing database collection(s), migration has been written
  • If UI texts are added or changed, all texts are internationalized

Reviewer checklist

Reviewed by: @marla-singer @matleppa

This list is to be completed by the pull request reviewer:

  • Code works as described/expected
  • Code seems to be error free
    • no browser console errors visible
    • no server console errors visible
    • passes CI build
  • Code is written in a way that promotes maintainability
    • easy to understand
    • well organized
    • follows project coding standards and conventions
    • well documented

@@ -69,7 +72,7 @@ Template.medianResponseTime.onRendered(function () {

// Get dates
const labels = chartData.map(dataset => {
return moment(dataset.date).format('MM/DD');
return moment(dataset.date).format(getLocaleDateFormat());
Copy link
Contributor

Choose a reason for hiding this comment

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

Not good enough. Get the locale format outside of loop

@@ -94,7 +97,7 @@ Template.requestTimeline.onRendered(function () {

// Initialization
const labels = selectedPathData.dates.map(date => {
return moment(date).format('MM/DD');
return moment(date).format(getLocaleDateFormat());
Copy link
Contributor

Choose a reason for hiding this comment

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

Get the locale format outside of loop

@@ -69,7 +72,7 @@ Template.requestsOverTime.onRendered(function () {

// Get dates
const labels = chartData.map(dataset => {
return moment(dataset.date).format('MM/DD');
return moment(dataset.date).format(getLocaleDateFormat());
Copy link
Contributor

Choose a reason for hiding this comment

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

Get the locale format outside of loop

@@ -89,7 +92,7 @@ Template.responseTimeTimeline.onRendered(function () {

// Create labels value
const labels = selectedPathData.dates.map(date => {
return moment(date).format('MM/DD');
return moment(date).format(getLocaleDateFormat());
Copy link
Contributor

Choose a reason for hiding this comment

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

Get the locale format outside of loop

@@ -69,7 +72,7 @@ Template.uniqueUsersOverTime.onRendered(function () {

// Get dates
const labels = chartData.map(dataset => {
return moment(dataset.date).format('MM/DD');
return moment(dataset.date).format(getLocaleDateFormat());
Copy link
Contributor

Choose a reason for hiding this comment

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

Get the locale format outside of loop

Copy link
Contributor

@marla-singer marla-singer left a comment

Choose a reason for hiding this comment

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

One remarks


export function getLocaleDateFormat () {
// Get locale
const locale = window.navigator.userLanguage || window.navigator.language;
Copy link
Contributor

Choose a reason for hiding this comment

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

Using another command to cover all user's preferred language:

const locale = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage)

Copy link
Contributor

Choose a reason for hiding this comment

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

And please squash all commits to one

@ghost ghost added the in progress label Feb 8, 2018
@deligence-dharmendra deligence-dharmendra force-pushed the feature/internationalize-date-formatting-of-charts branch from 27255d8 to dedaf46 Compare February 8, 2018 05:44
Copy link
Member

@matleppa matleppa left a comment

Choose a reason for hiding this comment

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

One change in date.

let format = localeData.longDateFormat('L');

// Remove year part
format = format.replace(/.YYYY/, '');
Copy link
Member

Choose a reason for hiding this comment

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

Remove only the year, not the dot before year.

Copy link
Contributor

Choose a reason for hiding this comment

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

@matleppa For what? The label looks "07.02" and I don't understand why do we need save the last dot?

Copy link
Member

@matleppa matleppa Feb 8, 2018

Choose a reason for hiding this comment

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

The label should look "07.02.", because the last dot is part of the date in this form.

Copy link
Contributor

@marla-singer marla-singer Feb 8, 2018

Choose a reason for hiding this comment

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

Can't agree with you 👀 let's ask other devs about this?

Copy link
Contributor

@marla-singer marla-singer Feb 8, 2018

Choose a reason for hiding this comment

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

Honestly, I don't know about Finnish date format, but for me the last dot looks sooo strange in the Date

Current realization

joxi_screenshot_1518080387310

Your suggestions

joxi_screenshot_1518080422318

Copy link
Contributor

@preriasusi preriasusi Feb 14, 2018

Choose a reason for hiding this comment

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

Keep the dot. In Finnish last dot is an indicator of the date. There's now dates without a fot after the month. "14.2." is a date in Finnish. "14.2" is not a date in Finnish.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@preriasusi, That means we go with keep the dot with finish date.

Copy link
Contributor

Choose a reason for hiding this comment

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

First if you get a date format from a i18n component/library, it is not a good ide ato start clipping it. And also very bad idea to do now some logic according to the language. Isn't there a format for the date without a year that you could use without doing any mods on it?

Copy link
Contributor

Choose a reason for hiding this comment

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

@preriasusi Nope. We use moment.js and it doesn't provide locale date w/out year

Copy link
Contributor

Choose a reason for hiding this comment

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

@marla-singer Ok, it seems that it doesn't. So, ok stripping the year away is in this case accettable. But touching the dot in Finnish date is very, very wrong thing to do.

@marla-singer
Copy link
Contributor

@matleppa Add case for Finnish locale. Please check and let's merge it

Copy link
Member

@matleppa matleppa left a comment

Choose a reason for hiding this comment

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

Change in comparison.

let format = localeData.longDateFormat('L');

// Remove year part
format = format.replace(/.YYYY/, '');
if (locale === 'fi') {
Copy link
Member

@matleppa matleppa Mar 16, 2018

Choose a reason for hiding this comment

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

Seems not to work.
Should the comparison be
locale === 'fi-FI'
Or use regex to find 'fi'

Copy link
Contributor

Choose a reason for hiding this comment

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

I remade it by using regex. Please check again. If everything is fine then not merge it yet, I wanna do rebase

Copy link
Member

@matleppa matleppa left a comment

Choose a reason for hiding this comment

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

Unfortunately still some problem.
Does not fill the charts and
gives lots of exceptions about regex.text.

Exception from Tracker afterFlush function:
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 TypeError: regex.text is not a function
at getLocaleDateFormat (format_date.js:41)
at Blaze.View. (requests_over_time.js:74)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1934
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1932
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at viewAutorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1931)
at Tracker.Computation._compute (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:339)
at new Tracker.Computation (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:229)
at Object.Tracker.autorun (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:613)
at Blaze.View.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1944)
at Blaze.TemplateInstance.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3604)
at Blaze.TemplateInstance. (requests_over_time.js:69)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3398
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at fireCallbacks (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3394)
at Blaze.View. (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3487)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1845
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1844
at Object.Tracker._runFlush (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:548)
at onGlobalMessage (meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:398)
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 Exception from Tracker afterFlush function:
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 TypeError: regex.text is not a function
at getLocaleDateFormat (format_date.js:41)
at Blaze.View. (median_response_time.js:74)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1934
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1932
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at viewAutorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1931)
at Tracker.Computation._compute (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:339)
at new Tracker.Computation (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:229)
at Object.Tracker.autorun (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:613)
at Blaze.View.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1944)
at Blaze.TemplateInstance.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3604)
at Blaze.TemplateInstance. (median_response_time.js:69)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3398
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at fireCallbacks (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3394)
at Blaze.View. (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3487)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1845
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1844
at Object.Tracker._runFlush (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:548)
at onGlobalMessage (meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:398)
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 Exception from Tracker afterFlush function:
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 TypeError: regex.text is not a function
at getLocaleDateFormat (format_date.js:41)
at Blaze.View. (unique_users.js:74)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1934
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1932
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at viewAutorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1931)
at Tracker.Computation._compute (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:339)
at new Tracker.Computation (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:229)
at Object.Tracker.autorun (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:613)
at Blaze.View.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1944)
at Blaze.TemplateInstance.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3604)
at Blaze.TemplateInstance. (unique_users.js:69)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3398
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at fireCallbacks (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3394)
at Blaze.View. (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3487)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1845
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1844
at Object.Tracker._runFlush (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:548)
at onGlobalMessage (meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:398)

- Create an additional case fo Finnish locale. Using regex because different browsers handle it different way
@marla-singer marla-singer force-pushed the feature/internationalize-date-formatting-of-charts branch from d431611 to 72140a7 Compare March 22, 2018 08:14
@marla-singer
Copy link
Contributor

@matleppa Please check again

Copy link
Member

@matleppa matleppa left a comment

Choose a reason for hiding this comment

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

Works as expected.

@matleppa matleppa merged commit b784fb0 into develop Mar 22, 2018
@ghost ghost removed the in progress label Mar 22, 2018
@preriasusi preriasusi deleted the feature/internationalize-date-formatting-of-charts branch August 29, 2018 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants