Skip to content

Commit

Permalink
Convert ISO8061 to Unix Timestamp (#1021)
Browse files Browse the repository at this point in the history
* Create convert_iso_to_timestamp_MOD.js

* Create add_commas_to_number_MOD.js

Adds commas every 1000. Example: 100000 -> 100,000. 
When something smaller than 1000 is given, for example 100, then no changes will be made to the original number.

* Update metadata

* Update metadata

* update metadata

---------

Co-authored-by: OneAndonlyFinbar <finbar@finbar.xyz>
  • Loading branch information
Robskan5300 and OneAndOnlyFinbar authored Jan 28, 2024
1 parent f63b239 commit 0761b7e
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
65 changes: 65 additions & 0 deletions actions/add_commas_to_number_MOD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module.exports = {
name: 'Add Commas to Number',
section: 'Other Stuff',
meta: {
version: '2.1.7',
preciseCheck: false,
author: 'DBM Mods',
authorUrl: 'https://github.com/dbm-network/mods',
modAuthors: ['Robskan5300'],
},

subtitle(data) {
return `Add Commas to ${data.number}`;
},

variableStorage(data, varType) {
if (parseInt(data.storage, 10) !== varType) return;
return [data.varName, 'String'];
},

fields: ['number', 'storage', 'varName'],

html() {
return `
<div style="float: left; width: 60%; padding-top: 8px;">
<p><u>Note:</u><br>
This mod adds commas to a number for every 1000.</p>
</div>
<br><br><br>
<div style="float: left; width: 70%; padding-top: 8px;">
<span class="dbminputlabel">Number to Add Commas</span>
<input id="number" class="round" type="text" placeholder="e.g. 1000000">
</div>
<br><br><br><br>
<div>
<store-in-variable dropdownLabel="Store In" selectId="storage" variableContainerId="varNameContainer" variableInputId="varName"></store-in-variable>
</div>
<br><br><br>
<div style="text-align: center; float: left; width: 100%; padding-top: 8px;">
<p><b>Example:</b> 1000000 will be converted to 1,000,000</p>
</div>`;
},

init() {
const { glob, document } = this;
glob.variableChange(document.getElementById('storage'), 'varNameContainer');
},

async action(cache) {
const data = cache.actions[cache.index];
const number = this.evalMessage(data.number, cache);

// Use regex to add commas to the number
const numberWithCommas = number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');

const storage = parseInt(data.storage, 10);
const varName = this.evalMessage(data.varName, cache);
this.storeValue(numberWithCommas, storage, varName, cache);

this.callNextAction(cache);
},
};
62 changes: 62 additions & 0 deletions actions/convert_iso_to_timestamp_MOD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module.exports = {
name: 'Convert ISO 8601 to Timestamp',
section: 'Other Stuff',
meta: {
version: '2.1.7',
preciseCheck: false,
author: 'DBM Mods',
authorUrl: 'https://github.com/dbm-network/mods',
modAuthors: ['Robskan5300'],
},

subtitle(data) {
return `Convert ${data.isoDate}`;
},

variableStorage(data, varType) {
if (parseInt(data.storage, 10) !== varType) return;
return [data.varName, 'Number'];
},

fields: ['isoDate', 'storage', 'varName'],

html() {
return `
<div style="float: left; width: 60%; padding-top: 8px;">
<p><u>Note:</u><br>
You can convert <b>ISO 8601</b> date to <b>Unix Timestamp</b> with this mod.</p>
</div>
<br><br><br>
<div style="float: left; width: 70%; padding-top: 8px;">
<span class="dbminputlabel">ISO 8601 Date to Convert</span>
<input id="isoDate" class="round" type="text" placeholder="e.g. 2024-01-28T16:05:00Z">
</div>
<br><br><br><br>
<div>
<store-in-variable dropdownLabel="Store In" selectId="storage" variableContainerId="varNameContainer" variableInputId="varName"></store-in-variable>
</div>
<br><br><br>`;
},

init() {
const { glob, document } = this;
glob.variableChange(document.getElementById('storage'), 'varNameContainer');
},

async action(cache) {
const data = cache.actions[cache.index];
const isoDate = this.evalMessage(data.isoDate, cache);

const timestamp = Date.parse(isoDate);

if (!isNaN(timestamp)) {
const storage = parseInt(data.storage, 10);
const varName = this.evalMessage(data.varName, cache);
this.storeValue(timestamp, storage, varName, cache);
}

this.callNextAction(cache);
},
};

0 comments on commit 0761b7e

Please sign in to comment.