Chore: Type improvements (#93267)
* some type fixes + ignore graveyard folder * few more fixes * remove comment * ignore global styles * few more type fixes
This commit is contained in:
@@ -2,7 +2,15 @@ import { includes, isDate } from 'lodash';
|
||||
|
||||
import { TimeZone } from '../types/time';
|
||||
|
||||
import { DateTime, dateTime, dateTimeForTimeZone, DurationUnit, isDateTime, ISO_8601 } from './moment_wrapper';
|
||||
import {
|
||||
DateTime,
|
||||
dateTime,
|
||||
dateTimeAsMoment,
|
||||
dateTimeForTimeZone,
|
||||
DurationUnit,
|
||||
isDateTime,
|
||||
ISO_8601,
|
||||
} from './moment_wrapper';
|
||||
|
||||
const units: DurationUnit[] = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'Q'];
|
||||
|
||||
@@ -51,10 +59,10 @@ export function parse(
|
||||
// We got some non string which is not a moment nor Date. TS should be able to check for that but not always.
|
||||
return undefined;
|
||||
} else {
|
||||
let time;
|
||||
let time: DateTime;
|
||||
let mathString = '';
|
||||
let index;
|
||||
let parseString;
|
||||
let index = -1;
|
||||
let parseString = '';
|
||||
|
||||
if (text.substring(0, 3) === 'now') {
|
||||
time = dateTimeForTimeZone(timezone);
|
||||
@@ -104,10 +112,9 @@ export function isValid(text: string | DateTime): boolean {
|
||||
* @param time
|
||||
* @param roundUp If true it will round the time to endOf time unit, otherwise to startOf time unit.
|
||||
*/
|
||||
// TODO: Had to revert Andrejs `time: moment.Moment` to `time: any`
|
||||
export function parseDateMath(
|
||||
mathString: string,
|
||||
time: any,
|
||||
time: DateTime,
|
||||
roundUp?: boolean,
|
||||
fiscalYearStartMonth = 0
|
||||
): DateTime | undefined {
|
||||
@@ -187,21 +194,21 @@ export function parseDateMath(
|
||||
return result;
|
||||
}
|
||||
|
||||
export function roundToFiscal(fyStartMonth: number, dateTime: any, unit: string, roundUp: boolean | undefined) {
|
||||
export function roundToFiscal(fyStartMonth: number, dateTime: DateTime, unit: string, roundUp: boolean | undefined) {
|
||||
switch (unit) {
|
||||
case 'y':
|
||||
if (roundUp) {
|
||||
roundToFiscal(fyStartMonth, dateTime, unit, false).add(11, 'M').endOf('M');
|
||||
roundToFiscal(fyStartMonth, dateTime, unit, false)?.add(11, 'M').endOf('M');
|
||||
} else {
|
||||
dateTime.subtract((dateTime.month() - fyStartMonth + 12) % 12, 'M').startOf('M');
|
||||
dateTime.subtract((dateTimeAsMoment(dateTime).month() - fyStartMonth + 12) % 12, 'M').startOf('M');
|
||||
}
|
||||
return dateTime;
|
||||
case 'Q':
|
||||
if (roundUp) {
|
||||
roundToFiscal(fyStartMonth, dateTime, unit, false).add(2, 'M').endOf('M');
|
||||
roundToFiscal(fyStartMonth, dateTime, unit, false)?.add(2, 'M').endOf('M');
|
||||
} else {
|
||||
// why + 12? to ensure this number is always a positive offset from fyStartMonth
|
||||
dateTime.subtract((dateTime.month() - fyStartMonth + 12) % 3, 'M').startOf('M');
|
||||
dateTime.subtract((dateTimeAsMoment(dateTime).month() - fyStartMonth + 12) % 3, 'M').startOf('M');
|
||||
}
|
||||
return dateTime;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user