Skip to content

Time isZero after String/Byte conv #60

@HenryVolkmer

Description

@HenryVolkmer

hi,

this test fails, any ideas?

package main

import (
    "testing"
    "time"
    "github.com/influxdata/line-protocol/v2/lineprotocol"
)

func TestTime(t *testing.T) {
    enc := lineprotocol.Encoder{}
    enc.StartLine("a_measurement")
    enc.AddField("temp",lineprotocol.MustNewValue(int64(10)))
    enc.EndLine(time.Now())

    // explicite from bytes to string and from string to bytes
    str := string(enc.Bytes())
    dec := lineprotocol.NewDecoderWithBytes([]byte(str))

    tests := map[string]lineprotocol.Precision {
        "nano": lineprotocol.Nanosecond,
        "micro": lineprotocol.Microsecond,
        "second": lineprotocol.Second,
    }

    for label,p := range tests {
        ti, err := dec.Time(p, time.Time{})
        if err != nil {
            panic(err)
        }
        if ti.IsZero() {
            t.Errorf("decoder.Time for precision %s should not be zero",label)
        }   
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions