Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
chore(profilecli): accept timestamps for queries (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev committed Jul 17, 2023
1 parent 262ebeb commit 77b3af5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/profilecli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -44,6 +45,27 @@ func parseTime(s string) (time.Time, error) {
return time.Now().Add(-d), nil
}

timestamp, terr := strconv.ParseInt(s, 10, 64)
if terr == nil {
/**
1689341454
1689341454046
1689341454046908
1689341454046908187
*/
switch len(s) {
case 10:
return time.Unix(timestamp, 0), nil
case 13:
return time.UnixMilli(timestamp), nil
case 16:
return time.UnixMicro(timestamp), nil
case 19:
return time.Unix(0, timestamp), nil
default:
return time.Time{}, fmt.Errorf("invalid timestamp length: %s", s)
}
}
// if not return first error
return time.Time{}, err

Expand Down

0 comments on commit 77b3af5

Please sign in to comment.