// 距离值归一化为米/公里展示结构
|
export const normalizeDistanceKm = (value: any) => {
|
const num = Number(value);
|
if (Number.isNaN(num)) {
|
return null;
|
}
|
if (num >= 1000) {
|
return { value: Number((num / 1000).toFixed(1)), unit: 'km' as const };
|
}
|
return { value: Math.max(0, Math.round(num)), unit: 'm' as const };
|
};
|
|
// 时长值归一化为秒
|
export const normalizeDurationSeconds = (value: any) => {
|
const num = Number(value);
|
if (Number.isNaN(num)) {
|
return null;
|
}
|
return Math.round(num);
|
};
|
|
// 剩余时长展示(begin-route):分钟按向下截断,秒按四舍五入
|
export const formatRemainingDurationDisplay = (value: any) => {
|
const num = Number(value);
|
if (Number.isNaN(num)) {
|
return { value: 0, unit: '分钟' as const };
|
}
|
if (num < 60) {
|
return { value: Math.max(0, Math.round(num)), unit: '秒' as const };
|
}
|
return { value: Math.max(0, Math.floor(num / 60)), unit: '分钟' as const };
|
};
|