@@ -331,16 +331,12 @@ func (b *BarmanBackup) deserializeBackupTimeStrings() error {
331331 return err
332332 }
333333 } else if b .BeginTimeString != "" {
334- b .BeginTime , err = time .Parse (barmanTimeLayout , b .BeginTimeString )
334+ // Barman 3.12.0 incorrectly puts an ISO formatted time in the ctime field.
335+ // So in case of parsing failure we try again parsing it as an ISO time,
336+ // discarding an eventual failure
337+ b .BeginTime , err = parseTimeWithFallbackLayout (b .BeginTimeString , barmanTimeLayout , barmanTimeLayoutISO )
335338 if err != nil {
336- // Barman 3.12.0 incorrectly puts an ISO formatted time in the ctime field.
337- // So in case of parsing failure we try again parsing it as an ISO time,
338- // discarding an eventual failure
339- var internalErr error
340- b .BeginTime , internalErr = time .Parse (barmanTimeLayoutISO , b .BeginTimeString )
341- if internalErr != nil {
342- return err
343- }
339+ return err
344340 }
345341 }
346342
@@ -350,22 +346,32 @@ func (b *BarmanBackup) deserializeBackupTimeStrings() error {
350346 return err
351347 }
352348 } else if b .EndTimeString != "" {
353- b .EndTime , err = time .Parse (barmanTimeLayout , b .EndTimeString )
349+ // Barman 3.12.0 incorrectly puts an ISO formatted time in the ctime field.
350+ // So in case of parsing failure we try again parsing it as an ISO time,
351+ // discarding an eventual failure
352+ b .EndTime , err = parseTimeWithFallbackLayout (b .EndTimeString , barmanTimeLayout , barmanTimeLayoutISO )
354353 if err != nil {
355- // Barman 3.12.0 incorrectly puts an ISO formatted time in the ctime field.
356- // So in case of parsing failure we try again parsing it as an ISO time,
357- // discarding an eventual failure
358- var internalErr error
359- b .EndTime , internalErr = time .Parse (barmanTimeLayoutISO , b .EndTimeString )
360- if internalErr != nil {
361- return err
362- }
354+ return err
363355 }
364356 }
365357
366358 return nil
367359}
368360
361+ func parseTimeWithFallbackLayout (value string , primaryLayout string , fallbackLayout string ) (time.Time , error ) {
362+ result , err := time .Parse (primaryLayout , value )
363+ if err == nil {
364+ return result , nil
365+ }
366+
367+ result , errFallback := time .Parse (fallbackLayout , value )
368+ if errFallback == nil {
369+ return result , nil
370+ }
371+
372+ return result , err
373+ }
374+
369375func (b * BarmanBackup ) isBackupDone () bool {
370376 return ! b .BeginTime .IsZero () && ! b .EndTime .IsZero ()
371377}
0 commit comments