@@ -158,12 +158,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
158
158
throw Error ( `Invalid date "${ date } ". Date has to be greater than 0.` ) ;
159
159
}
160
160
161
- let result ;
162
- if ( this . options && this . options . useUtc ) {
163
- result = moment . utc ( { year, month, date } ) . locale ( this . locale ) ;
164
- } else {
165
- result = moment ( { year, month, date } ) . locale ( this . locale ) ;
166
- }
161
+ const result = this . _createMoment ( { year, month, date} ) . locale ( this . locale ) ;
167
162
168
163
// If the result isn't valid, the date must have been out of bounds for this month.
169
164
if ( ! result . isValid ( ) ) {
@@ -174,14 +169,14 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
174
169
}
175
170
176
171
today ( ) : Moment {
177
- return moment ( ) . locale ( this . locale ) ;
172
+ return this . _createMoment ( ) . locale ( this . locale ) ;
178
173
}
179
174
180
175
parse ( value : any , parseFormat : string | string [ ] ) : Moment | null {
181
176
if ( value && typeof value == 'string' ) {
182
- return moment ( value , parseFormat , this . locale ) ;
177
+ return this . _createMoment ( value , parseFormat , this . locale ) ;
183
178
}
184
- return value ? moment ( value ) . locale ( this . locale ) : null ;
179
+ return value ? this . _createMoment ( value ) . locale ( this . locale ) : null ;
185
180
}
186
181
187
182
format ( date : Moment , displayFormat : string ) : string {
@@ -216,13 +211,13 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
216
211
deserialize ( value : any ) : Moment | null {
217
212
let date ;
218
213
if ( value instanceof Date ) {
219
- date = moment ( value ) ;
214
+ date = this . _createMoment ( value ) ;
220
215
}
221
216
if ( typeof value === 'string' ) {
222
217
if ( ! value ) {
223
218
return null ;
224
219
}
225
- date = moment ( value , moment . ISO_8601 ) . locale ( this . locale ) ;
220
+ date = this . _createMoment ( value , moment . ISO_8601 ) . locale ( this . locale ) ;
226
221
}
227
222
if ( date && this . isValid ( date ) ) {
228
223
return date ;
@@ -241,4 +236,9 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
241
236
invalid ( ) : Moment {
242
237
return moment . invalid ( ) ;
243
238
}
239
+
240
+ /** Creates a Moment instance while respecting the current UTC settings. */
241
+ private _createMoment ( ...args : any [ ] ) : Moment {
242
+ return ( this . options && this . options . useUtc ) ? moment . utc ( ...args ) : moment ( ...args ) ;
243
+ }
244
244
}
0 commit comments