From 29c3a8fe8681491b87cbab52ea42e647bb3689e2 Mon Sep 17 00:00:00 2001 From: ievgenii vdovenko Date: Tue, 11 Nov 2025 14:27:20 +0100 Subject: [PATCH 1/3] refactoring: migrated Moment.js to luxon --- package-lock.json | 32 +++++++------- package.json | 2 +- .../src/plugins/jquery.timeago-extension.js | 44 +++++++++++++------ rhodecode/public/js/src/rhodecode.js | 12 ++--- 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index f0d9d3d8..64bc2594 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,8 +43,8 @@ "imports-loader": "^0.7.1", "jquery": "1.11.3", "jshint": "^2.9.1-rc3", + "luxon": "^3.7.2", "mark.js": "8.11.1", - "moment": "^2.18.1", "mousetrap": "^1.6.1", "polymer-webpack-loader": "^2.0.1", "raw-loader": "1.0.0-beta.0", @@ -6823,6 +6823,15 @@ "yallist": "^2.1.2" } }, + "node_modules/luxon": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.7.2.tgz", + "integrity": "sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/make-dir": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", @@ -7145,15 +7154,6 @@ "mkdirp": "bin/cmd.js" } }, - "node_modules/moment": { - "version": "2.30.1", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", - "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/mousetrap": { "version": "1.6.5", "resolved": "https://registry.npmjs.org/mousetrap/-/mousetrap-1.6.5.tgz", @@ -17581,6 +17581,12 @@ "yallist": "^2.1.2" } }, + "luxon": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.7.2.tgz", + "integrity": "sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew==", + "dev": true + }, "make-dir": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", @@ -17850,12 +17856,6 @@ "minimist": "^1.2.6" } }, - "moment": { - "version": "2.30.1", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", - "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", - "dev": true - }, "mousetrap": { "version": "1.6.5", "resolved": "https://registry.npmjs.org/mousetrap/-/mousetrap-1.6.5.tgz", diff --git a/package.json b/package.json index a909f18b..c71c47ba 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,8 @@ "imports-loader": "^0.7.1", "jquery": "1.11.3", "jshint": "^2.9.1-rc3", + "luxon": "^3.7.2", "mark.js": "8.11.1", - "moment": "^2.18.1", "mousetrap": "^1.6.1", "polymer-webpack-loader": "^2.0.1", "raw-loader": "1.0.0-beta.0", diff --git a/rhodecode/public/js/src/plugins/jquery.timeago-extension.js b/rhodecode/public/js/src/plugins/jquery.timeago-extension.js index 89b3d60c..4132298b 100644 --- a/rhodecode/public/js/src/plugins/jquery.timeago-extension.js +++ b/rhodecode/public/js/src/plugins/jquery.timeago-extension.js @@ -3,25 +3,41 @@ var AgeModule = (function () { return { age: function(prevdate, now, show_short_version, show_suffix, short_format) { - var prevdate = moment(prevdate).utc(); - var now = now ? moment(now).utc() : moment().utc(); + prevdate = DateTime.fromJSDate(prevdate, { zone: "utc" }); + now = now + ? DateTime.fromJSDate(now, { zone: "utc" }) + : DateTime.utc(); var show_short_version = show_short_version || false; var show_suffix = show_suffix || true; var short_format = short_format || false; var _get_relative_delta = function(now, prevdate) { + const duration = now.diff(prevdate, [ + "years", + "months", + "days", + "hours", + "minutes", + "seconds", + ]); + const { + years = 0, + months = 0, + days = 0, + hours = 0, + minutes = 0, + seconds = 0, + } = duration.toObject(); - var duration = moment.duration(moment(now).diff(prevdate)); - return { - 'year': duration.years(), - 'month': duration.months(), - 'day': duration.days(), - 'hour': duration.hours(), - 'minute': duration.minutes(), - 'second': duration.seconds() - }; - + return { + year: years, + month: months, + day: days, + hour: hours, + minute: minutes, + second: seconds, + }; }; var _is_leap_year = function(year){ @@ -29,11 +45,11 @@ var AgeModule = (function () { }; var get_month = function(prevdate) { - return prevdate.getMonth() + return prevdate.month - 1; }; var get_year = function(prevdate) { - return prevdate.getYear() + return prevdate.year; }; var order = ['year', 'month', 'day', 'hour', 'minute', 'second']; diff --git a/rhodecode/public/js/src/rhodecode.js b/rhodecode/public/js/src/rhodecode.js index 265e6fe2..1aae54d3 100644 --- a/rhodecode/public/js/src/rhodecode.js +++ b/rhodecode/public/js/src/rhodecode.js @@ -652,22 +652,22 @@ var feedLifetimeOptions = function(query, initialData){ if (isQuery) { - var now = moment.utc(); + const now = DateTime.utc(); var parseQuery = function(entry, now){ - var fmt = 'DD/MM/YYYY H:mm'; - var parsed = moment.utc(entry, fmt); - var diffInMin = parsed.diff(now, 'minutes'); + var fmt = 'dd/LL/yyyy H:mm'; + var parsed = DateTime.fromFormat(entry, fmt, { zone: "utc" }); + var diffInMin = parsed.diff(now, "minutes").as("minutes"); if (diffInMin > 0){ return { id: diffInMin, - text: parsed.format(fmt) + text: parsed.toFormat(fmt), } } else { return { id: undefined, - text: parsed.format('DD/MM/YYYY') + ' ' + _gettext('date not in future') + text: parsed.toFormat('DD/MM/YYYY') + ' ' + _gettext('date not in future') } } From c09e1d136e5fc56e1b4023d89251ef655c18c55d Mon Sep 17 00:00:00 2001 From: ievgenii vdovenko Date: Tue, 11 Nov 2025 14:35:14 +0100 Subject: [PATCH 2/3] refactoring: adds comment --- rhodecode/public/js/src/plugins/jquery.timeago-extension.js | 1 + 1 file changed, 1 insertion(+) diff --git a/rhodecode/public/js/src/plugins/jquery.timeago-extension.js b/rhodecode/public/js/src/plugins/jquery.timeago-extension.js index 4132298b..11af1aa6 100644 --- a/rhodecode/public/js/src/plugins/jquery.timeago-extension.js +++ b/rhodecode/public/js/src/plugins/jquery.timeago-extension.js @@ -45,6 +45,7 @@ var AgeModule = (function () { }; var get_month = function(prevdate) { + // mimic moment().month() // 0–11 return prevdate.month - 1; }; From d7d35e70df9cf637ef647e283b91f75c6ac0c121 Mon Sep 17 00:00:00 2001 From: ievgenii vdovenko Date: Tue, 11 Nov 2025 16:16:35 +0100 Subject: [PATCH 3/3] refactoring: fixes grunt config --- grunt_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grunt_config.json b/grunt_config.json index 77f19187..609f2068 100644 --- a/grunt_config.json +++ b/grunt_config.json @@ -32,7 +32,7 @@ "src": [ "<%= dirs.js.node_modules %>/jquery/dist/jquery.min.js", "<%= dirs.js.node_modules %>/mousetrap/mousetrap.min.js", - "<%= dirs.js.node_modules %>/moment/min/moment.min.js", + "<%= dirs.js.node_modules %>/luxon/build/global/luxon.min.js", "<%= dirs.js.node_modules %>/clipboard/dist/clipboard.min.js", "<%= dirs.js.node_modules %>/favico.js/favico-0.3.10.min.js", "<%= dirs.js.node_modules %>/dropzone/dist/min/dropzone.min.js",