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
c01bbf20
Commit
c01bbf20
authored
Jul 24, 2019
by
kay delaney
Committed by
David
Jul 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Timerange: Fixes a bug where custom time ranges didn't respect UTC (#18248)
Closes #18170 Closes #18178
parent
459769af
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
6 deletions
+29
-6
packages/grafana-data/src/utils/datemath.ts
+12
-0
packages/grafana-ui/src/components/TimePicker/TimePicker.tsx
+12
-3
public/app/features/dashboard/components/DashNav/DashNavTimeControls.tsx
+5
-3
No files found.
packages/grafana-data/src/utils/datemath.ts
View file @
c01bbf20
...
...
@@ -5,6 +5,18 @@ import { TimeZone } from '../types';
const
units
:
DurationUnit
[]
=
[
'y'
,
'M'
,
'w'
,
'd'
,
'h'
,
'm'
,
's'
];
export
function
isMathString
(
text
:
string
|
DateTime
|
Date
):
boolean
{
if
(
!
text
)
{
return
false
;
}
if
(
typeof
text
===
'string'
&&
(
text
.
substring
(
0
,
3
)
===
'now'
||
text
.
includes
(
'||'
)))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* Parses different types input to a moment instance. There is a specific formatting language that can be used
* if text arg is string. See unit tests for examples.
...
...
packages/grafana-ui/src/components/TimePicker/TimePicker.tsx
View file @
c01bbf20
...
...
@@ -8,12 +8,13 @@ import { TimePickerPopover } from './TimePickerPopover';
import
{
ClickOutsideWrapper
}
from
'../ClickOutsideWrapper/ClickOutsideWrapper'
;
// Utils & Services
import
{
isDateTime
}
from
'@grafana/data'
;
import
{
isDateTime
,
DateTime
}
from
'@grafana/data'
;
import
{
rangeUtil
}
from
'@grafana/data'
;
import
{
rawToTimeRange
}
from
'./time'
;
// Types
import
{
TimeRange
,
TimeOption
,
TimeZone
,
TIME_FORMAT
,
SelectableValue
}
from
'@grafana/data'
;
import
{
isMathString
}
from
'@grafana/data/src/utils/datemath'
;
export
interface
Props
{
value
:
TimeRange
;
...
...
@@ -123,13 +124,21 @@ export class TimePicker extends PureComponent<Props, State> {
const
{
isCustomOpen
}
=
this
.
state
;
const
options
=
this
.
mapTimeOptionsToSelectableValues
(
selectTimeOptions
);
const
currentOption
=
options
.
find
(
item
=>
isTimeOptionEqualToTimeRange
(
item
.
value
,
value
));
const
rangeString
=
rangeUtil
.
describeTimeRange
(
value
.
raw
);
const
isUTC
=
timeZone
===
'utc'
;
const
adjustedTime
=
(
time
:
DateTime
)
=>
(
isUTC
?
time
.
utc
()
:
time
.
local
())
||
null
;
const
adjustedTimeRange
=
{
to
:
isMathString
(
value
.
raw
.
to
)
?
value
.
raw
.
to
:
adjustedTime
(
value
.
to
),
from
:
isMathString
(
value
.
raw
.
from
)
?
value
.
raw
.
from
:
adjustedTime
(
value
.
from
),
};
const
rangeString
=
rangeUtil
.
describeTimeRange
(
adjustedTimeRange
);
const
label
=
(
<>
{
isCustomOpen
&&
<
span
>
Custom time range
</
span
>
}
{
!
isCustomOpen
&&
<
span
>
{
rangeString
}
</
span
>
}
{
timeZone
===
'utc'
&&
<
span
className=
"time-picker-utc"
>
UTC
</
span
>
}
{
isUTC
&&
<
span
className=
"time-picker-utc"
>
UTC
</
span
>
}
</>
);
const
isAbsolute
=
isDateTime
(
value
.
raw
.
to
);
...
...
public/app/features/dashboard/components/DashNav/DashNavTimeControls.tsx
View file @
c01bbf20
// Libaries
import
React
,
{
Component
}
from
'react'
;
import
{
toUtc
}
from
'@grafana/data'
;
import
{
toUtc
,
dateMath
}
from
'@grafana/data'
;
// Types
import
{
DashboardModel
}
from
'../../state'
;
...
...
@@ -61,9 +61,11 @@ export class DashNavTimeControls extends Component<Props> {
const
panel
=
dashboard
.
timepicker
;
const
hasDelay
=
panel
.
nowDelay
&&
timeRange
.
raw
.
to
===
'now'
;
const
adjustedFrom
=
dateMath
.
isMathString
(
timeRange
.
raw
.
from
)
?
timeRange
.
raw
.
from
:
timeRange
.
from
;
const
adjustedTo
=
dateMath
.
isMathString
(
timeRange
.
raw
.
to
)
?
timeRange
.
raw
.
to
:
timeRange
.
to
;
const
nextRange
=
{
from
:
timeRange
.
raw
.
f
rom
,
to
:
hasDelay
?
'now-'
+
panel
.
nowDelay
:
timeRange
.
raw
.
t
o
,
from
:
adjustedF
rom
,
to
:
hasDelay
?
'now-'
+
panel
.
nowDelay
:
adjustedT
o
,
};
this
.
timeSrv
.
setTime
(
nextRange
);
...
...
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