refactoring: migrated Moment.js to luxon
This commit is contained in:
parent
6d04c50919
commit
29c3a8fe86
4 changed files with 53 additions and 37 deletions
32
package-lock.json
generated
32
package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue