Skip to content

Commit

Permalink
fixup! Date: Add formatDateToParts (2/2)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxaviers committed Apr 12, 2017
1 parent a9bc0b5 commit d19ee55
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions doc/api/date/date-to-parts-formatter.md
Expand Up @@ -95,7 +95,7 @@ var formatter;
Globalize.locale( "en" );
formatter = Globalize.dateToPartsFormatter();

formatter( new Date( 2010, 10, 30, 17, 55 ) );
formatter( new Date( 2010, 10, 30 ) );
// > [
// { "type": "month", "value": "11" },
// { "type": "literal", "value": "/" },
Expand All @@ -111,7 +111,7 @@ You can use the instance method `.dateToPartsFormatter()`, which uses the instan
var enFormatter = Globalize( "en" ).dateToPartsFormatter(),
deFormatter = Globalize( "de" ).dateToPartsFormatter();

enFormatter( new Date( 2010, 10, 30, 17, 55 ) );
enFormatter( new Date( 2010, 10, 30 ) );
// > [
// { "type": "month", "value": "11" },
// { "type": "literal", "value": "/" },
Expand All @@ -120,7 +120,7 @@ enFormatter( new Date( 2010, 10, 30, 17, 55 ) );
// { "type": "year", "value": "2010" }
// ]

deFormatter( new Date( 2010, 10, 30, 17, 55 ) );
deFormatter( new Date( 2010, 10, 30 ) );
// > [
// { type: 'day', value: '30' },
// { type: 'literal', value: '.' },
Expand All @@ -145,15 +145,15 @@ again in a customized way. For example by using [`Array.prototype.map()`][],
var formatter;

Globalize.locale( "en" );
formatter = Globalize.dateToPartsFormatter();
formatter = Globalize.dateToPartsFormatter({datetime: "short"});

formatter( new Date( 2010, 10, 30, 17, 55 ) ).map(({type, value}) => {
switch ( type ) {
case "year": return `<strong>${value}</strong>`;
default: return value;
}
}).join( "" );
// > "11/30/<strong>2010</strong>"
// > "11/30/<strong>10</strong>, 5:55 PM"
```

Please, see [.dateFormatter() example](./date-formatter.md#example) for
Expand Down

0 comments on commit d19ee55

Please sign in to comment.