Skip to content

Commit bba99b7

Browse files
committed
add date formatter to MessageFormatter, refs globalizejs#563
1 parent ab67520 commit bba99b7

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/core.js

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ Globalize.locale = function( locale ) {
8686
return this.cldr;
8787
};
8888

89+
Globalize._messageFmts = {};
90+
91+
Globalize.addMessageFormatterFunction = function( name, fn ) {
92+
Globalize._messageFmts[name] = fn;
93+
};
94+
8995
/**
9096
* Optimization to avoid duplicating some internal functions across modules.
9197
*/

src/date.js

+13
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ Globalize.prototype.parseDate = function( value, options ) {
153153
return this.dateParser( options )( value );
154154
};
155155

156+
Globalize.addMessageFormatterFunction( "date", function( v, lc, p ) {
157+
var options;
158+
if ( p ) {
159+
options = {
160+
date: p
161+
};
162+
}
163+
if ( typeof lc !== "string" ) {
164+
lc = lc[0];
165+
}
166+
return ( new Globalize( lc ) ).formatDate( v, options );
167+
} );
168+
156169
return Globalize;
157170

158171
});

src/message.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ Globalize.prototype.messageFormatter = function( path ) {
8787
this.pluralGenerator() :
8888
createErrorPluralModulePresence;
8989

90-
formatter = new MessageFormat( cldr.locale, pluralGenerator ).compile( message );
90+
formatter = new MessageFormat( cldr.locale, pluralGenerator, Globalize._messageFmts )
91+
.compile( message );
9192

9293
returnFn = messageFormatterFn( formatter );
9394

0 commit comments

Comments
 (0)