diff --git a/package-lock.json b/package-lock.json index cd72665..699c059 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "howler": "^2.2.1", "log4javascript": "github:Ritzlgrmft/log4javascript", - "moment": "^2.29.1", "pako": "^1.0.10", "pixi.js-legacy": "^6.0.4", "seedrandom": "^3.0.5", @@ -1799,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", @@ -3881,11 +3872,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 9ed9f3f..d7ee5da 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", "seedrandom": "^3.0.5", diff --git a/src/util/Clock.js b/src/util/Clock.js index 2fdfa3e..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,58 @@ 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.getDate + * @function + * @public + * @static + * @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 getDate(locales = 'en-CA', optionsMaybe) + { + const date = new Date(); + const options = Object.assign({ + hour12: false, + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + fractionalSecondDigits: 3 + }, optionsMaybe); + + 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 - * @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} A string representing the current time 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); + // 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 + .replace(':', 'h') + // yyyy-mm-dd_hh[h]mm.ss.sss + .replace(':', '.'); } } 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' }, 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'); }