Skip to content

Commit

Permalink
fix: adjust date ranges for UTC and remove debug cruft (#84)
Browse files Browse the repository at this point in the history
missed a correction for UTC timezone when displaying converted dates. No idea why this changed and the test passed before
  • Loading branch information
ywwg authored Sep 28, 2023
1 parent b4b782c commit 867f4a8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/graphite/convert/whisperconverter/daterange.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ READLOOP:
terms := []string{}

if minTS != int64(math.MaxInt64) {
terms = append(terms, fmt.Sprintf("--start-date %s", time.UnixMilli(minTS).Format("2006-01-02")))
terms = append(terms, fmt.Sprintf("--start-date %s", time.UnixMilli(minTS).UTC().Format("2006-01-02")))
}
if maxTS != int64(math.MinInt64) {
terms = append(terms, fmt.Sprintf("--end-date %s", time.UnixMilli(maxTS).Format("2006-01-02")))
terms = append(terms, fmt.Sprintf("--end-date %s", time.UnixMilli(maxTS).UTC().Format("2006-01-02")))
}
terms = append(terms, "\n")
fmt.Printf(strings.Join(terms, " "))
Expand Down
9 changes: 4 additions & 5 deletions pkg/graphite/convert/whisperconverter/daterange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ import (

// This test contains a data due to how we take over STDOUT but it should be harmless.
func TestCommandDateRange(t *testing.T) {
// tmpDir, err := os.MkdirTemp("/tmp", "testCommandDateRange*")
// require.NoError(t, err)
// defer os.RemoveAll(tmpDir)
tmpDir, err := os.MkdirTemp("/tmp", "testCommandDateRange*")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
whisper.Now = func() time.Time {
t, err := time.Parse("2006-01-02", "2022-06-01")
if err != nil {
panic(err)
}
return t
}
tmpDir := "/tmp"

fooTimes, err := ToTimes([]string{
"2022-05-01",
Expand Down Expand Up @@ -87,7 +86,7 @@ func TestCommandDateRange(t *testing.T) {
os.Stdout = stdout

out := <-outC
require.Equal(t, "--start-date 2018-02-01 --end-date 2022-05-04\n", out)
require.Equal(t, "--start-date 2018-02-01 --end-date 2022-05-04 \n", out)

require.Equal(t, uint64(2), c.GetProcessedCount())
require.Equal(t, uint64(0), c.GetSkippedCount())
Expand Down
13 changes: 1 addition & 12 deletions pkg/graphite/convert/whisperconverter/test_utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package whisperconverter

import (
"fmt"
"os"
"time"

Expand All @@ -23,25 +22,15 @@ func CreateWhisperFile(path string, timestamps []*time.Time) error {
if err != nil {
return err
}
// defer wsp.Close()
defer wsp.Close()

for _, t := range timestamps {
fmt.Println("yes?")
err = wsp.Update(1.0, int(t.Unix()))
if err != nil {
fmt.Println(err)
return err
}
}

wsp.Close()

// wsp, err = whisper.Open(path)
// if err != nil {
// return err
// }
// wsp.Dump(true, false)

return nil
}

Expand Down

0 comments on commit 867f4a8

Please sign in to comment.