« get me outta code hell

content, wiki-data: sameDayAs - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/common-util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-03-26 16:44:07 -0300
committer(quasar) nebula <qznebula@protonmail.com>2026-03-26 16:44:07 -0300
commit01bd5cec3a83e9ced7715954e76dd820aa7e91dd (patch)
tree2a0417a4ba60f2969c6c29a1352883a4d68b64d6 /src/common-util
parent4225157ef21e584037efb816651608d8aa269025 (diff)
content, wiki-data: sameDayAs
Diffstat (limited to 'src/common-util')
-rw-r--r--src/common-util/wiki-data.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js
index 42ff677e..ae186065 100644
--- a/src/common-util/wiki-data.js
+++ b/src/common-util/wiki-data.js
@@ -616,3 +616,30 @@ export const albumHasSubstantialCommentaryPage = album =>
     album.tracks
       .flatMap(track => track.commentary)
       .filter(entry => !entry.isWikiEditorCommentary));
+
+export function sameDayAs(givenDate, thing) {
+  if (!givenDate) return null;
+
+  const compare = (a, b) =>
+    a && b &&
+    a.toDateString() === b.toDateString();
+
+  if (thing.isAlbum || thing.isTrack) {
+    const album = thing.isTrack ? thing.album : thing;
+    const track = thing.isTrack ? thing : null;
+
+    if (compare(givenDate, album.date)) {
+      if (album.style === 'single') {
+        return 'single';
+      } else {
+        return 'album';
+      }
+    }
+
+    if (compare(givenDate, track?.date)) {
+      return 'track';
+    }
+  }
+
+  return null;
+}