Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prettyInterval converted to TS #1920

Merged
merged 6 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { prettyInterval } from './pretty_interval';

const IS_NOT_PAUSED = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -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}`;
}
};