@@ -142,6 +142,7 @@ export class DatePipe implements PipeTransform {
142142 }
143143
144144 let date : Date ;
145+ let match : RegExpMatchArray | null ;
145146 if ( isDate ( value ) ) {
146147 date = value ;
147148 } else if ( ! isNaN ( value - parseFloat ( value ) ) ) {
@@ -158,17 +159,14 @@ export class DatePipe implements PipeTransform {
158159 */
159160 const [ y , m , d ] = value . split ( '-' ) . map ( ( val : string ) => + val ) ;
160161 date = new Date ( y , m - 1 , d ) ;
162+ } else if ( ( typeof value === 'string' ) && ( match = value . match ( ISO8601_DATE_REGEX ) ) ) {
163+ date = isoStringToDate ( match ) ;
161164 } else {
162165 date = new Date ( value ) ;
163166 }
164167
165168 if ( ! isDate ( date ) ) {
166- let match : RegExpMatchArray | null ;
167- if ( ( typeof value === 'string' ) && ( match = value . match ( ISO8601_DATE_REGEX ) ) ) {
168- date = isoStringToDate ( match ) ;
169- } else {
170- throw invalidPipeArgumentError ( DatePipe , value ) ;
171- }
169+ throw invalidPipeArgumentError ( DatePipe , value ) ;
172170 }
173171
174172 return formatDate ( date , format , locale || this . locale , timezone ) ;
@@ -180,9 +178,12 @@ export function isoStringToDate(match: RegExpMatchArray): Date {
180178 const date = new Date ( 0 ) ;
181179 let tzHour = 0 ;
182180 let tzMin = 0 ;
181+
182+ // match[8] means that the string contains "Z" (UTC) or a timezone like "+01:00" or "+0100"
183183 const dateSetter = match [ 8 ] ? date . setUTCFullYear : date . setFullYear ;
184184 const timeSetter = match [ 8 ] ? date . setUTCHours : date . setHours ;
185185
186+ // if there is a timezone defined like "+01:00" or "+0100"
186187 if ( match [ 9 ] ) {
187188 tzHour = + ( match [ 9 ] + match [ 10 ] ) ;
188189 tzMin = + ( match [ 9 ] + match [ 11 ] ) ;
0 commit comments