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

Fixed issue 272 Handle DateTime in same skeleton. #426

Closed

Conversation

manrajgrover
Copy link
Contributor

@rxaviers sir,

Please review the code for issue #272 . I have tested it by making changes in date.js but not in expand-pattern.js . Please let me know the changes.

result = cldr.main([
"dates/calendars/gregorian/dateTimeFormats/availableFormats",
pattern.skeleton
]);
Copy link
Member

Choose a reason for hiding this comment

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

and if the availableFormats data does not include a dateFormatItem whose skeleton matches the same set of fields

First, check for availableFormats. Therefore, keep the above. If result === undefined, keep going...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rxaviers sir,

Sir here it is throwing error E_MISSING_CLDR error from cldr.main itself and not returning undefined for skeletons containing both date and time part. Hence we first have to check if skeleton entered has dateSkeleton or timeSkeleton or both before getting result. I am attaching a screenshot that will explain better.
untitled213

Copy link
Member

Choose a reason for hiding this comment

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

Hence we first have to check if skeleton entered has dateSkeleton or timeSkeleton or both before getting result. I am attaching a screenshot that will explain better.

Nope. There may be skeletons containing both date and time parts. So, we need to follow what's in the specification, which says "if the availableFormats data does not include a dateFormatItem whose skeleton matches the same set of fields" that we should look for date and time separately.

We need to find a way to technically do that. cldr.main itself doesn't throw E_MISSING_CLDR error. The error is thrown by our validation. We could skip that path from the validation. See https://github.com/jquery/globalize/blob/master/src/date.js#L63.

Copy link
Member

Choose a reason for hiding this comment

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

For example, otherwise you wouldn't get EHms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rxaviers sir,

There may be skeletons containing both date and time parts. So, we need to follow what's in the specification, which says "if the availableFormats data does not include a dateFormatItem whose skeleton matches the same set of fields" that we should look for date and time separately.

Yeah. Some cases will get missed through this method.

We could skip that path from the validation. See https://github.com/jquery/globalize/blob/master/src/date.js#L63.

By skipping the path you mean adding the path for availableFormats here?
https://github.com/jquery/globalize/blob/master/src/date.js#L29

Copy link
Member

Choose a reason for hiding this comment

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

By skipping the path you mean adding the path for availableFormats here?
https://github.com/jquery/globalize/blob/master/src/date.js#L29

Correct.

@rxaviers
Copy link
Member

Below is what needs to be done: (from the spec)

If a client-requested set of fields includes both date and time fields, and if the availableFormats data does not include a dateFormatItem whose skeleton matches the same set of fields, then the request should be handled as follows:

  1. Divide the request into a date fields part and a time fields part

Can you point me where in your code is this being performed?

  1. For each part, find the matching dateFormatItem

Can you point me where in your code is this being performed?

  1. Combine the patterns for the two dateFormatItems using the appropriate dateTimeFormat pattern, determined as follows from the requested date fields:
    • If the requested date fields include wide month (MMMM, LLLL) and weekday name of any length (e.g. E, EEEE, c, cccc), use
    • Otherwise, if the requested date fields include wide month, use
    • Otherwise, if the requested date fields include abbreviated month (MMM, LLL), use
    • Otherwise use

@rxaviers
Copy link
Member

Beyond the above comments, your code needs to follow our coding styles http://contribute.jquery.org/style-guide/js/.

}
return result;
}

Copy link
Member

Choose a reason for hiding this comment

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

  1. By placing this function outside the define scope, it's outside the module and therefore won't build correctly.
  2. Given you have created this function, why aren't you using it on case "datetime" in pattern: below? You have duplicate block of code.

Copy link
Member

Choose a reason for hiding this comment

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

Please, see my comment above (1) and (2) items.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rxaviers sir,

Sir, there is difference in path used in cldr.main of blocks of code mentioned. If wanted, we can add a if block for case "datetime" in pattern: and check for "datetime" in pattern: or "skeleton" in pattern: to handle both in one function. Should I add?

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

What I have inferred from the issue is this:

Divide the request into a date fields part and a time fields part

