diff --git a/CHANGELOG.md b/CHANGELOG.md index 932143a33c6..56e17a9eeb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) +- Converted `pretty_interval` to TS ([#1920](https://github.com/elastic/eui/pull/1920)) - Converted `relative_options` to TS ([#1921](https://github.com/elastic/eui/pull/1921)) **Bug fixes** diff --git a/src/components/date_picker/super_date_picker/pretty_interval.test.js b/src/components/date_picker/super_date_picker/pretty_interval.test.ts similarity index 99% rename from src/components/date_picker/super_date_picker/pretty_interval.test.js rename to src/components/date_picker/super_date_picker/pretty_interval.test.ts index 1eb067fdb92..e44138d3cf3 100644 --- a/src/components/date_picker/super_date_picker/pretty_interval.test.js +++ b/src/components/date_picker/super_date_picker/pretty_interval.test.ts @@ -1,4 +1,3 @@ - import { prettyInterval } from './pretty_interval'; const IS_NOT_PAUSED = false; diff --git a/src/components/date_picker/super_date_picker/pretty_interval.js b/src/components/date_picker/super_date_picker/pretty_interval.ts similarity index 70% rename from src/components/date_picker/super_date_picker/pretty_interval.js rename to src/components/date_picker/super_date_picker/pretty_interval.ts index fe8db73a50a..9530d7614e1 100644 --- a/src/components/date_picker/super_date_picker/pretty_interval.js +++ b/src/components/date_picker/super_date_picker/pretty_interval.ts @@ -1,27 +1,27 @@ - const MS_IN_SECOND = 1000; const MS_IN_MINUTE = 60 * MS_IN_SECOND; const MS_IN_HOUR = 60 * MS_IN_MINUTE; const MS_IN_DAY = 24 * MS_IN_HOUR; -export function prettyInterval(isPaused, intervalInMs) { +export const prettyInterval = (isPaused: boolean, intervalInMs: number) => { + let units: string; if (isPaused || intervalInMs === 0) { return 'Off'; } else if (intervalInMs < MS_IN_MINUTE) { const intervalInSeconds = Math.round(intervalInMs / MS_IN_SECOND); - const units = intervalInSeconds > 1 ? 'seconds' : 'second'; + units = intervalInSeconds > 1 ? 'seconds' : 'second'; return `${intervalInSeconds} ${units}`; } else if (intervalInMs < MS_IN_HOUR) { const intervalInMinutes = Math.round(intervalInMs / MS_IN_MINUTE); - const units = intervalInMinutes > 1 ? 'minutes' : 'minute'; + units = intervalInMinutes > 1 ? 'minutes' : 'minute'; return `${intervalInMinutes} ${units}`; } else if (intervalInMs < MS_IN_DAY) { const intervalInHours = Math.round(intervalInMs / MS_IN_HOUR); - const units = intervalInHours > 1 ? 'hours' : 'hour'; + units = intervalInHours > 1 ? 'hours' : 'hour'; return `${intervalInHours} ${units}`; } const intervalInDays = Math.round(intervalInMs / MS_IN_DAY); - const units = intervalInDays > 1 ? 'days' : 'day'; + units = intervalInDays > 1 ? 'days' : 'day'; return `${intervalInDays} ${units}`; -} +};