-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixes for build * fix time view
- Loading branch information
Showing
9 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export enum TIME_IN_SEC { | ||
minute = 60, | ||
hour = 60 * minute, | ||
day = 24 * hour, | ||
week = 7 * day, | ||
month = 4 * week, | ||
year = 12 * month, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { TIME_IN_SEC } from '@/enums' | ||
import { i18n } from '@/localization' | ||
import { duration } from '@distributedlab/tools' | ||
|
||
export const humanizeTime = (seconds: number): string => { | ||
const { t } = i18n.global | ||
const durationInSeconds = duration(seconds, 'seconds') | ||
|
||
if (seconds >= TIME_IN_SEC.year) { | ||
const timeAsYears = durationInSeconds.asYears | ||
return timeAsYears > 1 | ||
? t('time.years', { duration: timeAsYears }) | ||
: t('time.year', { duration: timeAsYears }) | ||
} | ||
if (seconds >= TIME_IN_SEC.month) { | ||
const timeAsMonths = durationInSeconds.asMonths | ||
return timeAsMonths > 1 | ||
? t('time.months', { duration: timeAsMonths }) | ||
: t('time.month', { duration: timeAsMonths }) | ||
} | ||
if (seconds >= TIME_IN_SEC.day) { | ||
const timeAsDays = durationInSeconds.asDays | ||
return timeAsDays > 1 | ||
? t('time.days', { duration: timeAsDays }) | ||
: t('time.day', { duration: timeAsDays }) | ||
} | ||
if (seconds >= TIME_IN_SEC.hour) { | ||
const timeAsHours = durationInSeconds.asHours | ||
return timeAsHours > 1 | ||
? t('time.hours', { duration: timeAsHours }) | ||
: t('time.hour', { duration: timeAsHours }) | ||
} | ||
if (seconds >= TIME_IN_SEC.minute) { | ||
const timeAsMinutes = durationInSeconds.asMinutes | ||
return timeAsMinutes > 1 | ||
? t('time.minutes', { duration: timeAsMinutes }) | ||
: t('time.minute', { duration: timeAsMinutes }) | ||
} | ||
return seconds > 1 | ||
? t('time.seconds', { duration: seconds }) | ||
: t('time.second', { duration: seconds }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters