From ec17ceb303ddf3fc9beb718332cd91f9a243465d Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Mon, 24 May 2021 13:16:56 +0100 Subject: [PATCH 1/7] util/Clock: drop moment and the format argument from getDateStr() --- src/util/Clock.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/util/Clock.js b/src/util/Clock.js index a4f9ccc..0919106 100644 --- a/src/util/Clock.js +++ b/src/util/Clock.js @@ -75,12 +75,23 @@ export class MonotonicClock * @function * @public * @static - * @param {string} [format= 'YYYY-MM-DD_HH[h]mm.ss.SSS'] - the format for the string (see [momentjs.com]{@link https://momentjs.com/docs/#/parsing/string-format/} for details) - * @return {string} a string representing the current time in the given format + * @return {string} ISO based, zero UTC offset datetime string re-formatted as YYYY-MM-DD_HH[h]mm.ss.sss */ - static getDateStr(format = 'YYYY-MM-DD_HH[h]mm.ss.SSS') + static getDateStr() { - return moment().format(format); + const date = new Date(); + const s = date.toISOString(); + + // Go from: + // ±YYYYYY-MM-DDTHH:mm:ss.sssZ + // YYYY-MM-DDTHH:mm:ss.sssZ + // To: + // YYYY-MM-DD_HH[h]mm.ss.sss + return s.substring(s.length - 24) + .replace('T', '_') + .replace(':', 'h') + .replace(':', '.') + .replace('Z', ''); } } From 78b4466c6add0ae3b7fefaea672d76390e54aebc Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Tue, 25 May 2021 12:18:29 +0100 Subject: [PATCH 2/7] util/Clock: drop the ISO part in favour of session specific timestamps --- src/util/Clock.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/util/Clock.js b/src/util/Clock.js index 0919106..d2f503c 100644 --- a/src/util/Clock.js +++ b/src/util/Clock.js @@ -80,18 +80,26 @@ export class MonotonicClock static getDateStr() { const date = new Date(); - const s = date.toISOString(); + const dateTimeFormat = new Intl.DateTimeFormat('en-CA', { + hour12: false, + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + fractionalSecondDigits: 3 + }); - // Go from: - // ±YYYYYY-MM-DDTHH:mm:ss.sssZ - // YYYY-MM-DDTHH:mm:ss.sssZ - // To: - // YYYY-MM-DD_HH[h]mm.ss.sss - return s.substring(s.length - 24) - .replace('T', '_') + return dateTimeFormat + // yyyy-mm-dd, hh:mm:ss.sss + .format(date) + // yyyy-mm-dd_hh:mm:ss.sss + .replace(', ', '_') + // yyyy-mm-dd_hh[h]mm:ss.sss .replace(':', 'h') - .replace(':', '.') - .replace('Z', ''); + // yyyy-mm-dd_hh[h]mm.ss.sss + .replace(':', '.'); } } From 43be6cad044e32211dc17feaffcd7b9e5804ec1d Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Tue, 25 May 2021 13:12:14 +0100 Subject: [PATCH 3/7] util/Clock: fix JSDoc --- src/util/Clock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/Clock.js b/src/util/Clock.js index d2f503c..97b9e83 100644 --- a/src/util/Clock.js +++ b/src/util/Clock.js @@ -75,7 +75,7 @@ export class MonotonicClock * @function * @public * @static - * @return {string} ISO based, zero UTC offset datetime string re-formatted as YYYY-MM-DD_HH[h]mm.ss.sss + * @return {string} a string representing the current time formatted as YYYY-MM-DD_HH[h]mm.ss.sss */ static getDateStr() { From 4c1426dea5242fbfae50d2d647fbb8ca92329e61 Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Fri, 4 Jun 2021 11:50:20 +0100 Subject: [PATCH 4/7] util/Clock: split date formatting and parsing into separate funcs, drop moment import --- src/util/Clock.js | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/util/Clock.js b/src/util/Clock.js index 0bd4d70..4ee213b 100644 --- a/src/util/Clock.js +++ b/src/util/Clock.js @@ -7,8 +7,6 @@ * @license Distributed under the terms of the MIT License */ -import moment from 'moment'; - /** *

MonotonicClock offers a convenient way to keep track of time during experiments. An experiment can have as many independent clocks as needed, e.g. one to time responses, another one to keep track of stimuli, etc.

@@ -69,20 +67,22 @@ export class MonotonicClock /** - * Get the clock's current time as a formatted string. + * Get the current timestamp with language-sensitive formatting rules applied. * - *

Note: this is mostly used as an appendix to the name of the keys save to the server.

+ *

Note: This is just a convenience wrapper around `Intl.DateTimeFormat()`.

* - * @name module:util.MonotonicClock.getDateStr + * @name module:util.MonotonicClock.getDate * @function * @public * @static - * @return {string} a string representing the current time formatted as YYYY-MM-DD_HH[h]mm.ss.sss + * @param {string|array.string} locales - A string with a BCP 47 language tag, or an array of such strings. + * @param {object} options - An object with detailed date and time styling information. + * @return {string} The current timestamp in the chosen format. */ - static getDateStr() + static getDate(locales = 'en-CA', optionsMaybe) { const date = new Date(); - const dateTimeFormat = new Intl.DateTimeFormat('en-CA', { + const options = Object.assign({ hour12: false, year: 'numeric', month: '2-digit', @@ -91,11 +91,28 @@ export class MonotonicClock minute: 'numeric', second: 'numeric', fractionalSecondDigits: 3 - }); + }, optionsMaybe); - return dateTimeFormat - // yyyy-mm-dd, hh:mm:ss.sss - .format(date) + const dateTimeFormat = new Intl.DateTimeFormat(locales, options); + + return dateTimeFormat.format(date); + } + + /** + * Get the clock's current time in the default format filtering out file name unsafe characters. + * + *

Note: This is mostly used as an appendix to the name of the keys save to the server.

+ * + * @name module:util.MonotonicClock.getDateStr + * @function + * @public + * @static + * @return {string} A string representing the current time formatted as YYYY-MM-DD_HH[h]mm.ss.sss + */ + static getDateStr() + { + // yyyy-mm-dd, hh:mm:ss.sss + return MonotonicClock.getDate() // yyyy-mm-dd_hh:mm:ss.sss .replace(', ', '_') // yyyy-mm-dd_hh[h]mm:ss.sss From f532e739aecbcf0c791d162e512940a11b538b6f Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Fri, 4 Jun 2021 11:57:26 +0100 Subject: [PATCH 5/7] package: drop moment from deps --- package-lock.json | 15 --------------- package.json | 1 - 2 files changed, 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7d04e5b..8baa3bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,13 +5,11 @@ "requires": true, "packages": { "": { - "name": "psychojs", "version": "2021.x", "license": "MIT", "dependencies": { "howler": "^2.2.1", "log4javascript": "github:Ritzlgrmft/log4javascript", - "moment": "^2.29.1", "pako": "^1.0.10", "pixi.js-legacy": "^6.0.4", "preload-js": "^0.6.3", @@ -1800,14 +1798,6 @@ "node": ">=10" } }, - "node_modules/moment": { - "version": "2.29.1", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz", - "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==", - "engines": { - "node": "*" - } - }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -3887,11 +3877,6 @@ "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", "dev": true }, - "moment": { - "version": "2.29.1", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz", - "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==" - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", diff --git a/package.json b/package.json index d2e2ad1..d17c602 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "dependencies": { "howler": "^2.2.1", "log4javascript": "github:Ritzlgrmft/log4javascript", - "moment": "^2.29.1", "pako": "^1.0.10", "pixi.js-legacy": "^6.0.4", "preload-js": "^0.6.3", From d3e3a67a80395ead087c6b028d3083fe220bd02e Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Tue, 15 Jun 2021 14:32:23 +0100 Subject: [PATCH 6/7] visual/TextBox: pass text value on to text input --- src/visual/TextBox.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/visual/TextBox.js b/src/visual/TextBox.js index 095de0b..b181b9e 100644 --- a/src/visual/TextBox.js +++ b/src/visual/TextBox.js @@ -319,6 +319,7 @@ export class TextBox extends util.mix(VisualStim).with(ColorMixin) padding: padding_px + 'px', multiline, + text: this._text, height: multiline ? (height_px - 2 * padding_px) + 'px' : undefined, width: (width_px - 2 * padding_px) + 'px' }, From e868f941f9d3dcbdba3d5d7915ae01654747b183 Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Tue, 15 Jun 2021 14:33:07 +0100 Subject: [PATCH 7/7] visual/TextInput: access a text value, only disable text substitution when multiline --- src/visual/TextInput.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/visual/TextInput.js b/src/visual/TextInput.js index 1826ce6..f99d08b 100644 --- a/src/visual/TextInput.js +++ b/src/visual/TextInput.js @@ -22,6 +22,7 @@ export class TextInput extends PIXI.Container background: 'none', border: 'none', outline: 'none', + text: '', transformOrigin: '0 0', lineHeight: '1' }, @@ -56,7 +57,7 @@ export class TextInput extends PIXI.Container this._selection = [0, 0]; this._restrict_value = ''; this._createDOMInput(); - this.substituteText = false; + this.substituteText = !this._multiline; this._setState('DEFAULT'); }