Documentation
¶
Overview ¶
Package timestamp provides a type-safe timestamp implementation for evidence packs.
The Timestamp type enforces the exact format "YYYY-MM-DDTHH:MM:SSZ" (RFC 3339 strict) required by the evidence pack spec. This format is critical for JCS canonicalization - different timestamp representations (fractional seconds, timezone offsets) would produce different manifest digests.
Format Requirements ¶
- Exactly 20 characters
- UTC timezone (trailing "Z")
- No fractional seconds
- No timezone offsets
Usage ¶
ts := timestamp.Now()
ts, err := timestamp.Parse("2024-01-15T10:30:00Z")
ts := timestamp.FromTime(time.Now())
Security Properties ¶
- Format validation at parse time
- Immutable after construction
- JSON marshaling preserves exact format
Index ¶
- Constants
- func Validate(s string) error
- type Timestamp
- func (ts Timestamp) After(other Timestamp) bool
- func (ts Timestamp) Before(other Timestamp) bool
- func (ts Timestamp) Equal(other Timestamp) bool
- func (ts Timestamp) IsZero() bool
- func (ts Timestamp) MarshalJSON() ([]byte, error)
- func (ts Timestamp) String() string
- func (ts Timestamp) Sub(other Timestamp) time.Duration
- func (ts Timestamp) Time() time.Time
- func (ts *Timestamp) UnmarshalJSON(data []byte) error
Constants ¶
const Format = "2006-01-02T15:04:05Z"
Format is the exact timestamp format required by the evidence pack spec. This is a strict subset of RFC 3339: no fractional seconds, no timezone offsets.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Timestamp ¶
type Timestamp struct {
// contains filtered or unexported fields
}
Timestamp represents a timestamp in the canonical evidence pack format. The zero value is invalid; use Now, Parse, or FromTime to create.
func FromTime ¶
FromTime converts a time.Time to a Timestamp. The time is converted to UTC and truncated to second precision.
func MustParse ¶
MustParse parses a timestamp string, panicking if invalid. Use only for compile-time constants and tests.
func Parse ¶
Parse parses a timestamp string in the canonical format. Returns an error if the format is invalid.
func (Timestamp) After ¶
After reports whether ts is after other. Returns false if either timestamp is zero.
func (Timestamp) Before ¶
Before reports whether ts is before other. Returns false if either timestamp is zero.
func (Timestamp) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Timestamp) String ¶
String returns the canonical string representation. Returns empty string for zero-value Timestamp.
func (Timestamp) Time ¶
Time returns the underlying time.Time value. Returns zero time for zero-value Timestamp.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. Validates the timestamp format during unmarshaling.