« get me outta code hell

data: duration utility - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-08 16:25:22 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-08 16:25:22 -0300
commitcd3e2ae7384d82f0f2758beb0ae38ce0fe9f5e09 (patch)
treeb015fef9361fe7255f8b2861f946fae169b88146
parente01b73d286fbb11ac8ded59b4c23738dff195171 (diff)
data: duration utility
-rw-r--r--src/data/things/thing.js10
-rw-r--r--src/data/things/track.js8
2 files changed, 12 insertions, 6 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 0484b589..169fc1ca 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -27,6 +27,7 @@ import {
   isDate,
   isDimensions,
   isDirectory,
+  isDuration,
   isFileExtension,
   isName,
   isString,
@@ -132,6 +133,15 @@ export function dimensions() {
   };
 }
 
+// Duration! This is a number of seconds, possibly floating point, always
+// at minimum zero.
+export function duration() {
+  return {
+    flags: {update: true, expose: true},
+    update: {validate: isDuration},
+  };
+}
+
 // Straightforward flag descriptor for a variety of property purposes.
 // Provide a default value, true or false!
 export function flag(defaultValue = false) {
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 0cd39dca..53798cda 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -19,7 +19,6 @@ import {
   isColor,
   isContributionList,
   isDate,
-  isDuration,
   isFileExtension,
 } from '#validators';
 
@@ -31,6 +30,7 @@ import Thing, {
   commentatorArtists,
   contributionList,
   directory,
+  duration,
   flag,
   name,
   referenceList,
@@ -54,11 +54,7 @@ export class Track extends Thing {
     name: name('Unnamed Track'),
     directory: directory(),
 
-    duration: {
-      flags: {update: true, expose: true},
-      update: {validate: isDuration},
-    },
-
+    duration: duration(),
     urls: urls(),
     dateFirstReleased: simpleDate(),