Skip to content

Commit

Permalink
Fall back to item creation date if title is malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Nov 7, 2023
1 parent c7952a5 commit 72677eb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/renderer/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function rendererBackground(context) {
// Extracts the layer's date from the title.
let extractDateFromTitle = title => {
const dateComponents = title.match(/\(Wayback (\d{4})-(\d\d)-(\d\d)\)/);
if (!dateComponents) return;
return new Date(Date.UTC(parseInt(dateComponents[1], 10),
parseInt(dateComponents[2], 10) - 1,
parseInt(dateComponents[3], 10)));
Expand All @@ -48,16 +49,16 @@ export function rendererBackground(context) {
.filter(item => item.type === 'Map Service')
.map(item => {
// Extract the layer's date from the title to avoid having to hit each MapServer right away.
const date = extractDateFromTitle(item.title);
const date = extractDateFromTitle(item.title) || new Date(item.created);
const dateString = date.toISOString().split('T')[0];
return [dateString, item.url];
}));

_waybackIndex = groups.items
.filter(item => item.type === 'WMTS')
.map(item => {
const date = extractDateFromTitle(item.title);
const dateString = date.toISOString().split('T')[0];
const date = extractDateFromTitle(item.title) || new Date(item.created);
const dateString = date && date.toISOString().split('T')[0];

// Convert the bounding box to a polygon.
const bbox = {
Expand Down

0 comments on commit 72677eb

Please sign in to comment.