Fixed crash on android in view sessions
- time formatting wasn't defined - fixes issue 6
This commit is contained in:
parent
6ed968a8c5
commit
96db91f027
|
@ -1,37 +1,58 @@
|
||||||
|
|
||||||
import moment from 'moment/min/moment-with-locales';
|
|
||||||
import {i18n} from './i18n';
|
import {i18n} from './i18n';
|
||||||
|
|
||||||
|
const locale = i18n.locale;
|
||||||
|
|
||||||
|
const fullDateFormat = Intl.DateTimeFormat(locale, {
|
||||||
|
weekday: "short",
|
||||||
|
year: "2-digit",
|
||||||
|
month: "2-digit",
|
||||||
|
day: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
});
|
||||||
|
const timeFormatter = Intl.DateTimeFormat(locale, {
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Doesn't work on android yet (so use full time for now instead of relative time)
|
||||||
|
const relativeTimeFormatter = 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 - new Date()) / 1000
|
||||||
|
for (let i = 0; i < DIVISIONS.length; i++) {
|
||||||
|
const division = DIVISIONS[i]
|
||||||
|
if (Math.abs(duration) < division.amount) {
|
||||||
|
const suffix = (division.name === "days") ? ", " + timeFormatter.format(date) : "";
|
||||||
|
return relativeTimeFormatter.format(Math.round(duration), division.name) + suffix
|
||||||
|
}
|
||||||
|
duration /= division.amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
function timeSince(timeStamp) {
|
function timeSince(timeStamp) {
|
||||||
moment.locale(i18n.locale);
|
|
||||||
|
|
||||||
const now = Math.floor((new Date()).getTime() / 1000);
|
const now = Math.floor((new Date()).getTime() / 1000);
|
||||||
const secondsPast = now - timeStamp;
|
const secondsPassed = now - timeStamp;
|
||||||
if (secondsPast <= 6 * 3600) {
|
const daysPassed = secondsPassed / 60 / 60 / 24;
|
||||||
return moment().seconds(-secondsPast).fromNow();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
const timeStampDate = new Date(timeStamp * 1000);
|
const timeStampDate = new Date(timeStamp * 1000);
|
||||||
const dateNow = new Date();
|
//if (daysPassed < 2)
|
||||||
|
// return formatTimeAgo(timeStampDate);
|
||||||
const timeStampMoment = moment.unix(timeStamp);
|
//else
|
||||||
|
return fullDateFormat.format(timeStampDate);
|
||||||
let dateStr = "";
|
|
||||||
|
|
||||||
if (timeStampDate.getDate() == dateNow.getDate())
|
|
||||||
dateStr = "Heute, " + timeStampMoment.format("HH:mm");
|
|
||||||
else if (timeStampDate.getDate() + 1 == dateNow.getDate())
|
|
||||||
dateStr = "Gestern, " + timeStampMoment.format("HH:mm");
|
|
||||||
else {
|
|
||||||
dateStr = timeStampMoment.format("llll");
|
|
||||||
}
|
|
||||||
return dateStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const toTimeStr = seconds => {
|
const toTimeStr = seconds => {
|
||||||
let minuteStr = String(Math.floor(seconds / 60));
|
let minuteStr = String(Math.floor(seconds / 60));
|
||||||
if (minuteStr.length < 2)
|
if (minuteStr.length < 2)
|
||||||
|
@ -42,5 +63,4 @@ const toTimeStr = seconds => {
|
||||||
return minuteStr + ":" + secondStr;
|
return minuteStr + ":" + secondStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export { toTimeStr, timeSince };
|
export { toTimeStr, timeSince };
|
||||||
|
|
|
@ -180,7 +180,7 @@ async function getFullData(swimTrackerHost, analysisSettings) {
|
||||||
const da = new DataAnalysis();
|
const da = new DataAnalysis();
|
||||||
e.analysis = da.analyze(analysisSettings, e.startTime, e.values);
|
e.analysis = da.analyze(analysisSettings, e.startTime, e.values);
|
||||||
}
|
}
|
||||||
console.log("full data", parsed);
|
//console.log("full data", parsed);
|
||||||
return parsed.reverse();
|
return parsed.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ class LastSessionsView extends React.Component {
|
||||||
textFirstLine={timeSince(data.item.startTime)}
|
textFirstLine={timeSince(data.item.startTime)}
|
||||||
laps={(data.item.analysis.peaks.size / this.props.peaksPerLap).toFixed(1)}
|
laps={(data.item.analysis.peaks.size / this.props.peaksPerLap).toFixed(1)}
|
||||||
momentum={Math.trunc(data.item.analysis.totalMomentum * this.props.kgFactor / 10 / 60)}
|
momentum={Math.trunc(data.item.analysis.totalMomentum * this.props.kgFactor / 10 / 60)}
|
||||||
activeTime={data.item.analysis.activeTime} />
|
activeTime={Math.round(data.item.analysis.activeTime / 60, 0)} />
|
||||||
)}
|
)}
|
||||||
renderHiddenItem={(data, rowMap) => <SessionCardBehindSwipe onDelete={() => { deleteSession(data.item.name) }} />}
|
renderHiddenItem={(data, rowMap) => <SessionCardBehindSwipe onDelete={() => { deleteSession(data.item.name) }} />}
|
||||||
leftOpenValue={0}
|
leftOpenValue={0}
|
||||||
|
|
Loading…
Reference in New Issue