From 989c4ce351b62b46de07da1ce624a88af841cfca Mon Sep 17 00:00:00 2001 From: arT2 <60965610+etrusci-org@users.noreply.github.com> Date: Mon, 20 May 2024 18:09:08 +0200 Subject: [PATCH 1/4] Swatch internet time aka beats for clock --- app/lib/beats.js | 9 +++++++++ app/lib/olay.js | 1 + app/mod/clock/clock.js | 3 +++ 3 files changed, 13 insertions(+) create mode 100644 app/lib/beats.js diff --git a/app/lib/beats.js b/app/lib/beats.js new file mode 100644 index 0000000..fec4d8a --- /dev/null +++ b/app/lib/beats.js @@ -0,0 +1,9 @@ +function beatsNow() +{ + const now = new Date() + const h = now.getUTCHours() < 23 ? now.getUTCHours() + 1 : 0 + const m = now.getUTCMinutes() + const s = now.getUTCSeconds() + const now_b = (((h * 3600) + (m * 60) + s) / 86.4).toFixed(2) + return now_b +} diff --git a/app/lib/olay.js b/app/lib/olay.js index d87f0a1..0cbe637 100644 --- a/app/lib/olay.js +++ b/app/lib/olay.js @@ -17,6 +17,7 @@ const appConf = { './mod/clock/clock.default.css', ], libs: [ + './lib/beats.js', './lib/humantimestamp.js', './lib/replacenumswithchars.js', ], diff --git a/app/mod/clock/clock.js b/app/mod/clock/clock.js index e7287e6..118168f 100644 --- a/app/mod/clock/clock.js +++ b/app/mod/clock/clock.js @@ -23,6 +23,9 @@ export class Mod extends ModBase else if (this.conf.type == 'unixms') { out = String(Date.now()) } + else if (this.conf.type == 'beat') { + out = String(`@${beatsNow()}`) + } if (this.conf.repnum == 'true') { out = replaceNumsWithChars(out, this.conf.repmap) From cdac50ff1b3ae0c9295f91e5df36caa662430495 Mon Sep 17 00:00:00 2001 From: arT2 <60965610+etrusci-org@users.noreply.github.com> Date: Fri, 24 May 2024 12:21:32 +0200 Subject: [PATCH 2/4] Beats format, Rename file, Doc --- app/lib/{beats.js => beatsnow.js} | 0 app/lib/olay.js | 2 +- app/mod/clock/README.md | 13 +++++++++++++ app/mod/clock/clock.conf.js | 1 + app/mod/clock/clock.js | 4 ++-- 5 files changed, 17 insertions(+), 3 deletions(-) rename app/lib/{beats.js => beatsnow.js} (100%) diff --git a/app/lib/beats.js b/app/lib/beatsnow.js similarity index 100% rename from app/lib/beats.js rename to app/lib/beatsnow.js diff --git a/app/lib/olay.js b/app/lib/olay.js index 0cbe637..a1567ce 100644 --- a/app/lib/olay.js +++ b/app/lib/olay.js @@ -17,7 +17,7 @@ const appConf = { './mod/clock/clock.default.css', ], libs: [ - './lib/beats.js', + './lib/beatsnow.js', './lib/humantimestamp.js', './lib/replacenumswithchars.js', ], diff --git a/app/mod/clock/README.md b/app/mod/clock/README.md index 528183c..945eb77 100644 --- a/app/mod/clock/README.md +++ b/app/mod/clock/README.md @@ -15,6 +15,8 @@ Display current local date and time. - [mod=clock&repnum=true&repmap=4](https://etrusci.org/tool/olay/?mod=clock&repnum=true&repmap=4) - [mod=clock&type=unix](https://etrusci.org/tool/olay/?mod=clock&type=unix) - [mod=clock&type=unixms&updaterate=80](https://etrusci.org/tool/olay/?mod=clock&type=unixms&updaterate=80) +- [mod=clock&type=beats](https://etrusci.org/tool/olay/?mod=clock&type=beats) +- [mod=clock&type=beats&beatsformat=@{beats}](https://etrusci.org/tool/olay/?mod=clock&type=beats&beatsformat=@{beats}) --- @@ -54,6 +56,17 @@ Placeholders: - `{millisecond}`: Millisecond - `{timezoneOffset}`: Timezone offset (relative from UTC) +### beatsformat + +Internet time format template. + +Requires: `type = beats` +Valid: `Placeholders, text, HTML` + +Placeholders: + +- `{beats}`: Beats + ### repnum Whether to replace numbers with characters. diff --git a/app/mod/clock/clock.conf.js b/app/mod/clock/clock.conf.js index cabdb72..4eb71bb 100644 --- a/app/mod/clock/clock.conf.js +++ b/app/mod/clock/clock.conf.js @@ -4,6 +4,7 @@ export const modConf = { updaterate: '1000', type: 'human', humanformat: '{year}-{month}-{day} {hour}:{minute}:{second}', + beatsformat: '@{beats} .beats', repnum: 'false', repmap: '1', } diff --git a/app/mod/clock/clock.js b/app/mod/clock/clock.js index 118168f..ad4760b 100644 --- a/app/mod/clock/clock.js +++ b/app/mod/clock/clock.js @@ -23,8 +23,8 @@ export class Mod extends ModBase else if (this.conf.type == 'unixms') { out = String(Date.now()) } - else if (this.conf.type == 'beat') { - out = String(`@${beatsNow()}`) + else if (this.conf.type == 'beats') { + out = this.conf.beatsformat.replace('{beats}', beatsNow()) } if (this.conf.repnum == 'true') { From c743c6965664a3d3a5d393f98477afcc2c7a8cc2 Mon Sep 17 00:00:00 2001 From: arT2 <60965610+etrusci-org@users.noreply.github.com> Date: Fri, 24 May 2024 12:24:00 +0200 Subject: [PATCH 3/4] Doc --- app/mod/clock/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mod/clock/README.md b/app/mod/clock/README.md index 945eb77..26fda76 100644 --- a/app/mod/clock/README.md +++ b/app/mod/clock/README.md @@ -37,6 +37,7 @@ Valid: - `human`: Human-readable format - `unix`: Unixtime stamp in seconds - `unixms`: Unixtime stamp in milliseconds +- `beats`: Internet time ### humanformat From c9faa422f5810d900afcffd6fc6a7707aed07558 Mon Sep 17 00:00:00 2001 From: arT2 <60965610+etrusci-org@users.noreply.github.com> Date: Sat, 25 May 2024 14:55:39 +0200 Subject: [PATCH 4/4] Less consts, Doc --- app/lib/beatsnow.js | 6 +----- app/mod/clock/README.md | 10 +++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/lib/beatsnow.js b/app/lib/beatsnow.js index fec4d8a..0c23084 100644 --- a/app/lib/beatsnow.js +++ b/app/lib/beatsnow.js @@ -1,9 +1,5 @@ function beatsNow() { const now = new Date() - const h = now.getUTCHours() < 23 ? now.getUTCHours() + 1 : 0 - const m = now.getUTCMinutes() - const s = now.getUTCSeconds() - const now_b = (((h * 3600) + (m * 60) + s) / 86.4).toFixed(2) - return now_b + return ((((now.getUTCHours() < 23 ? now.getUTCHours() + 1 : 0) * 3600) + (now.getUTCMinutes() * 60) + now.getUTCSeconds()) / 86.4).toFixed(2) } diff --git a/app/mod/clock/README.md b/app/mod/clock/README.md index 26fda76..d5cf28b 100644 --- a/app/mod/clock/README.md +++ b/app/mod/clock/README.md @@ -34,10 +34,10 @@ Which type of clock to load. Valid: -- `human`: Human-readable format -- `unix`: Unixtime stamp in seconds -- `unixms`: Unixtime stamp in milliseconds -- `beats`: Internet time +- `human`: [Human-readable](https://en.wikipedia.org/wiki/Human-readable_medium_and_data) date/time format +- `unix`: [Unixtime](https://en.wikipedia.org/wiki/Unix_time) stamp in seconds +- `unixms`: [Unixtime](https://en.wikipedia.org/wiki/Unix_time) stamp in milliseconds +- `beats`: [Swatch internet time](https://en.wikipedia.org/wiki/Swatch_Internet_Time) ### humanformat @@ -59,7 +59,7 @@ Placeholders: ### beatsformat -Internet time format template. +Swatch internet time format template. Requires: `type = beats` Valid: `Placeholders, text, HTML`