-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert ISO8061 to Unix Timestamp (#1021)
* 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
1 parent
f63b239
commit 0761b7e
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}; |