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: Add formatDateToParts #700

Merged
merged 3 commits into from Apr 12, 2017

Conversation

Projects
None yet
4 participants
@rxaviers
Member

rxaviers commented Mar 3, 2017

Supersedes #697, Fixes #678

List of part types, its respective CLDR date fields, and comparison with Intl DateTimeFormat formatToParts.

Globalize CLDR date fields Intl formatToParts
era era era
year year year
quarter quarter -
month month month
week week -
day day day
weekday weekday weekday
dayperiod dayperiod dayPeriod
hour hour hour
minute minute minute
second second second
zone zone timeZoneName
literal literal literal

List of part types and the corresponding CLDR date field patterns.

part type CLDR date field CLDR date field patterns
era era G
year year yY
quarter quarter qQ
month month ML
week week wW
day day dDF
weekday weekday ecE
dayperiod dayperiod a
hour hour hHkK
minute minute m
second second sSA
zone zone zOxX
literal literal

Checklist:
Checklist

  • Implementation
    • Functionality
    • Coding style (build passes)
    • formatDateToParts and dateToPartsFormatter.
  • Unit tests
    • Update test/unit/date/format.js
    • Update test/unit/date/format-properties.js
  • Functional tests
    • Update test/functional/date/format-date.js
    • move from test/functional/date/format-date.js into formatDateToParts and dateToPartsFormatter.
  • Runtime code
    • Update src/date-runtime.js
  • Documentation
    • Update doc/api/date/date-to-parts-formatter.md
  • Examples
    • Update examples/amd-bower
    • Update examples/app-npm-webpack
      • globalize-webpack-plugin update
      • use dateToParts
    • Update examples/globalize-compiler
    • Update examples/node-npm
    • Update examples/plain-javascript
    • Requires compiler upgrade globalizejs/globalize-compiler#24
@jsf-clabot

This comment has been minimized.

Show comment
Hide comment
@jsf-clabot

jsf-clabot Mar 14, 2017

CLA assistant check
All committers have signed the CLA.

jsf-clabot commented Mar 14, 2017

CLA assistant check
All committers have signed the CLA.

@rxaviers rxaviers added this to the 1.3.0 milestone Mar 17, 2017

@jzaefferer

I started reviewing, then got dragged into a meeting. Didn't get very far, but hopefully the existing comments will help.

@@ -89,7 +89,7 @@ var enFormatter = Globalize( "en" ).dateFormatter(),
deFormatter = Globalize( "de" ).dateFormatter();
enFormatter( new Date( 2010, 10, 30, 17, 55 ) );
// > "11/30/2010, 5:55 PM"
// > "11/30/2010"

This comment has been minimized.

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

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.

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

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.

This comment has been minimized.

@rxaviers

rxaviers Apr 11, 2017

Member

The time part of the Date constructor is irrelevant and could be removed. 👍

@rxaviers

rxaviers Apr 11, 2017

Member

The time part of the Date constructor is irrelevant and could be removed. 👍

This comment has been minimized.

@rxaviers
### Example
Prior to using any date methods, you must load

This comment has been minimized.

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

Do all docs have this note in the example section? Seems like important information that could be pulled up.

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

Do all docs have this note in the example section? Seems like important information that could be pulled up.

This comment has been minimized.

@rxaviers

rxaviers Apr 11, 2017

Member

Yeap, other modules/fns have the same statement.

@rxaviers

rxaviers Apr 11, 2017

Member

Yeap, other modules/fns have the same statement.

Show outdated Hide outdated doc/api/date/date-to-parts-formatter.md
formatter( new Date( 2010, 10, 30, 17, 55 ) ).map(({type, value}) => {
switch ( type ) {
case "year": return `<strong>${value}</strong>`;
default : return value;

This comment has been minimized.

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

misplaced space in front of the colon

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

misplaced space in front of the colon

This comment has been minimized.

@rxaviers
@rxaviers
- `day`
The string used for the day, e.g., `"17"`, `"١٦"`.

This comment has been minimized.

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

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"`, `"١٦"`.
@jzaefferer

jzaefferer Apr 11, 2017

Contributor

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"`, `"١٦"`.

This comment has been minimized.

@rxaviers

rxaviers Apr 11, 2017

Member

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.

@rxaviers

rxaviers Apr 11, 2017

Member

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.

This comment has been minimized.

@rxaviers

rxaviers Apr 12, 2017

Member

Let's track overall docs improvement in a separate PR.

@rxaviers

rxaviers Apr 12, 2017

Member

Let's track overall docs improvement in a separate PR.

Show outdated Hide outdated doc/api/date/date-to-parts-formatter.md
Globalize.locale( "en" );
formatter = Globalize.dateToPartsFormatter();
formatter( new Date( 2010, 10, 30, 17, 55 ) ).map(({type, value}) => {

This comment has been minimized.

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

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.

@jzaefferer

jzaefferer Apr 11, 2017

Contributor

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.

This comment has been minimized.

@rxaviers

rxaviers Apr 11, 2017

Member

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.

@rxaviers

rxaviers Apr 11, 2017

Member

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.

This comment has been minimized.

@rxaviers
@rxaviers

This comment has been minimized.

Show comment
Hide comment
@rxaviers

rxaviers Apr 12, 2017

Member

@jzaefferer thanks for your review

Member

rxaviers commented Apr 12, 2017

@jzaefferer thanks for your review

@@ -4,6 +4,7 @@
"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)",

This comment has been minimized.

@rxaviers

rxaviers Apr 12, 2017

Member

Thanks @lwelti

@rxaviers
@@ -4,6 +4,7 @@
"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)",

This comment has been minimized.

@rxaviers
@rxaviers

@rxaviers rxaviers merged commit 8eed86d into globalizejs:master Apr 12, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details

@rxaviers rxaviers deleted the rxaviers:date-to-parts-2 branch Apr 12, 2017

rxaviers added a commit to rxaviers/globalize that referenced this pull request May 17, 2017

Date: Fix dateFormatter runtime
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 #678
Ref #697
Ref #700
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment