@@ -10,7 +10,7 @@ define([
10
10
"./common/validate/parameter-type/string" ,
11
11
"./core" ,
12
12
"./date/expand-pattern" ,
13
- "./date/formatter-fn" ,
13
+ "./date/to-parts- formatter-fn" ,
14
14
"./date/format-properties" ,
15
15
"./date/parser-fn" ,
16
16
"./date/parse-properties" ,
@@ -21,7 +21,7 @@ define([
21
21
"./number"
22
22
] , function ( Cldr , runtimeBind , validate , validateCldr , validateDefaultLocale ,
23
23
validateParameterPresence , validateParameterTypeDate , validateParameterTypePlainObject ,
24
- validateParameterTypeString , Globalize , dateExpandPattern , dateFormatterFn ,
24
+ validateParameterTypeString , Globalize , dateExpandPattern , dateToPartsFormatterFn ,
25
25
dateFormatProperties , dateParserFn , dateParseProperties , dateTokenizerProperties ) {
26
26
27
27
function validateRequiredCldr ( path , value ) {
@@ -77,6 +77,33 @@ function validateOptionsSkeleton( pattern, skeleton ) {
77
77
*/
78
78
Globalize . dateFormatter =
79
79
Globalize . prototype . dateFormatter = function ( options ) {
80
+ var formatterFn = this . dateToPartsFormatter ( options ) ;
81
+ return function ( ) {
82
+ var parts = formatterFn . apply ( this , arguments ) ;
83
+ return parts . map ( function ( part ) {
84
+ return part . value ;
85
+ } ) . join ( "" ) ;
86
+ } ;
87
+ } ;
88
+
89
+ /**
90
+ * .dateToPartsFormatter( options )
91
+ *
92
+ * @options [Object] see date/expand_pattern for more info.
93
+ *
94
+ * Return a date formatter function (of the form below) according to the given options and the
95
+ * default/instance locale.
96
+ *
97
+ * fn( value )
98
+ *
99
+ * @value [Date]
100
+ *
101
+ * Return a function that formats a date to parts according to the given `format`
102
+ * and the default/instance
103
+ * locale.
104
+ */
105
+ Globalize . dateToPartsFormatter =
106
+ Globalize . prototype . dateToPartsFormatter = function ( options ) {
80
107
var args , cldr , numberFormatters , pad , pattern , properties , returnFn ;
81
108
82
109
validateParameterTypePlainObject ( options , "options" ) ;
@@ -104,7 +131,7 @@ Globalize.prototype.dateFormatter = function( options ) {
104
131
} ) ;
105
132
}
106
133
107
- returnFn = dateFormatterFn ( numberFormatters , properties ) ;
134
+ returnFn = dateToPartsFormatterFn ( numberFormatters , properties ) ;
108
135
109
136
runtimeBind ( args , cldr , returnFn , [ numberFormatters , properties ] ) ;
110
137
@@ -166,6 +193,23 @@ Globalize.prototype.formatDate = function( value, options ) {
166
193
return this . dateFormatter ( options ) ( value ) ;
167
194
} ;
168
195
196
+ /**
197
+ * .formatDateToParts( value, options )
198
+ *
199
+ * @value [Date]
200
+ *
201
+ * @options [Object] see date/expand_pattern for more info.
202
+ *
203
+ * Formats a date or number to parts according to the given options and the default/instance locale.
204
+ */
205
+ Globalize . formatDateToParts =
206
+ Globalize . prototype . formatDateToParts = function ( value , options ) {
207
+ validateParameterPresence ( value , "value" ) ;
208
+ validateParameterTypeDate ( value , "value" ) ;
209
+
210
+ return this . dateToPartsFormatter ( options ) ( value ) ;
211
+ } ;
212
+
169
213
/**
170
214
* .parseDate( value, options )
171
215
*
0 commit comments