1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/timeutils/utils.go
Ahmet Alp Balkan cb9a6b9aed Add --since argument to docker logs cmd
Added --since argument to `docker logs` command. Accept unix
timestamps and shows logs only created after the specified date.

Default value is 0 and passing default value or not specifying
the value in the request causes parameter to be ignored (behavior
prior to this change).

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
2015-05-10 20:42:14 +00:00

22 lines
519 B
Go

package timeutils
import (
"strconv"
"time"
)
// GetTimestamp tries to parse given string as RFC3339 time
// or Unix timestamp, if successful returns a Unix timestamp
// as string otherwise returns value back.
func GetTimestamp(value string) string {
format := RFC3339NanoFixed
loc := time.FixedZone(time.Now().Zone())
if len(value) < len(format) {
format = format[:len(value)]
}
t, err := time.ParseInLocation(format, value, loc)
if err != nil {
return value
}
return strconv.FormatInt(t.Unix(), 10)
}