Skip to content

Commit

Permalink
opted for this strategy
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
  • Loading branch information
kavilla committed Apr 26, 2024
1 parent 575fcd8 commit a94fb05
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
},
"dependencies": {
"@aws-crypto/client-node": "^3.1.1",
"@elastic/datemath": "link:packages/opensearch-datemath",
"@elastic/datemath": "5.0.3",
"@elastic/eui": "npm:@opensearch-project/oui@1.5.1",
"@elastic/good": "^9.0.1-kibana3",
"@elastic/numeral": "npm:@amoo-miki/numeral@2.6.0",
Expand All @@ -154,6 +154,7 @@
"@hapi/vision": "^6.1.0",
"@hapi/wreck": "^17.1.0",
"@opensearch-project/opensearch": "^2.6.0",
"@opensearch/datemath": "5.0.3",
"@osd/ace": "1.0.0",
"@osd/analytics": "1.0.0",
"@osd/apm-config-loader": "1.0.0",
Expand Down
44 changes: 22 additions & 22 deletions packages/opensearch-datemath/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ describe('dateMath', function () {
});

it('should return a moment if passed a date', function () {
expect(dateMath.parse(date).format(format)).to.eql(mmnt.format(format));
expect(dateMath.parse(date)!.format(format)).to.eql(mmnt.format(format));
});

it('should return a moment if passed an ISO8601 string', function () {
expect(dateMath.parse(string).format(format)).to.eql(mmnt.format(format));
expect(dateMath.parse(string)!.format(format)).to.eql(mmnt.format(format));
});

it('should return the current time when parsing now', function () {
expect(dateMath.parse('now').format(format)).to.eql(now.format(format));
expect(dateMath.parse('now')!.format(format)).to.eql(now.format(format));
});

it('should use the forceNow parameter when parsing now', function () {
expect(dateMath.parse('now', { forceNow: anchoredDate }).valueOf()).to.eql(unix);
expect(dateMath.parse('now', { forceNow: anchoredDate })!.valueOf()).to.eql(unix);
});
});

