@@ -158,12 +158,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
158158 throw Error ( `Invalid date "${ date } ". Date has to be greater than 0.` ) ;
159159 }
160160
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 ) ;
167162
168163 // If the result isn't valid, the date must have been out of bounds for this month.
169164 if ( ! result . isValid ( ) ) {
@@ -174,14 +169,14 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
174169 }
175170
176171 today ( ) : Moment {
177- return moment ( ) . locale ( this . locale ) ;
172+ return this . _createMoment ( ) . locale ( this . locale ) ;
178173 }
179174
180175 parse ( value : any , parseFormat : string | string [ ] ) : Moment | null {
181176 if ( value && typeof value == 'string' ) {
182- return moment ( value , parseFormat , this . locale ) ;
177+ return this . _createMoment ( value , parseFormat , this . locale ) ;
183178 }
184- return value ? moment ( value ) . locale ( this . locale ) : null ;
179+ return value ? this . _createMoment ( value ) . locale ( this . locale ) : null ;
185180 }
186181
187182 format ( date : Moment , displayFormat : string ) : string {
@@ -216,13 +211,13 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
216211 deserialize ( value : any ) : Moment | null {
217212 let date ;
218213 if ( value instanceof Date ) {
219- date = moment ( value ) ;
214+ date = this . _createMoment ( value ) ;
220215 }
221216 if ( typeof value === 'string' ) {
222217 if ( ! value ) {
223218 return null ;
224219 }
225- date = moment ( value , moment . ISO_8601 ) . locale ( this . locale ) ;
220+ date = this . _createMoment ( value , moment . ISO_8601 ) . locale ( this . locale ) ;
226221 }
227222 if ( date && this . isValid ( date ) ) {
228223 return date ;
@@ -241,4 +236,9 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
241236 invalid ( ) : Moment {
242237 return moment . invalid ( ) ;
243238 }
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+ }
244244}
0 commit comments