Open xmha97 opened 2 years ago
Try this: (by @ebraminio)
data:text/html;charset=utf8,<textarea id=input style="width: 50%; height: 5em; white-space: pre" oninput="result.innerText = calculate(this.value)"></textarea><div id=result></div><script>window.onload = () => { input.value = '1d 2h 3m 4s + 4h 5s - 2030s + 28h'; input.dispatchEvent(new Event('input')) }; function calculate(input) { const units = Object.entries({ d: 86400, h: 3600, m: 60, s: 1 }); const seconds = eval(input.replace(/[\d\w\s]+/g, x => '(' + units.reduce((acc, unit) => acc.replace(new RegExp('(\\d+)' + unit[0]), '+$1*' + unit[1]), x) + ')')); const result = units.reduce(([result, reminder], unit) => [result + Math.floor(reminder / unit[1]) + unit[0] + ' ', reminder % unit[1]], ['', seconds])[0]; return result + '\n' + units.map(unit => (seconds / unit[1]) + ' ' + unit[0]).join('\n'); }</script>
Thos feels for me like an addition to calculator plugin
Hi @htcfreek, just a confusion, can we use the TimeSpan
struct here?
References -
Hi @htcfreek, just a confusion, can we use the
TimeSpan
struct here?References -
Need to try. But sounds to me, like it make sense to use it.
Hi @htcfreek, I looked into this issue and found that this feature can be introduced in Mages
, not our repo. Since the whole query string is being given to Mages
, it makes much more sense to process it then and there (or add any new functionality). Could you add the External Dependency
label here? Also, could you add the same to #31740?
Came over from duplicate issue #35709 . In that one I also suggested that PowerToy Run's Calculator plugin should be able to calculate time differentials between dates. For example, typing 6/13 - 3 would spit out 6/10.
Also, being able to divide/multiply a time string would be nice! For instance, when you want to find out how long a YouTube video will be at a certain speed.
Description of the new feature / enhancement
Scenario when this would be used?
Use this calculator to add or subtract two or more time values in the form of an expression. https://www.calculator.net/time-calculator.html?tcexpression=1d+2h+3m+4s+%2B+4h+5s+-+2030s+%2B+28h&ctype=3&x=57&y=21#expression
Supporting information
No response