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

Dynamically augment availableFormats #462

Closed
wants to merge 3 commits into from

Conversation

vectart
Copy link

@vectart vectart commented Jul 15, 2015

fixes #271

Dynamically augment availableFormats

Fixes globalizejs#271
@rxaviers
Copy link
Member

Awesome! All I see for now are some style issues, which I'm going to comment inline.

@@ -7,3 +7,4 @@ before_install:
install:
- npm install
- bower install
sudo: false
Copy link
Member

Choose a reason for hiding this comment

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

cc @jzaefferer @scottgonzalez to comment on that

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as its in a separate commit. Should also enable caching, see, for example, qunitjs/qunit#835

Copy link
Member

Choose a reason for hiding this comment

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

@vectart please could you include this? ☝️

@@ -38,6 +39,89 @@ return function( options, cldr ) {
);
}

function getBestMatchPattern( path, skeleton ) {
var availableFormats, ratedFormats, format;
Copy link
Member

Choose a reason for hiding this comment

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

I assume you want to define pattern as a variable local to this function, so it's not mixed up with pattern defined by the parent function.

@rxaviers
Copy link
Member

@vectart I left a couple of comments, please just let me know on any questions and thanks so far.

@vectart
Copy link
Author

vectart commented Jul 15, 2015

@rxaviers Thanks for the useful comments, I've updated PR according to them

@rxaviers
Copy link
Member

Please, could you rebase on master (git rebase master)? I've updated jscs and it will help us to find the coding style issues.

maxLength = Math.max( formatA.length, formatB.length );
minLength = Math.min( formatA.length, formatB.length );

for ( index = 0; index < minLength; index++ ) {
Copy link
Member

Choose a reason for hiding this comment

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

It's ok using i instead of index here. :)

@rxaviers
Copy link
Member

Interestingly, the augmentation for Globalize("en").formatDate(new Date(), {skeleton: "hhmm"}) worked just fine: '12:34 AM'. Although, it didn't work for Globalize("en").formatDate(new Date(), {skeleton: "HHmm"}): '0033' ('00:33'' expected). Please, could you check and also add this as a new test case?

@rxaviers
Copy link
Member

Another worth doing test is checking against ICU... One difference I found is: EHmss gives 'Wed, 20:38:05' opposed to Wed 20:38:05 on ICU (http://demo.icu-project.org/icu4jweb/flexTest.jsp?pat=EHmss&_=en_US). The first one seems to have chosen by E alone and ms alone, then augmented ms into mss, then glued them. The second one seems to have chosen EHms, then augmented it into EHmss.

timeSkeleton = getBestMatchPattern(
"dates/calendars/gregorian/dateTimeFormats/availableFormats",
timeSkeleton
);
Copy link
Member

Choose a reason for hiding this comment

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

You might need use getBestMatchPattern() for each date and time before the type assignment above. For example, MMMMh should give July, 8 PM (type medium) instead of July at 8 PM (type long). Because, "MMMM" will be converted into "LLLL".

@rxaviers
Copy link
Member

@vectart just let me know when you have progress, so we can land this fix. Thanks for your great work so far.

Strate added a commit to megaplan/globalize that referenced this pull request Mar 22, 2016
Strate added a commit to megaplan/globalize that referenced this pull request Mar 22, 2016
@Strate
Copy link
Contributor

Strate commented Apr 1, 2016

How about to use builtin new Intl.DateTimeFormatter().resolved.pattern to get best-fit pattern?

rxaviers added a commit to rxaviers/globalize that referenced this pull request Mar 14, 2017
rxaviers added a commit to rxaviers/globalize that referenced this pull request Mar 14, 2017
rxaviers added a commit to rxaviers/globalize that referenced this pull request Mar 14, 2017
rxaviers added a commit to rxaviers/globalize that referenced this pull request Mar 17, 2017
@rxaviers rxaviers added this to the 1.3.0 milestone Mar 17, 2017
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.

Date (skeletons): dynamically augment availableFormats
6 participants