Expand All @@ -158,17 +158,17 @@ describe('dateMath', function () {
const thenEx = `${anchor}||-${len}${span}`;

it('should return ' + len + span + ' ago', function () {
const parsed = dateMath.parse(nowEx).format(format);
const parsed = dateMath.parse(nowEx)!.format(format);
expect(parsed).to.eql(now.subtract(len, span).format(format));
});

it('should return ' + len + span + ' before ' + anchor, function () {
const parsed = dateMath.parse(thenEx).format(format);
const parsed = dateMath.parse(thenEx)!.format(format);
expect(parsed).to.eql(anchored.subtract(len, span).format(format));
});

it('should return ' + len + span + ' before forceNow', function () {
const parsed = dateMath.parse(nowEx, { forceNow: anchoredDate }).valueOf();
const parsed = dateMath.parse(nowEx, { forceNow: anchoredDate })!.valueOf();
expect(parsed).to.eql(anchored.subtract(len, span).valueOf());
});
});
Expand All @@ -195,17 +195,17 @@ describe('dateMath', function () {
const thenEx = `${anchor}||+${len}${span}`;

it('should return ' + len + span + ' from now', function () {
expect(dateMath.parse(nowEx).format(format)).to.eql(now.add(len, span).format(format));
expect(dateMath.parse(nowEx)!.format(format)).to.eql(now.add(len, span).format(format));
});

it('should return ' + len + span + ' after ' + anchor, function () {
expect(dateMath.parse(thenEx).format(format)).to.eql(
expect(dateMath.parse(thenEx)!.format(format)).to.eql(
anchored.add(len, span).format(format)
);
});

it('should return ' + len + span + ' after forceNow', function () {
expect(dateMath.parse(nowEx, { forceNow: anchoredDate }).valueOf()).to.eql(
expect(dateMath.parse(nowEx, { forceNow: anchoredDate })!.valueOf()).to.eql(
anchored.add(len, span).valueOf()
);
});
Expand All @@ -229,26 +229,26 @@ describe('dateMath', function () {

spans.forEach((span) => {
it(`should round now to the beginning of the ${span}`, function () {
expect(dateMath.parse('now/' + span).format(format)).to.eql(
expect(dateMath.parse('now/' + span)!.format(format)).to.eql(
now.startOf(span).format(format)
);
});

it(`should round now to the beginning of forceNow's ${span}`, function () {
expect(dateMath.parse('now/' + span, { forceNow: anchoredDate }).valueOf()).to.eql(
expect(dateMath.parse('now/' + span, { forceNow: anchoredDate })!.valueOf()).to.eql(
anchored.startOf(span).valueOf()
);
});

it(`should round now to the end of the ${span}`, function () {
expect(dateMath.parse('now/' + span, { roundUp: true }).format(format)).to.eql(
expect(dateMath.parse('now/' + span, { roundUp: true })!.format(format)).to.eql(
now.endOf(span).format(format)
);
});

it(`should round now to the end of forceNow's ${span}`, function () {
expect(
dateMath.parse('now/' + span, { roundUp: true, forceNow: anchoredDate }).valueOf()
dateMath.parse('now/' + span, { roundUp: true, forceNow: anchoredDate })!.valueOf()
).to.eql(anchored.endOf(span).valueOf());
});
});
Expand All @@ -269,28 +269,28 @@ describe('dateMath', function () {
});

it('should round to the nearest second with 0 value', function () {
const val = dateMath.parse('now-0s/s').format(format);
const val = dateMath.parse('now-0s/s')!.format(format);
expect(val).to.eql(now.startOf('s').format(format));
});

it('should subtract 17s, rounded to the nearest second', function () {
const val = dateMath.parse('now-17s/s').format(format);
const val = dateMath.parse('now-17s/s')!.format(format);
expect(val).to.eql(now.startOf('s').subtract(17, 's').format(format));
});

it('should add 555ms, rounded to the nearest millisecond', function () {
const val = dateMath.parse('now+555ms/ms').format(format);
const val = dateMath.parse('now+555ms/ms')!.format(format);
expect(val).to.eql(now.add(555, 'ms').startOf('ms').format(format));
});

it('should subtract 555ms, rounded to the nearest second', function () {
const val = dateMath.parse('now-555ms/s').format(format);
const val = dateMath.parse('now-555ms/s')!.format(format);
expect(val).to.eql(now.subtract(555, 'ms').startOf('s').format(format));
});

it('should round weeks to Sunday by default', function () {
const val = dateMath.parse('now-1w/w');
expect(val.isoWeekday()).to.eql(7);
expect(val!.isoWeekday()).to.eql(7);
});

it('should round weeks based on the passed moment locale start of week setting', function () {
Expand All @@ -300,7 +300,7 @@ describe('dateMath', function () {
week: { dow: 2 },
});
const val = dateMath.parse('now-1w/w', { momentInstance: m });
expect(val.isoWeekday()).to.eql(2);
expect(val!.isoWeekday()).to.eql(2);
});

it('should round up weeks based on the passed moment locale start of week setting', function () {
Expand All @@ -315,11 +315,11 @@ describe('dateMath', function () {
});
// The end of the range (rounding up) should be the last day of the week (so one day before)
// our start of the week, that's why 3 - 1
expect(val.isoWeekday()).to.eql(3 - 1);
expect(val!.isoWeekday()).to.eql(3 - 1);
});

it('should round relative to forceNow', function () {
const val = dateMath.parse('now-0s/s', { forceNow: anchoredDate }).valueOf();
const val = dateMath.parse('now-0s/s', { forceNow: anchoredDate })!.valueOf();
expect(val).to.eql(anchored.startOf('s').valueOf());
});

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/data_frames/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { SearchResponse } from 'elasticsearch';
import datemath from '@elastic/datemath';
import datemath from '@opensearch/datemath';
import { DATA_FRAME_TYPES, IDataFrame, IDataFrameWithAggs, PartialDataFrame } from './types';
import { IFieldType } from './fields';
import { IndexPatternFieldMap, IndexPatternSpec } from '../index_patterns';
Expand Down
9 changes: 6 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1486,9 +1486,12 @@
utility-types "^3.10.0"
uuid "^3.3.2"

"@elastic/datemath@link:packages/opensearch-datemath":
version "0.0.0"
uid ""
"@elastic/datemath@5.0.3":
version "5.0.3"
resolved "https://registry.yarnpkg.com/@elastic/datemath/-/datemath-5.0.3.tgz#7baccdab672b9a3ecb7fe8387580670936b58573"
integrity sha512-8Hbr1Uyjm5OcYBfEB60K7sCP6U3IXuWDaLaQmYv3UxgI4jqBWbakoemwWvsqPVUvnwEjuX6z7ghPZbefs8xiaA==
dependencies:
tslib "^1.9.3"

"@elastic/ecs-helpers@^1.1.0":
version "1.1.0"
Expand Down

0 comments on commit a94fb05

Please sign in to comment.