mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-11-15 23:13:12 +01:00
automatically remove null sub-entries from existing trackers
This commit is contained in:
parent
0ca60318f8
commit
d80bc764ce
1 changed files with 8 additions and 3 deletions
|
@ -34,7 +34,7 @@ export function loadTracker(json: string): Tracker {
|
|||
if (json) {
|
||||
try {
|
||||
let ret = JSON.parse(json);
|
||||
fixLegacyTimestamps(ret.entries);
|
||||
updateLegacyInfo(ret.entries);
|
||||
return ret;
|
||||
} catch (e) {
|
||||
console.log(`Failed to parse Tracker from ${json}`);
|
||||
|
@ -308,15 +308,20 @@ function unformatEditableTimestamp(formatted: string, settings: SimpleTimeTracke
|
|||
return moment(formatted, settings.editableTimestampFormat).toISOString();
|
||||
}
|
||||
|
||||
function fixLegacyTimestamps(entries: Entry[]): void {
|
||||
function updateLegacyInfo(entries: Entry[]): void {
|
||||
for (let entry of entries) {
|
||||
// in 0.1.8, timestamps were changed from unix to iso
|
||||
if (entry.startTime && !isNaN(+entry.startTime))
|
||||
entry.startTime = moment.unix(+entry.startTime).toISOString();
|
||||
if (entry.endTime && !isNaN(+entry.endTime))
|
||||
entry.endTime = moment.unix(+entry.endTime).toISOString();
|
||||
|
||||
// in 1.0.0, sub-entries were made optional
|
||||
if (entry.subEntries == null || !entry.subEntries.length)
|
||||
entry.subEntries = undefined;
|
||||
|
||||
if (entry.subEntries)
|
||||
fixLegacyTimestamps(entry.subEntries);
|
||||
updateLegacyInfo(entry.subEntries);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue