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
9acb9990
Unverified
Commit
9acb9990
authored
Sep 07, 2020
by
Domas
Committed by
GitHub
Sep 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Elasticsearch: Fixes localized dates in index pattern (#27351)
Fixes #8403
parent
5402157c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
3 deletions
+36
-3
packages/grafana-data/src/datetime/moment_wrapper.ts
+4
-0
public/app/plugins/datasource/elasticsearch/index_pattern.ts
+6
-2
public/app/plugins/datasource/elasticsearch/specs/index_pattern.test.ts
+26
-1
No files found.
packages/grafana-data/src/datetime/moment_wrapper.ts
View file @
9acb9990
...
@@ -79,6 +79,10 @@ export const setLocale = (language: string) => {
...
@@ -79,6 +79,10 @@ export const setLocale = (language: string) => {
moment
.
locale
(
language
);
moment
.
locale
(
language
);
};
};
export
const
getLocale
=
()
=>
{
return
moment
.
locale
();
};
export
const
getLocaleData
=
():
DateTimeLocale
=>
{
export
const
getLocaleData
=
():
DateTimeLocale
=>
{
return
moment
.
localeData
();
return
moment
.
localeData
();
};
};
...
...
public/app/plugins/datasource/elasticsearch/index_pattern.ts
View file @
9acb9990
...
@@ -9,11 +9,15 @@ const intervalMap: any = {
...
@@ -9,11 +9,15 @@ const intervalMap: any = {
};
};
export
class
IndexPattern
{
export
class
IndexPattern
{
private
dateLocale
=
'en'
;
constructor
(
private
pattern
:
any
,
private
interval
?:
string
)
{}
constructor
(
private
pattern
:
any
,
private
interval
?:
string
)
{}
getIndexForToday
()
{
getIndexForToday
()
{
if
(
this
.
interval
)
{
if
(
this
.
interval
)
{
return
toUtc
().
format
(
this
.
pattern
);
return
toUtc
()
.
locale
(
this
.
dateLocale
)
.
format
(
this
.
pattern
);
}
else
{
}
else
{
return
this
.
pattern
;
return
this
.
pattern
;
}
}
...
@@ -35,7 +39,7 @@ export class IndexPattern {
...
@@ -35,7 +39,7 @@ export class IndexPattern {
const
indexList
=
[];
const
indexList
=
[];
while
(
start
.
valueOf
()
<=
endEpoch
)
{
while
(
start
.
valueOf
()
<=
endEpoch
)
{
indexList
.
push
(
start
.
format
(
this
.
pattern
));
indexList
.
push
(
start
.
locale
(
this
.
dateLocale
).
format
(
this
.
pattern
));
start
.
add
(
1
,
intervalInfo
.
amount
);
start
.
add
(
1
,
intervalInfo
.
amount
);
}
}
...
...
public/app/plugins/datasource/elasticsearch/specs/index_pattern.test.ts
View file @
9acb9990
///<amd-dependency path="test/specs/helpers" name="helpers" />
///<amd-dependency path="test/specs/helpers" name="helpers" />
import
{
IndexPattern
}
from
'../index_pattern'
;
import
{
IndexPattern
}
from
'../index_pattern'
;
import
{
toUtc
}
from
'@grafana/data'
;
import
{
toUtc
,
getLocale
,
setLocale
}
from
'@grafana/data'
;
describe
(
'IndexPattern'
,
()
=>
{
describe
(
'IndexPattern'
,
()
=>
{
const
originalLocale
=
getLocale
();
afterEach
(()
=>
setLocale
(
originalLocale
));
describe
(
'when getting index for today'
,
()
=>
{
describe
(
'when getting index for today'
,
()
=>
{
test
(
'should return correct index name'
,
()
=>
{
test
(
'should return correct index name'
,
()
=>
{
const
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'Daily'
);
const
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'Daily'
);
...
@@ -11,6 +14,17 @@ describe('IndexPattern', () => {
...
@@ -11,6 +14,17 @@ describe('IndexPattern', () => {
expect
(
pattern
.
getIndexForToday
()).
toBe
(
expected
);
expect
(
pattern
.
getIndexForToday
()).
toBe
(
expected
);
});
});
test
(
'should format date using western arabic numerals regardless of locale'
,
()
=>
{
setLocale
(
'ar_SA'
);
// saudi-arabic, formatting for YYYY.MM.DD looks like "٢٠٢٠.٠٩.٠٣"
const
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'Daily'
);
const
expected
=
'asd-'
+
toUtc
()
.
locale
(
'en'
)
.
format
(
'YYYY.MM.DD'
);
expect
(
pattern
.
getIndexForToday
()).
toBe
(
expected
);
});
});
});
describe
(
'when getting index list for time range'
,
()
=>
{
describe
(
'when getting index list for time range'
,
()
=>
{
...
@@ -33,6 +47,17 @@ describe('IndexPattern', () => {
...
@@ -33,6 +47,17 @@ describe('IndexPattern', () => {
expect
(
pattern
.
getIndexList
(
from
,
to
)).
toEqual
(
expected
);
expect
(
pattern
.
getIndexList
(
from
,
to
)).
toEqual
(
expected
);
});
});
test
(
'should format date using western arabic numerals regardless of locale'
,
()
=>
{
setLocale
(
'ar_SA'
);
// saudi-arabic, formatting for YYYY.MM.DD looks like "٢٠٢٠.٠٩.٠٣"
const
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'Daily'
);
const
from
=
new
Date
(
1432940523000
);
const
to
=
new
Date
(
1433153106000
);
const
expected
=
[
'asd-2015.05.29'
,
'asd-2015.05.30'
,
'asd-2015.05.31'
,
'asd-2015.06.01'
];
expect
(
pattern
.
getIndexList
(
from
,
to
)).
toEqual
(
expected
);
});
});
});
});
});
});
});
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