the home site for me: also iteration 3 or 4 of my site

feat: update relative time to use 2 week period

dunkirk.sh 17bd0c11 198814a7

verified
+25 -12
+25 -12
static/js/relative-time.js
··· 32 } 33 34 get threshold() { 35 - return this.getAttribute('threshold') || 'P30D'; 36 } 37 38 get prefix() { ··· 70 this.scheduleUpdate(3600000); 71 } else { 72 this.textContent = this.formatRelative(diff); 73 - this.scheduleUpdate(this.getNextUpdateDelay(absDiff)); 74 } 75 } 76 ··· 88 return 60000 * 5; 89 } else if (days < 7) { 90 return 3600000; 91 } else { 92 - return 3600000 * 6; 93 } 94 } 95 96 formatRelative(diff) { 97 - const rtf = new Intl.RelativeTimeFormat(navigator.language, { 98 - numeric: 'auto', 99 - style: 'long' 100 - }); 101 102 const absDiff = Math.abs(diff); 103 const sign = diff > 0 ? -1 : 1; ··· 105 const minutes = Math.floor(seconds / 60); 106 const hours = Math.floor(minutes / 60); 107 const days = Math.floor(hours / 24); 108 - const months = Math.floor(days / 30); 109 - const years = Math.floor(days / 365); 110 111 if (seconds < 60) { 112 return rtf.format(sign * seconds, 'second'); ··· 116 return rtf.format(sign * hours, 'hour'); 117 } else if (days < 30) { 118 return rtf.format(sign * days, 'day'); 119 - } else if (months < 12) { 120 - return rtf.format(sign * months, 'month'); 121 } else { 122 - return rtf.format(sign * years, 'year'); 123 } 124 } 125
··· 32 } 33 34 get threshold() { 35 + return this.getAttribute('threshold') || 'P14D'; 36 } 37 38 get prefix() { ··· 70 this.scheduleUpdate(3600000); 71 } else { 72 this.textContent = this.formatRelative(diff); 73 + const delay = this.getNextUpdateDelay(absDiff); 74 + if (delay !== null) this.scheduleUpdate(delay); 75 } 76 } 77 ··· 89 return 60000 * 5; 90 } else if (days < 7) { 91 return 3600000; 92 + } else if (days < 30) { 93 + return 3600000 * 6; 94 } else { 95 + return null; 96 } 97 } 98 99 + getRtf() { 100 + if (!this._rtf || this._rtfLang !== navigator.language) { 101 + this._rtfLang = navigator.language; 102 + this._rtf = new Intl.RelativeTimeFormat(navigator.language, { 103 + numeric: 'auto', 104 + style: 'long' 105 + }); 106 + } 107 + return this._rtf; 108 + } 109 + 110 formatRelative(diff) { 111 + const rtf = this.getRtf(); 112 113 const absDiff = Math.abs(diff); 114 const sign = diff > 0 ? -1 : 1; ··· 116 const minutes = Math.floor(seconds / 60); 117 const hours = Math.floor(minutes / 60); 118 const days = Math.floor(hours / 24); 119 + const date = new Date(Date.now() - diff); 120 + const now = new Date(); 121 + const months = (now.getFullYear() - date.getFullYear()) * 12 + (now.getMonth() - date.getMonth()); 122 + const years = Math.floor(Math.abs(months) / 12) * sign; 123 124 if (seconds < 60) { 125 return rtf.format(sign * seconds, 'second'); ··· 129 return rtf.format(sign * hours, 'hour'); 130 } else if (days < 30) { 131 return rtf.format(sign * days, 'day'); 132 + } else if (Math.abs(months) < 12) { 133 + return rtf.format(months, 'month'); 134 } else { 135 + return rtf.format(years, 'year'); 136 } 137 } 138