我无法按照 start [开始时间] 对时间日志进行 排序。
const tasks = dv.current().file.lists.map(task => {
const timeParts = task.text.split(' - ');
const start = new Date(`1970-01-01T${timeParts[0]}`).getTime(); // 获取start时间对应的时间戳
const endTime = timeParts[1].split(' ')[0]; // 获取 - 到空格之间的时间作为end时间
const end = new Date(`1970-01-01T${endTime}`).getTime();
const taskStartIndex = task.text.indexOf('[[');
const taskEndIndex = task.text.indexOf(']]', taskStartIndex) + 2;
const taskContent = task.text.substring(taskStartIndex, taskEndIndex);
const subStartIndex = task.text.indexOf('[[', taskEndIndex);
const subEndIndex = task.text.indexOf(']]', subStartIndex) + 2;
const subContent = task.text.substring(subStartIndex, subEndIndex);
const description = task.text.substring(subEndIndex).trim();
const span = (end - start) / (1000 * 60 * 60); // 转换为小时
return {
description: description,
span: span.toFixed(2), // 保留两位小数
start: timeParts[0],
end: endTime,
task: taskContent,
sub: subContent
};
});
// 按照start时间戳对任务数组进行排序
tasks.sort((a, b) => new Date(`1970-01-01T${a.start}`).getTime() - new Date(`1970-01-01T${b.start}`).getTime());
dv.table(
[ "Start", "End", "Span", "Task", "Sub", "Description"],
tasks.map(task => [
task.start,
task.end,
task.span,
task.task,
task.sub,
task.description
])
);