diff --git a/README.md b/README.md index 6b1025d11..101ed50a9 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ Executes Javascript, Typescript Scripts. +### **WORK IN PROGRESS** + +* (@klein0r) Added possibility to escape chars in formatTimeDiff + ### 8.9.2 (2025-04-27) * (@GermanBluefox) Updated packages for GUI diff --git a/docs/en/javascript.md b/docs/en/javascript.md index fcfdc51bd..3f7ccab6b 100644 --- a/docs/en/javascript.md +++ b/docs/en/javascript.md @@ -1299,6 +1299,8 @@ formatTimeDiff(milliseconds, format); * ss, сс(cyrillic) - full seconds, e.g. "05" * s, с(cyrillic) - short seconds, e.g., "5" +You can use escape charachter `\` to avoid the replacement. e.g. `DD \Day\s, h \hour\s, m \minute, ss \second\s` + #### Example ```js diff --git a/lib/sandbox.js b/lib/sandbox.js index ea35875ae..c3cf52b33 100644 --- a/lib/sandbox.js +++ b/lib/sandbox.js @@ -3537,50 +3537,60 @@ function sandBox(script, name, verbose, debug, context) { const neg = diff < 0; diff = Math.abs(diff); - if (/DD|TT|ДД|D|T|Д/.test(text)) { + if (/(? {\n` + ` const diff1 = formatTimeDiff(172800000 + 10800000 + 540000 + 15000, 'hh:mm:ss');\n` + ` const diff2 = formatTimeDiff((172800000 + 10800000 + 540000 + 15000) * -1, 'mm:ss');\n` + - ` setState('test_formatTimeDiff', { val: JSON.stringify({ diff1, diff2 }), ack: true });\n` + + ` const diff3 = formatTimeDiff(374501000, 'DD \\\\Day\\\\s, h \\\\hour\\\\s, m \\\\minute, ss \\\\second\\\\s');\n` + + ` setState('test_formatTimeDiff', { val: JSON.stringify({ diff1, diff2, diff3 }), ack: true });\n` + `});`, }, native: {}, @@ -1961,6 +1962,9 @@ describe.only('Test JS', function () { expect(obj.diff2).to.be.a('string'); expect(obj.diff2).to.be.equal('-3069:15'); + expect(obj.diff3).to.be.a('string'); + expect(obj.diff3).to.be.equal('04 Days, 8 hours, 1 minute, 41 seconds'); + removeStateChangedHandler(onStateChanged); done(); }