mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Allow to configure roundUp in date helper of url drilldown (#137874)
This commit is contained in:
parent
c5391dc253
commit
3d5632310b
3 changed files with 11 additions and 2 deletions
|
@ -46,7 +46,8 @@ a|Format dates. Supports relative dates expressions (for example, "now-15d"). R
|
|||
Example:
|
||||
|
||||
`{{date event.from “YYYY MM DD”}}` +
|
||||
`{{date “now-15”}}`
|
||||
`{{date “now-15d”}}` +
|
||||
`{{date “now/d” roundUp=true}}`
|
||||
|
||||
|formatNumber
|
||||
a|Format numbers. Numbers can be formatted to look like currency, percentages, times or numbers with decimal places, thousands, and abbreviations.
|
||||
|
|
|
@ -49,12 +49,13 @@ handlebars.registerHelper(
|
|||
|
||||
handlebars.registerHelper('date', (...args) => {
|
||||
const values = args.slice(0, -1) as [string | Date, string | undefined];
|
||||
const { hash } = args.slice(-1)[0] as Handlebars.HelperOptions;
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [date, format] = values;
|
||||
if (typeof date === 'undefined') throw new Error(`[date]: unknown variable`);
|
||||
let momentDate: Moment | undefined;
|
||||
if (typeof date === 'string') {
|
||||
momentDate = dateMath.parse(date);
|
||||
momentDate = dateMath.parse(date, { roundUp: hash.roundUp === true });
|
||||
if (!momentDate || !momentDate.isValid()) {
|
||||
const ts = Number(date);
|
||||
if (!Number.isNaN(ts)) {
|
||||
|
|
|
@ -108,6 +108,13 @@ describe('date helper', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('can configure roundUp for dateMath', async () => {
|
||||
const url = 'https://elastic.co/from={{date from}}&to={{date to roundUp=true}}';
|
||||
expect(await compile(url, { from: 'now/d', to: 'now/d' })).toMatchInlineSnapshot(
|
||||
`"https://elastic.co/from=2020-08-18T00:00:00.000Z&to=2020-08-18T23:59:59.999Z"`
|
||||
);
|
||||
});
|
||||
|
||||
test('can use format', async () => {
|
||||
const url = 'https://elastic.co/{{date time "dddd, MMMM Do YYYY, h:mm:ss a"}}';
|
||||
expect(await compile(url, { time: 'now' })).toMatchInlineSnapshot(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue