Date: Add formatDateToParts - #700
Conversation
1b039ba to
5ee25cb
Compare
9a1b387 to
1cd9bd4
Compare
1cd9bd4 to
6118055
Compare
ff349bd to
c11b38a
Compare
jzaefferer
left a comment
There was a problem hiding this comment.
I started reviewing, then got dragged into a meeting. Didn't get very far, but hopefully the existing comments will help.
|
|
||
| enFormatter( new Date( 2010, 10, 30, 17, 55 ) ); | ||
| // > "11/30/2010, 5:55 PM" | ||
| // > "11/30/2010" |
There was a problem hiding this comment.
Should the line above still pass the time to the Date constructor? Probably applies to various other examples in this file (and others?) as well.
There was a problem hiding this comment.
The time part of the Date constructor is irrelevant and could be removed. 👍
|
|
||
| ### Example | ||
|
|
||
| Prior to using any date methods, you must load |
There was a problem hiding this comment.
Do all docs have this note in the example section? Seems like important information that could be pulled up.
There was a problem hiding this comment.
Yeap, other modules/fns have the same statement.
| formatter( new Date( 2010, 10, 30, 17, 55 ) ).map(({type, value}) => { | ||
| switch ( type ) { | ||
| case "year": return `<strong>${value}</strong>`; | ||
| default : return value; |
There was a problem hiding this comment.
misplaced space in front of the colon
|
|
||
| - `day` | ||
|
|
||
| The string used for the day, e.g., `"17"`, `"١٦"`. |
There was a problem hiding this comment.
Could compress this section a lot by putting the type of description on one line.
- `day`: The string used for the day, e.g., `"17"`, `"١٦"`.
There was a problem hiding this comment.
Yeap, I think it needs overall improvement. I dislike the current format of the API, I am wondering if we had something like https://github.com/rxaviers/relative-time#formatdate-options instead.
There was a problem hiding this comment.
Let's track overall docs improvement in a separate PR.
| Globalize.locale( "en" ); | ||
| formatter = Globalize.dateToPartsFormatter(); | ||
|
|
||
| formatter( new Date( 2010, 10, 30, 17, 55 ) ).map(({type, value}) => { |
There was a problem hiding this comment.
This is a great example, but it doesn't output the time, which seems harder to implement, since a join("") wouldn't be enough. Would be great to have an example including time.
There was a problem hiding this comment.
since a
join("")wouldn't be enough
Why? Check the parts output of a date and time case https://github.com/globalizejs/globalize/pull/700/files#diff-5e625c00d307f2b886e1b33225953053R165
Having said that, I think it's valid to include a date and time example.
|
@jzaefferer thanks for your review |
d9b8c40 to
9408bff
Compare
| "number-label": "Número", | ||
| "currency-label": "Moneda", | ||
| "date-label": "Fecha", | ||
| "date-to-parts-label": "Fecha (note el mes destacado en negro, el marcador de html se agregó utilizando dateToPartsFormatter)", |
| "number-label": "Zahl", | ||
| "currency-label": "Währung", | ||
| "date-label": "Datum", | ||
| "date-to-parts-label": "Datum (beachten Sie den hervorgehobenen Monat, das Markup wurde mit dateToPartsFormatter hinzugefügt)", |
9408bff to
8eed86d
Compare
When dateToPartsFormatter was added, dateFormatter became an alias to it. Although globalize-compiler can handle it by using `.compileExtracts()`, it doesn't by using `.compile()` and passing `formattersAndParsers` argument. This update fixed that. Amends e4234a7 Ref globalizejs#678 Ref globalizejs#697 Ref globalizejs#700
Supersedes #697, Fixes #678
List of part types, its respective CLDR date fields, and comparison with Intl DateTimeFormat formatToParts.
List of part types and the corresponding CLDR date field patterns.
Checklist:
Checklist