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

Date (skeletons): handle date and time in the same skeleton #272

Closed
rxaviers opened this issue Jun 3, 2014 · 16 comments
Closed

Date (skeletons): handle date and time in the same skeleton #272

rxaviers opened this issue Jun 3, 2014 · 16 comments

Comments

@rxaviers
Copy link
Member

rxaviers commented Jun 3, 2014

Currently, it's possible to:

> Globalize.formatDate(new Date(), "MMMd")
'Jun 3'
> Globalize.formatDate(new Date(), "hms")
'1:40:31 PM'

Although, .formatDate( date, "MMMdhm" ) isn't. But, it should.
http://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems

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
  2. For each part, find the matching dateFormatItem
  3. 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

See also: ibm-js/ecma402#76

@manrajgrover
Copy link
Contributor

@rxaviers sir,

I see ibm-js/ecma402/issues/76 have already implemented long , medium , short which is already available here under preset datetime . If there is more customization like above examples given by you, what we can do is parse the skeleton and see date and time component and call formatDate for both separately and return accordingly. But yes there may be several cases we have to take care of. For example, "GyMMM" and similar skeletons: In this we would need to put AD after the time. Also it may be possible user asks for time first before date. So should take care of all flexibilities.

I would like to take this up if possible.

@rxaviers
Copy link
Member Author

is already available here under preset datetime

Yeap, this issue isn't about the presets. But, skeletons.

For example, "GyMMM" and similar skeletons: In this we would need to put AD after the time. Also it may be possible user asks for time first before date. So should take care of all flexibilities.

@manrajgrover note there's a difference between skeletons and raw patterns. A skeleton is mapped into a raw pattern. For example, GyMMM skeleton becomes MMM y G raw pattern for en-US, and Gy年M月 raw pattern for zh-CN. So, note the order of the pattern-fields in a skeleton doesn't select their order in the final raw pattern. That's its beauty by the way. A skeleton should be always in the canonical order.

and call formatDate for both separately and return accordingly

I'm looking for a solution that extends date/expand-pattern.

@manrajgrover
Copy link
Contributor

@rxaviers sir,

Ohkay sir. So basically the pattern should be entered in canonical form and then should be extracted and processed, right? The method mentioned in this can be used but it does not say anything about the time. What if user wants dates "full" date but "short" time? There this method will return datetime: "full" .

I would suggest we take each date and time separately and then concatenate them. One more thing is if either date nor time don't exist, should we throw an error or give a closest form of datetime? How to do that?

I went through the code given in date/expand-pattern and saw we can handle these in case "skeleton" in pattern.

@rxaviers
Copy link
Member Author

So basically the pattern should be entered in canonical form and then should be extracted and processed, right

Correct.

What if user wants dates "full" date but "short" time? There this method will return datetime: "full" .

I would suggest we take each date and time separately and then concatenate them. One more thing is if either date nor time don't exist, should we throw an error or give a closest form of datetime? How to do that?

We won't handle the combination of different values for date and time separately.

I went through the code given in date/expand-pattern and saw we can handle these in case "skeleton" in pattern.

Correct. Just let me know in any questions.

@manrajgrover
Copy link
Contributor

@rxaviers sir,

We can check if it is date or time or datetime.

if(skeleton.isDate() != skeleton.isTime()){
    then do default search for result
else if(skeleton.isDateTime()){
    then follow four if cases listed above.
}

Last case is default short. We won't be doing appendItems as mentioned in this link last paragraph, right?

I shall start working on it.

@rxaviers
Copy link
Member Author

Yeap, your high level sketchup seems correct. Looking forward to it. Thanks

@manrajgrover
Copy link
Contributor

@rxaviers sir,

I have almost completed the feature. It is throwing error for the case containing "MMMME" and "MMMM" . This is because the CLDR does not contain these pattern. Though I just need to give "full" as result for them, which I am, it is throwing "E_MISSING_CLDR: Missing required CLDR content 'main/en/dates/timeZoneNames/gmtFormat'".

@rxaviers
Copy link
Member Author

it is throwing "E_MISSING_CLDR: Missing required CLDR content 'main/en/dates/timeZoneNames/gmtFormat'".

Have you loaded all the required CLDR data for the Date module?

@rxaviers
Copy link
Member Author

Though I just need to give "full" as result for them,

Why do you need to return full?

I have almost completed the feature. It is throwing error for the case containing "MMMME" and "MMMM" . This is because the CLDR does not contain these pattern.

I'm confused why are checking "MMMM" given it's about the month pattern only. It has nothing to do with handling date and time in the same skeleton.

Can you handle "MMME"? I'm mostly interested on handling date and time patterns in the same skeleton. Not #271.

@manrajgrover
Copy link
Contributor

@rxaviers sir,

According to the link, there are 4 cases, first one being when skeleton has "MMMM" and a day component. For that it says to print answer as datetime: "full". Yes sir, similarly for next three cases, I am returning "long" , "medium" and "short". "MMME" comes under Case 2.

@rxaviers
Copy link
Member Author

It's not saying you should use datetime: "full" (this is a Globalize definition). But, <dateTimeFormatLength type="long">, which is the "glue" pattern from CLDR data.

@rxaviers
Copy link
Member Author

I assume you have seen this data. But, just in case http://www.unicode.org/repos/cldr-aux/json/26/main/en/ca-gregorian.json

@manrajgrover
Copy link
Contributor

Yes sir. I have been following this only and have inferred the data from this and the link I mentioned before working. Sir, by "glue" pattern you mean?

@rxaviers
Copy link
Member Author

"dateTimeFormats": {
          "full": "{1} 'at' {0}",
          "long": "{1} 'at' {0}",
          "medium": "{1}, {0}",
          "short": "{1}, {0}"
}

@manrajgrover
Copy link
Contributor

Yeps. I have used them only. Should I send a PR? That will help clear things.

@rxaviers
Copy link
Member Author

Great then. Yeap, please do so.

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

No branches or pull requests

2 participants