Here there is no need to do this since the date and time part can be checked in both A and B ways as mentioned by you above and we won't be requiring individual parts as the 4 cases below don't need them. If they are present individually, they have already been handled before.

For each part, find the matching dateFormatItem

Again since we have to return "full" , "long", "medium", "short" , I see no need to find raw patterns.

Combine the patterns for the two dateFormatItems using the appropriate dateTimeFormat pattern, determined as follows from the requested date fields

Here we need to return "full" , "long", "medium", "short" according to cases.

This is what I meant in the rough code I mentioned here

Now I feel I had inferred it wrong. What I now feel needs to be done is this:

Divide the request into a date fields part and a time fields part

Here extract the date and time part by parsing and checking for 'M', 'h' etc.

For each part, find the matching dateFormatItem

Check if these exist individually in the availableFormats. What if it doesn't? Throw an error, right?

Combine the patterns for the two dateFormatItems using the appropriate dateTimeFormat pattern, determined as follows from the requested date fields

Case 1. If date component has "(MMMM, LLLL)" and "(E, EEEE, c, cccc)" , we use rawPattern of "full". By use we mean return the "full" or we need to arrange "MMMM" and everything in component as in rawPattern of "full" etc, right? Need a suggestion how to do this, if it indeed is to be done.
....(same for next cases)

Beyond the above comments, your code needs to follow our coding styles http://contribute.jquery.org/style-guide/js/.

Okay sir, going through it.

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

May I know if new inference is correct or if there is any changes required.

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

If there is any change in what I mentioned please let me know or give me a yes. so that I start implementing it. Thank you. Sorry if I am disturbing.

@rxaviers
Copy link
Member

@manrajgrover, I'm not convinced your interpretation is correct. What pattern do you get for the skeleton "MMME"? Do you get "LLL, ccc"?

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

Nope. But I guess I have started to see your point now and what the algorithm actually says.

If a client-requested set of fields includes both date and time fields, and if the availableFormats data does not include a dateFormatItem whose skeleton matches the same set of fields, then the request should be handled as follows:

  1. Divide the request into a date fields part and a time fields part

We need to take out the date and time from the skeleton provided.

  1. For each part, find the matching dateFormatItem

We match the dateSkeleton and timeSkeleton to the availableFormats

  1. Combine the patterns for the two dateFormatItems using the appropriate dateTimeFormat pattern, determined as follows from the requested date fields:
    1. If the requested date fields include wide month (MMMM, LLLL) and weekday name of any length (e.g. E, EEEE, c, cccc), use <dateTimeFormatLength type="full">

Sir here we will check dateSkeleton and see if it contains MMMM and if yes then we will use "full" dateTime skeleton, convert it to raw pattern and then map the raw pattern of dateSkeleton to dateTime raw pattern and delete which all unmapped entities from result before returning it.

   1. Otherwise, if the requested date fields include wide month, use `<dateTimeFormatLength type="long">`

Same here with dateTime raw pattern "long".

   1. Otherwise, if the requested date fields include abbreviated month (MMM, LLL), use `<dateTimeFormatLength type="medium">`

Same here with dateTime raw pattern "medium".

   1. Otherwise use `<dateTimeFormatLength type="short">`

Same here with dateTime raw pattern "short".

Sorry for taking time to understand this. I hope this is correct now.

@rxaviers
Copy link
Member

We need to take out the date and time from the skeleton provided.

Correct. 👍

We match the dateSkeleton and timeSkeleton to the availableFormats

Correct. 👍

Sir here we will check dateSkeleton and see if it contains MMMM and if yes then we will use "full" dateTime skeleton, convert it to raw pattern and then map the raw pattern of dateSkeleton to dateTime raw pattern and delete which all unmapped entities from result before returning it.
...
Same here with dateTime raw pattern "long".
...
Same here with dateTime raw pattern "medium".
...
Same here with dateTime raw pattern "short".

I don't think this is correct. I understood that depending of the fields present in the dateSkeleton or timeSkeleton you should use a different form of "glue". For example, if the skeleton has "MMMM", you must use <dateTimeFormatLength type="full">, which is {1} 'at' {0}. You will replace {1} with the date pattern and {0} with the time pattern according to http://www.unicode.org/reports/tr35/tr35-dates.html#dateTimeFormat.

