misc: gpt did a goofy

This commit is contained in:
Xyphyn committed 2023-07-06 17:06:11 -07:00
1 parent 3c239ce21c
commit 66eca58d01
3 files changed
+10 -12

No files matched your search

+2 -7
View File
@@ -4,10 +4,8 @@
function formatRelativeDate(date: Date) {
const now = Date.now()
// Calculate the difference in milliseconds between 'now' and 'date'
const diffInMillis = now - date.getTime()
// Define time thresholds for different units (milliseconds)
const thresholds = [
{ unit: 'second', threshold: 1000 },
{ unit: 'minute', threshold: 60 * 1000 },
@@ -16,16 +14,13 @@
{ unit: 'week', threshold: 7 * 24 * 60 * 60 * 1000 },
{ unit: 'month', threshold: 30 * 24 * 60 * 60 * 1000 },
{ unit: 'year', threshold: 365 * 24 * 60 * 60 * 1000 },
// You can add more units as needed, e.g., week, month, year
]
// Iterate through the thresholds to find the appropriate unit to display
for (let i = thresholds.length - 1; i >= 0; i--) {
if (diffInMillis >= thresholds[i].threshold) {
const value = Math.round(diffInMillis / thresholds[i].threshold)
// Create a RelativeTimeFormat instance with user's locale and options
const rtf = new Intl.RelativeTimeFormat(navigator.language, {
const rtf = new Intl.RelativeTimeFormat('en', {
numeric: 'always',
style: 'long',
})
@@ -34,7 +29,7 @@
}
}
return 'Now' // If none of the above conditions match defaulting to "Now"
return 'Now'
}
</script>