| 1 |
// Copyright (c) 2018, Maxime Soulé |
| 2 |
// All rights reserved. |
| 3 |
// |
| 4 |
// This source code is licensed under the BSD-style license found in the |
| 5 |
// LICENSE file in the root directory of this source tree. |
| 6 |
|
| 7 |
package td |
| 8 |
|
| 9 |
import ( |
| 10 |
"reflect" |
| 11 |
"time" |
| 12 |
|
| 13 |
"github.com/maxatome/go-testdeep/internal/ctxerr" |
| 14 |
"github.com/maxatome/go-testdeep/internal/dark" |
| 15 |
"github.com/maxatome/go-testdeep/internal/types" |
| 16 |
) |
| 17 |
|
| 18 |
// getTime returns the time.Time that is inside got or that can be |
| 19 |
// converted from got contents. |
| 20 |
func getTime(ctx ctxerr.Context, got reflect.Value, mustConvert bool) (time.Time, *ctxerr.Error) { |
| 21 |
var ( |
| 22 |
gotIf any |
| 23 |
ok bool |
| 24 |
) |
| 25 |
if mustConvert { |
| 26 |
gotIf, ok = dark.GetInterface(got.Convert(types.Time), true) |
| 27 |
} else { |
| 28 |
gotIf, ok = dark.GetInterface(got, true) |
| 29 |
} |
| 30 |
if !ok { |
| 31 |
return time.Time{}, ctx.CannotCompareError() |
| 32 |
} |
| 33 |
return gotIf.(time.Time), nil |
| 34 |
} |