Sorry for taking time to understand this. I hope this is correct now.

No problem. Thanks for the resilience.

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

Ohkay sir! I was thinking of giving full flexibility to user to use any skeleton he/she wants and then mapping accordingly to give the result(This would require some brainstorming as well)

I am currently working on it but one thing that is confusing is availableFormats does not contain any skeleton for MMMM. I will add this case once this is cleared. Till then, I will code rest of the things.

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

I have re-coded the whole feature and tested on few cases and got positive results. I have also taken care of putting G to the end of the result in case of medium and short for putting AD at the end. I have tried to follow good coding style given here but don't know if I am missing anything or not.

Also please clear the MMMM case as they are not available under availableFormats given here.

I have not included L and c cases as they don't occur in skeleton but occur in raw pattern.

Please review the code. Thank you.

@jzaefferer
Copy link
Contributor

@manrajgrover regarding GSoC (I missed your IRC PM), please submit your proposal on the official site, we can review it there.

@manrajgrover
Copy link
Contributor Author

@jzaefferer sir,

No problem sir. Sure sir. Thank you. :)

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

I feel everything is covered now. Please review the code and let me know if I am missing anything. Thank you.

@@ -29,7 +29,8 @@ function validateRequiredCldr( path, value ) {
skip: [
/dates\/calendars\/gregorian\/days\/.*\/short/,
/supplemental\/timeData\/(?!001)/,
/supplemental\/weekData\/(?!001)/
/supplemental\/weekData\/(?!001)/,
/dates\/calendars\/gregorian\/dateTimeFormats\/availableFormats/
Copy link
Member

Choose a reason for hiding this comment

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

Style: please sort it using alphabetical order, i.e., as first line.

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

Made the changes. Please review the fixes. Thank you.

@manrajgrover
Copy link
Contributor Author

Hi @rxaviers sir,

Please review the code and let me know the changes. Sorry if you're busy and I am disturbing. Thank you.

@@ -28,6 +28,7 @@ function validateRequiredCldr( path, value ) {
validateCldr( path, value, {
skip: [
/dates\/calendars\/gregorian\/days\/.*\/short/,
/dates\/calendars\/gregorian\/dateTimeFormats\/availableFormats/,
/supplemental\/timeData\/(?!001)/,
/supplemental\/weekData\/(?!001)/
Copy link
Member

Choose a reason for hiding this comment

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

Alphabetical order is:

/dates\/calendars\/gregorian\/dateTimeFormats\/availableFormats/,
/dates\/calendars\/gregorian\/days\/.*\/short/,
/supplemental\/timeData\/(?!001)/,
/supplemental\/weekData\/(?!001)/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oopsie. Fixing.

return function( pattern, cldr ) {
var result;
var result, getDateTime, skeleton, dateSkeleton = "", timeSkeleton = "", type;
Copy link
Member

Choose a reason for hiding this comment

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

-       var result, getDateTime, skeleton, dateSkeleton = "", timeSkeleton = "",
+       var getDateTime, result, skeleton, type,
+               dateSkeleton = "",
+               timeSkeleton = "";

Note that variables that assign initial value are placed in their own lines. Note the alphabetical order.

@rxaviers
Copy link
Member

Implementation is working, great! Now, it's time to fix the coding style issues for which I've left comments inline and consider replacing getDateTime for combineDateTime detailed in my inline comments as well.

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

I have replaced getDateTime for combineDateTime but found a bug in the function and have commented issue and fix for it. Let me know if I missed anything.

@rxaviers
Copy link
Member

@manrajgrover, yeap date and time were inverted there. Your fix is correct.

@rxaviers rxaviers closed this in c471268 Apr 14, 2015
rxaviers added a commit that referenced this pull request Apr 14, 2015
@rxaviers
Copy link
Member

Landed thanks

@manrajgrover
Copy link
Contributor Author

@rxaviers sir,

Great! Thank you for helping me throughout the fix. Really learn't a lot including coding styles through this fix. I feel we should document the new feature now and add examples for the same.

@rxaviers
Copy link
Member

Sounds good. Feel free to send a PR with such updates. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants