mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
show localized elapsed time
This commit is contained in:
@@ -31,7 +31,7 @@ import { FormLoader, SectionContent, useLayoutTitle } from 'components';
|
|||||||
import { useI18nContext } from 'i18n/i18n-react';
|
import { useI18nContext } from 'i18n/i18n-react';
|
||||||
|
|
||||||
const Version = () => {
|
const Version = () => {
|
||||||
const { LL } = useI18nContext();
|
const { LL, locale } = useI18nContext();
|
||||||
const [restarting, setRestarting] = useState<boolean>(false);
|
const [restarting, setRestarting] = useState<boolean>(false);
|
||||||
const [openInstallDialog, setOpenInstallDialog] = useState<boolean>(false);
|
const [openInstallDialog, setOpenInstallDialog] = useState<boolean>(false);
|
||||||
const [usingDevVersion, setUsingDevVersion] = useState<boolean>(false);
|
const [usingDevVersion, setUsingDevVersion] = useState<boolean>(false);
|
||||||
@@ -92,6 +92,30 @@ const Version = () => {
|
|||||||
}
|
}
|
||||||
}, [latestVersion, latestDevVersion]);
|
}, [latestVersion, latestDevVersion]);
|
||||||
|
|
||||||
|
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });
|
||||||
|
const DIVISIONS = [
|
||||||
|
{ amount: 60, name: 'seconds' },
|
||||||
|
{ amount: 60, name: 'minutes' },
|
||||||
|
{ amount: 24, name: 'hours' },
|
||||||
|
{ amount: 7, name: 'days' },
|
||||||
|
{ amount: 4.34524, name: 'weeks' },
|
||||||
|
{ amount: 12, name: 'months' },
|
||||||
|
{ amount: Number.POSITIVE_INFINITY, name: 'years' }
|
||||||
|
];
|
||||||
|
function formatTimeAgo(date) {
|
||||||
|
let duration = (date.getTime() - new Date().getTime()) / 1000;
|
||||||
|
for (let i = 0; i < DIVISIONS.length; i++) {
|
||||||
|
const division = DIVISIONS[i];
|
||||||
|
if (Math.abs(duration) < division.amount) {
|
||||||
|
return rtf.format(
|
||||||
|
Math.round(duration),
|
||||||
|
division.name as Intl.RelativeTimeFormatUnit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
duration /= division.amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const getBinURL = () => {
|
const getBinURL = () => {
|
||||||
if (!internetLive) {
|
if (!internetLive) {
|
||||||
return '';
|
return '';
|
||||||
@@ -274,7 +298,7 @@ const Version = () => {
|
|||||||
</Grid>
|
</Grid>
|
||||||
<Grid size={{ xs: 8, md: 10 }}>
|
<Grid size={{ xs: 8, md: 10 }}>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
disabled
|
disabled={!isDev}
|
||||||
control={
|
control={
|
||||||
<Checkbox
|
<Checkbox
|
||||||
sx={{
|
sx={{
|
||||||
@@ -284,12 +308,17 @@ const Version = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
slotProps={{
|
||||||
|
typography: {
|
||||||
|
color: 'grey'
|
||||||
|
}
|
||||||
|
}}
|
||||||
checked={!isDev}
|
checked={!isDev}
|
||||||
label={LL.STABLE()}
|
label={LL.STABLE()}
|
||||||
sx={{ '& .MuiSvgIcon-root': { fontSize: 18 } }}
|
sx={{ '& .MuiSvgIcon-root': { fontSize: 16 } }}
|
||||||
/>
|
/>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
disabled
|
disabled={isDev}
|
||||||
control={
|
control={
|
||||||
<Checkbox
|
<Checkbox
|
||||||
sx={{
|
sx={{
|
||||||
@@ -299,9 +328,14 @@ const Version = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
slotProps={{
|
||||||
|
typography: {
|
||||||
|
color: 'grey'
|
||||||
|
}
|
||||||
|
}}
|
||||||
checked={isDev}
|
checked={isDev}
|
||||||
label={LL.DEVELOPMENT()}
|
label={LL.DEVELOPMENT()}
|
||||||
sx={{ '& .MuiSvgIcon-root': { fontSize: 18 } }}
|
sx={{ '& .MuiSvgIcon-root': { fontSize: 16 } }}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -332,14 +366,7 @@ const Version = () => {
|
|||||||
{latestVersion.published_at && (
|
{latestVersion.published_at && (
|
||||||
<Typography component="span" variant="caption">
|
<Typography component="span" variant="caption">
|
||||||
(
|
(
|
||||||
{LL.DAYS_AGO(
|
{formatTimeAgo(new Date(latestVersion.published_at))})
|
||||||
Math.floor(
|
|
||||||
(Date.now() -
|
|
||||||
new Date(latestVersion.published_at).getTime()) /
|
|
||||||
(1000 * 60 * 60 * 24)
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
)
|
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
{!usingDevVersion && showButtons(false)}
|
{!usingDevVersion && showButtons(false)}
|
||||||
@@ -357,14 +384,7 @@ const Version = () => {
|
|||||||
{latestDevVersion.published_at && (
|
{latestDevVersion.published_at && (
|
||||||
<Typography component="span" variant="caption">
|
<Typography component="span" variant="caption">
|
||||||
(
|
(
|
||||||
{LL.DAYS_AGO(
|
{formatTimeAgo(new Date(latestDevVersion.published_at))})
|
||||||
Math.floor(
|
|
||||||
(Date.now() -
|
|
||||||
new Date(latestDevVersion.published_at).getTime()) /
|
|
||||||
(1000 * 60 * 60 * 24)
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
)
|
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
{showButtons(true)}
|
{showButtons(true)}
|
||||||
|
|||||||
Reference in New Issue
Block a user