refactoring: migrated Moment.js to luxon

This commit is contained in:
ievgenii vdovenko 2025-11-11 14:27:20 +01:00
parent 6d04c50919
commit 29c3a8fe86
4 changed files with 53 additions and 37 deletions

View file

@ -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'];

View file

@ -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')
}
}