9892ab0af7
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>
22 lines
519 B
Go
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)
|
|
}
|