Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
af551b88
Commit
af551b88
authored
Sep 21, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(tsdb): remove toUnix from timerange
parent
9534a04d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
40 deletions
+12
-40
pkg/tsdb/time_range.go
+0
-28
pkg/tsdb/time_range_test.go
+12
-12
No files found.
pkg/tsdb/time_range.go
View file @
af551b88
...
...
@@ -20,17 +20,6 @@ type TimeRange struct {
Now
time
.
Time
}
func
(
tr
TimeRange
)
FromUnix
()
(
int64
,
error
)
{
fromRaw
:=
strings
.
Replace
(
tr
.
From
,
"now-"
,
""
,
1
)
diff
,
err
:=
time
.
ParseDuration
(
"-"
+
fromRaw
)
if
err
!=
nil
{
return
0
,
err
}
return
tr
.
Now
.
Add
(
diff
)
.
Unix
(),
nil
}
func
(
tr
TimeRange
)
FromTime
()
(
time
.
Time
,
error
)
{
fromRaw
:=
strings
.
Replace
(
tr
.
From
,
"now-"
,
""
,
1
)
...
...
@@ -42,23 +31,6 @@ func (tr TimeRange) FromTime() (time.Time, error) {
return
tr
.
Now
.
Add
(
diff
),
nil
}
func
(
tr
TimeRange
)
ToUnix
()
(
int64
,
error
)
{
if
tr
.
To
==
"now"
{
return
tr
.
Now
.
Unix
(),
nil
}
else
if
strings
.
HasPrefix
(
tr
.
To
,
"now-"
)
{
withoutNow
:=
strings
.
Replace
(
tr
.
To
,
"now-"
,
""
,
1
)
diff
,
err
:=
time
.
ParseDuration
(
"-"
+
withoutNow
)
if
err
!=
nil
{
return
0
,
nil
}
return
tr
.
Now
.
Add
(
diff
)
.
Unix
(),
nil
}
return
0
,
fmt
.
Errorf
(
"cannot parse to value %s"
,
tr
.
To
)
}
func
(
tr
TimeRange
)
ToTime
()
(
time
.
Time
,
error
)
{
if
tr
.
To
==
"now"
{
return
tr
.
Now
,
nil
...
...
pkg/tsdb/time_range_test.go
View file @
af551b88
...
...
@@ -23,15 +23,15 @@ func TestTimeRange(t *testing.T) {
fiveMinAgo
,
_
:=
time
.
ParseDuration
(
"-5m"
)
expected
:=
now
.
Add
(
fiveMinAgo
)
res
,
err
:=
tr
.
From
Unix
()
res
,
err
:=
tr
.
From
Time
()
So
(
err
,
ShouldBeNil
)
So
(
res
,
ShouldAlmost
Equal
,
expected
.
Unix
())
So
(
res
.
Unix
(),
Should
Equal
,
expected
.
Unix
())
})
Convey
(
"now "
,
func
()
{
res
,
err
:=
tr
.
To
Unix
()
res
,
err
:=
tr
.
To
Time
()
So
(
err
,
ShouldBeNil
)
So
(
res
,
ShouldAlmost
Equal
,
now
.
Unix
())
So
(
res
.
Unix
(),
Should
Equal
,
now
.
Unix
())
})
})
...
...
@@ -43,20 +43,20 @@ func TestTimeRange(t *testing.T) {
}
Convey
(
"5h ago "
,
func
()
{
five
Min
Ago
,
_
:=
time
.
ParseDuration
(
"-5h"
)
expected
:=
now
.
Add
(
five
Min
Ago
)
five
Hour
Ago
,
_
:=
time
.
ParseDuration
(
"-5h"
)
expected
:=
now
.
Add
(
five
Hour
Ago
)
res
,
err
:=
tr
.
From
Unix
()
res
,
err
:=
tr
.
From
Time
()
So
(
err
,
ShouldBeNil
)
So
(
res
,
ShouldAlmost
Equal
,
expected
.
Unix
())
So
(
res
.
Unix
(),
Should
Equal
,
expected
.
Unix
())
})
Convey
(
"now-10m "
,
func
()
{
fiveMinAgo
,
_
:=
time
.
ParseDuration
(
"-10m"
)
expected
:=
now
.
Add
(
fiveMinAgo
)
res
,
err
:=
tr
.
To
Unix
()
res
,
err
:=
tr
.
To
Time
()
So
(
err
,
ShouldBeNil
)
So
(
res
,
ShouldAlmost
Equal
,
expected
.
Unix
())
So
(
res
.
Unix
(),
Should
Equal
,
expected
.
Unix
())
})
})
...
...
@@ -68,10 +68,10 @@ func TestTimeRange(t *testing.T) {
Now
:
now
,
}
_
,
err
=
tr
.
From
Unix
()
_
,
err
=
tr
.
From
Time
()
So
(
err
,
ShouldNotBeNil
)
_
,
err
=
tr
.
To
Unix
()
_
,
err
=
tr
.
To
Time
()
So
(
err
,
ShouldNotBeNil
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment