diff --git a/src/adminPage/adminSnapshots.js b/src/adminPage/adminSnapshots.js index 4e4057b..5272d27 100644 --- a/src/adminPage/adminSnapshots.js +++ b/src/adminPage/adminSnapshots.js @@ -24,8 +24,8 @@ async function manageSnapshots(snapshotTable) { snapshotTable.appendChild(snapshotsUL) sortedSnapshotFileNames.reverse(function (x, y) { - const timestampx = x.substring(x.lastIndexOf('-')+1, x.indexOf('.ttl')) - const timestampy = y.substring(y.lastIndexOf('-')+1, y.indexOf('.ttl')) + const timestampx = getTimestampFromSnapshot(x) + const timestampy = getTimestampFromSnapshot(y) return timestampx - timestampy; }) @@ -39,7 +39,7 @@ async function manageSnapshots(snapshotTable) { const timestampDiv = document.createElement('div') timestampDiv.setAttribute('class', 'timstampDiv') - const timestamp = sortedSnapshotFileNames[i].substring(sortedSnapshotFileNames[i].lastIndexOf('-') + 1, sortedSnapshotFileNames[i].indexOf('.ttl')) + const timestamp = getTimestampFromSnapshot(sortedSnapshotFileNames[i]) timestampDiv.textContent = (new Date(parseInt(timestamp))).toISOString() const userDiv = document.createElement('div') diff --git a/src/adminPage/snapshots/snapshot.js b/src/adminPage/snapshots/snapshot.js index d9018ab..0fae97c 100644 --- a/src/adminPage/snapshots/snapshot.js +++ b/src/adminPage/snapshots/snapshot.js @@ -48,8 +48,8 @@ async function createSnapshot(store, currentKG, nameOfSnapshot) { function deleteOlderSnapshots(store, snapshots, threshold) { snapshots.sort(function (x, y) { - const timestampx = x.substring(x.lastIndexOf('-')+1, x.indexOf('.ttl')) - const timestampy = y.substring(y.lastIndexOf('-')+1, y.indexOf('.ttl')) + const timestampx = getTimestampFromSnapshot(x) + const timestampy = getTimestampFromSnapshot(y) return timestampx - timestampy; }) for (let i = 0; i < snapshots.length-threshold; i++) { @@ -109,4 +109,8 @@ async function getSnapshotWithoutAdditionalTriples(store, linkToResource) { loadedResource = await store.fetcher.load(linkToResource) await store.updater.update([], creator.concat(modified)) return loadedResource +} + +function getTimestampFromSnapshot(snapshot) { + return snapshot.substring(snapshot.lastIndexOf('-')+1, snapshot.lastIndexOf('.')) } \ No newline at end of file