mirror of
https://github.com/kopia/kopia.git
synced 2026-02-02 02:33:14 -05:00
Lack of generics support is blocking various dependency upgrades, so this unblocks that. Temporarily disabled `checklocks` linter until it is fixed upstream.
31 lines
792 B
Go
31 lines
792 B
Go
// Package timestampmeta provides utilities for preserving timestamps
|
|
// using per-blob key-value-pairs (metadata, tags, etc.)
|
|
package timestampmeta
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// ToMap returns a map containing single entry representing the provided time or nil map
|
|
// if the time is zero. The key-value pair map should be stored alongside the blob.
|
|
func ToMap(t time.Time, mapKey string) map[string]string {
|
|
if t.IsZero() {
|
|
return nil
|
|
}
|
|
|
|
return map[string]string{
|
|
mapKey: strconv.FormatInt(t.UnixNano(), 10),
|
|
}
|
|
}
|
|
|
|
// FromValue attempts to convert the provided value stored in metadata into time.Time.
|
|
func FromValue(v string) (t time.Time, ok bool) {
|
|
nanos, err := strconv.ParseInt(v, 10, 64)
|
|
if err != nil {
|
|
return time.Time{}, false
|
|
}
|
|
|
|
return time.Unix(0, nanos), true
|
|
}
|