github.com/hernad/nomad@v1.6.112/nomad/state/indexer/time.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package indexer 5 6 import ( 7 "fmt" 8 "time" 9 ) 10 11 type TimeQuery struct { 12 Value time.Time 13 } 14 15 // IndexFromTimeQuery can be used as a memdb.Indexer query via ReadIndex and 16 // allows querying by time. 17 func IndexFromTimeQuery(arg any) ([]byte, error) { 18 p, ok := arg.(*TimeQuery) 19 if !ok { 20 return nil, fmt.Errorf("unexpected type %T for TimeQuery index", arg) 21 } 22 23 // Construct the index value and return the byte array representation of 24 // the time value. 25 var b IndexBuilder 26 b.Time(p.Value) 27 return b.Bytes(), nil 28 }