mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 15:30:13 +01:00
Fix Due dates to be color coded and have icons.
Thanks to xet7 ! Fixes #5950
This commit is contained in:
parent
5d2bfab0f5
commit
d965faa317
6 changed files with 126 additions and 32 deletions
|
|
@ -304,6 +304,10 @@ export function format(date, format = 'L') {
|
|||
return d.toLocaleString();
|
||||
case 'llll':
|
||||
return d.toLocaleString();
|
||||
case 'LLLL':
|
||||
return d.toLocaleString();
|
||||
case 'l LT':
|
||||
return `${month}/${day}/${year} ${hours}:${minutes}`;
|
||||
case 'YYYY-MM-DD':
|
||||
return `${year}-${month}-${day}`;
|
||||
case 'YYYY-MM-DD HH:mm':
|
||||
|
|
@ -490,3 +494,40 @@ export function calendar(date, now = new Date()) {
|
|||
|
||||
return format(d, 'L');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the difference between two dates in the specified unit
|
||||
* @param {Date|string} date1 - First date
|
||||
* @param {Date|string} date2 - Second date
|
||||
* @param {string} unit - Unit of measurement ('millisecond', 'second', 'minute', 'hour', 'day', 'week', 'month', 'year')
|
||||
* @returns {number} Difference in the specified unit
|
||||
*/
|
||||
export function diff(date1, date2, unit = 'millisecond') {
|
||||
const d1 = new Date(date1);
|
||||
const d2 = new Date(date2);
|
||||
|
||||
if (isNaN(d1.getTime()) || isNaN(d2.getTime())) return 0;
|
||||
|
||||
const diffMs = d1.getTime() - d2.getTime();
|
||||
|
||||
switch (unit) {
|
||||
case 'millisecond':
|
||||
return diffMs;
|
||||
case 'second':
|
||||
return Math.floor(diffMs / 1000);
|
||||
case 'minute':
|
||||
return Math.floor(diffMs / (1000 * 60));
|
||||
case 'hour':
|
||||
return Math.floor(diffMs / (1000 * 60 * 60));
|
||||
case 'day':
|
||||
return Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||
case 'week':
|
||||
return Math.floor(diffMs / (1000 * 60 * 60 * 24 * 7));
|
||||
case 'month':
|
||||
return Math.floor(diffMs / (1000 * 60 * 60 * 24 * 30));
|
||||
case 'year':
|
||||
return Math.floor(diffMs / (1000 * 60 * 60 * 24 * 365));
|
||||
default:
|
||||
return diffMs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue