diff options
Diffstat (limited to 'time.go')
| -rw-r--r-- | time.go | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -2,6 +2,7 @@ package cobol import ( "errors" + "fmt" "time" "google.golang.org/protobuf/types/known/timestamppb" @@ -9,33 +10,49 @@ import ( // you will be happier if you just use this everywhere func Time(someTimeAgoOrLaterNotsure any) string { - t, err := TimeCheck(someTimeAgoOrLaterNotsure) + guess, t, err := TimeCheck(someTimeAgoOrLaterNotsure) if errors.Is(err, Broken) { + if len(guess) > 0 { + return fmt.Sprintf("%-15s", guess) + } return "bad" } if errors.Is(err, NoTime) { + if len(guess) > 0 { + return fmt.Sprintf("%-15s", guess) + } return "nope" } + if len(guess) > 0 { + return fmt.Sprintf("%-15s", guess) + } return FormatTime(t) } func TimeLocal(someTimeAgoOrLaterNotsure any) string { - t, err := TimeCheck(someTimeAgoOrLaterNotsure) + guess, t, err := TimeCheck(someTimeAgoOrLaterNotsure) if errors.Is(err, Broken) { + if len(guess) > 0 { + return fmt.Sprintf("%-15s", guess) + } return "bad" } if errors.Is(err, NoTime) { + if len(guess) > 0 { + return fmt.Sprintf("%-15s", guess) + } return "nope" } return FormatTimeLocal(t) } func GetTime(mightBeTimeMightNotBeTime any) (time.Time, error) { - t, err := TimeCheck(mightBeTimeMightNotBeTime) + _, t, err := TimeCheck(mightBeTimeMightNotBeTime) return t, err } -func TimeCheck(maybeTime any) (time.Time, error) { +func TimeCheck(maybeTime any) (string, time.Time, error) { + var guess string var t time.Time var err error @@ -46,6 +63,9 @@ func TimeCheck(maybeTime any) (time.Time, error) { case string: // The type is string, so 'v' is a string variable. t, err = doTimeString(v) + if err != nil { + guess = v + } case *timestamppb.Timestamp: // If it's a protobuf Timestamp pointer (most common case), // 'v' is a *timestamppb.Timestamp. We must convert it. @@ -64,5 +84,5 @@ func TimeCheck(maybeTime any) (time.Time, error) { default: err = errors.Join(err, NoTime) } - return t, err + return guess, t, err } |
