MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / normalizeTimeFields

Method normalizeTimeFields

internal/search/search.go:372–403  ·  view source on GitHub ↗

normalizeTimeFields converts time fields to Unix timestamps

(config CollectionConfig, data map[string]interface{})

Source from the content-addressed store, hash-verified

370
371// normalizeTimeFields converts time fields to Unix timestamps
372func (t *TypesenseClient) normalizeTimeFields(config CollectionConfig, data map[string]interface{}) {
373 for _, field := range config.TimeFields {
374 if fieldValue, ok := data[field]; ok {
375 switch v := fieldValue.(type) {
376 case time.Time:
377 data[field] = v.Unix()
378 case int64:
379 // Time already in Unix format, no action needed
380 case string:
381 if v == "" {
382 delete(data, field)
383 continue
384 }
385
386 if t, err := time.Parse(time.RFC3339, v); err == nil {
387 data[field] = t.Unix()
388 } else if t, err := time.Parse(time.RFC3339Nano, v); err == nil {
389 data[field] = t.Unix()
390 } else {
391 logrus.Warnf("Failed to parse time field %s with value %v, setting to 0", field, v)
392 data[field] = int64(0)
393 }
394 case float64:
395 data[field] = int64(v)
396 default:
397 // For truly unrecognized types, set to 0 and log
398 logrus.Warnf("Unrecognized time field type for %s: %T, setting to 0", field, v)
399 data[field] = int64(0)
400 }
401 }
402 }
403}
404
405// getIDField returns the primary ID field name for a given table
406func (t *TypesenseClient) getIDField(table string) string {

Calls

no outgoing calls