Files
yatm/internal/dataformat/time.go
T
Samuel Cui 4fef653b71 Prepare YATM v1.0.0-alpha.2
Unify file queries and Scan execution, retain indexed Identical results,
improve Job and Preview workflows, and verify release packaging.
2026-10-05 19:08:49 +08:00

20 lines
527 B
Go

package dataformat
import (
"fmt"
"time"
)
// Nanoseconds converts a source instant to the persisted signed Unix nanosecond format.
// A missing source time keeps the established zero sentinel instead of overflowing UnixNano.
func Nanoseconds(value time.Time) (int64, error) {
if value.IsZero() {
return 0, nil
}
stamp := value.UnixNano()
if !time.Unix(0, stamp).Equal(value) {
return 0, fmt.Errorf("timestamp %s is outside the signed Unix nanosecond range", value.Format(time.RFC3339Nano))
}
return stamp, nil
}