mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[@kbn/datemath] improve types (#24671)
* [kbn-datemath][parseEsInterval] improve types slightly * [kbn-datemath][vis/leastCommonInterval] make types more precise * [ui/leastCommonInterval] fix bug in finding same types * add back valid test
This commit is contained in:
parent
fd4e63c5a9
commit
39be1afe1b
7 changed files with 58 additions and 26 deletions
34
packages/kbn-datemath/src/index.d.ts
vendored
34
packages/kbn-datemath/src/index.d.ts
vendored
|
@ -17,13 +17,29 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
declare module '@kbn/datemath' {
|
||||
const dateMath: {
|
||||
parse: any;
|
||||
unitsMap: any;
|
||||
units: string[];
|
||||
unitsAsc: string[];
|
||||
unitsDesc: string[];
|
||||
import moment from 'moment';
|
||||
export type Unit = 'ms' | 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'y';
|
||||
|
||||
declare const datemath: {
|
||||
unitsMap: {
|
||||
[k in Unit]: {
|
||||
weight: number;
|
||||
type: 'calendar' | 'fixed' | 'mixed';
|
||||
base: number;
|
||||
}
|
||||
};
|
||||
export default dateMath;
|
||||
}
|
||||
units: Unit[];
|
||||
unitsAsc: Unit[];
|
||||
unitsDesc: Unit[];
|
||||
|
||||
parse(
|
||||
input: string,
|
||||
options?: {
|
||||
roundUp?: boolean;
|
||||
forceNow?: boolean;
|
||||
momentInstance?: typeof moment;
|
||||
}
|
||||
): moment.Moment | undefined;
|
||||
};
|
||||
|
||||
export default datemath;
|
||||
|
|
|
@ -25,10 +25,10 @@ const unitsMap = {
|
|||
m: { weight: 3, type: 'mixed', base: 1000 * 60 },
|
||||
h: { weight: 4, type: 'mixed', base: 1000 * 60 * 60 },
|
||||
d: { weight: 5, type: 'mixed', base: 1000 * 60 * 60 * 24 },
|
||||
w: { weight: 6, type: 'calendar' },
|
||||
M: { weight: 7, type: 'calendar' },
|
||||
w: { weight: 6, type: 'calendar', base: NaN },
|
||||
M: { weight: 7, type: 'calendar', base: NaN },
|
||||
// q: { weight: 8, type: 'calendar' }, // TODO: moment duration does not support quarter
|
||||
y: { weight: 9, type: 'calendar' },
|
||||
y: { weight: 9, type: 'calendar', base: NaN },
|
||||
};
|
||||
const units = Object.keys(unitsMap).sort((a, b) => unitsMap[b].weight - unitsMap[a].weight);
|
||||
const unitsDesc = [...units];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue