refactoring based on pr review

pull/2080/head
Cory LaNou 2015-03-26 14:11:44 -06:00
parent d653e41712
commit c0404e577e
1 changed files with 2 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package graphite
import (
"errors"
"fmt"
"math"
"strconv"
"strings"
"time"
@ -87,21 +88,13 @@ func (p *Parser) Parse(line string) (influxdb.Point, error) {
fieldValues[name] = v
// Parse timestamp.
//unixTime, err := strconv.ParseInt(fields[2], 10, 64)
unixTime, err := strconv.ParseFloat(fields[2], 64)
if err != nil {
return influxdb.Point{}, err
}
var timestamp time.Time
// Check if we have fractional seconds
if float64(int64(unixTime)) != unixTime {
nanoseconds := int64((unixTime - float64(int64(unixTime))) * float64(time.Second))
seconds := int64(unixTime)
timestamp = time.Unix(seconds, nanoseconds)
} else {
timestamp = time.Unix(int64(unixTime), 0)
}
timestamp := time.Unix(int64(unixTime), int64((unixTime-math.Floor(unixTime))*float64(time.Second)))
point := influxdb.Point{
Name: name,