@socketsupply/components
Advanced tools
Comparing version 14.0.6 to 14.0.7
{ | ||
"name": "@socketsupply/components", | ||
"version": "14.0.6", | ||
"version": "14.0.7", | ||
"description": "Example components", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -207,6 +207,5 @@ import { Tonic } from '@socketsupply/tonic' | ||
export class RelativeTime { | ||
constructor (date, locale, shortUnits) { | ||
constructor (date, locale) { | ||
this.date = date | ||
this.locale = locale | ||
this.shortUnits = shortUnits | ||
} | ||
@@ -275,25 +274,25 @@ | ||
if (ms < 0) { | ||
return formatRelativeTime(locale, 0, 'second', this.shortUnits) | ||
return formatRelativeTime(locale, 0, 'second') | ||
} else if (sec < 10) { | ||
return formatRelativeTime(locale, 0, 'second', this.shortUnits) | ||
return formatRelativeTime(locale, 0, 'second') | ||
} else if (sec < 45) { | ||
return formatRelativeTime(locale, -sec, 'second', this.shortUnits) | ||
return formatRelativeTime(locale, -sec, 'second') | ||
} else if (sec < 90) { | ||
return formatRelativeTime(locale, -min, 'minute', this.shortUnits) | ||
return formatRelativeTime(locale, -min, 'minute') | ||
} else if (min < 45) { | ||
return formatRelativeTime(locale, -min, 'minute', this.shortUnits) | ||
return formatRelativeTime(locale, -min, 'minute') | ||
} else if (min < 90) { | ||
return formatRelativeTime(locale, -hr, 'hour', this.shortUnits) | ||
return formatRelativeTime(locale, -hr, 'hour') | ||
} else if (hr < 24) { | ||
return formatRelativeTime(locale, -hr, 'hour', this.shortUnits) | ||
return formatRelativeTime(locale, -hr, 'hour') | ||
} else if (hr < 36) { | ||
return formatRelativeTime(locale, -day, 'day', this.shortUnits) | ||
return formatRelativeTime(locale, -day, 'day') | ||
} else if (day < 30) { | ||
return formatRelativeTime(locale, -day, 'day', this.shortUnits) | ||
return formatRelativeTime(locale, -day, 'day') | ||
} else if (month < 12) { | ||
return formatRelativeTime(locale, -month, 'month', this.shortUnits) | ||
return formatRelativeTime(locale, -month, 'month') | ||
} else if (month < 18) { | ||
return formatRelativeTime(locale, -year, 'year', this.shortUnits) | ||
return formatRelativeTime(locale, -year, 'year') | ||
} else { | ||
return formatRelativeTime(locale, -year, 'year', this.shortUnits) | ||
return formatRelativeTime(locale, -year, 'year') | ||
} | ||
@@ -316,25 +315,25 @@ } | ||
if (month >= 18) { | ||
return formatRelativeTime(locale, year, 'year', this.shortUnits) | ||
return formatRelativeTime(locale, year, 'year') | ||
} else if (month >= 12) { | ||
return formatRelativeTime(locale, year, 'year', this.shortUnits) | ||
return formatRelativeTime(locale, year, 'year') | ||
} else if (day >= 45) { | ||
return formatRelativeTime(locale, month, 'month', this.shortUnits) | ||
return formatRelativeTime(locale, month, 'month') | ||
} else if (day >= 30) { | ||
return formatRelativeTime(locale, month, 'month', this.shortUnits) | ||
return formatRelativeTime(locale, month, 'month') | ||
} else if (hr >= 36) { | ||
return formatRelativeTime(locale, day, 'day', this.shortUnits) | ||
return formatRelativeTime(locale, day, 'day') | ||
} else if (hr >= 24) { | ||
return formatRelativeTime(locale, day, 'day', this.shortUnits) | ||
return formatRelativeTime(locale, day, 'day') | ||
} else if (min >= 90) { | ||
return formatRelativeTime(locale, hr, 'hour', this.shortUnits) | ||
return formatRelativeTime(locale, hr, 'hour') | ||
} else if (min >= 45) { | ||
return formatRelativeTime(locale, hr, 'hour', this.shortUnits) | ||
return formatRelativeTime(locale, hr, 'hour') | ||
} else if (sec >= 90) { | ||
return formatRelativeTime(locale, min, 'minute', this.shortUnits) | ||
return formatRelativeTime(locale, min, 'minute') | ||
} else if (sec >= 45) { | ||
return formatRelativeTime(locale, min, 'minute', this.shortUnits) | ||
return formatRelativeTime(locale, min, 'minute') | ||
} else if (sec >= 10) { | ||
return formatRelativeTime(locale, sec, 'second', this.shortUnits) | ||
return formatRelativeTime(locale, sec, 'second') | ||
} else { | ||
return formatRelativeTime(locale, 0, 'second', this.shortUnits) | ||
return formatRelativeTime(locale, 0, 'second') | ||
} | ||
@@ -364,3 +363,3 @@ } | ||
function formatRelativeTime (locale, value, unit, isShort) { | ||
function formatRelativeTime (locale, value, unit) { | ||
const formatter = makeRelativeFormat(locale, { numeric: 'auto' }) | ||
@@ -371,3 +370,3 @@ | ||
} else { | ||
return formatEnRelativeTime(value, unit, isShort) | ||
return formatEnRelativeTime(value, unit) | ||
} | ||
@@ -381,3 +380,3 @@ } | ||
// | ||
function formatEnRelativeTime (value, unit, isShort) { | ||
function formatEnRelativeTime (value, unit) { | ||
if (value === 0) { | ||
@@ -389,3 +388,3 @@ switch (unit) { | ||
case 'week': | ||
return `this ${isShort ? unit[0] : unit}` | ||
return `this ${unit}` | ||
case 'day': | ||
@@ -395,3 +394,3 @@ return 'today' | ||
case 'minute': | ||
return `in 0 ${isShort ? unit[0] : unit + 's'}` | ||
return `in 0 ${unit}s` | ||
case 'second': | ||
@@ -406,3 +405,3 @@ return 'now' | ||
case 'week': | ||
return `next ${isShort ? unit[0] : unit}` | ||
return `next ${unit}` | ||
case 'day': | ||
@@ -413,3 +412,3 @@ return 'tomorrow' | ||
case 'second': | ||
return `in 1 ${isShort ? unit[0] : unit}` | ||
return `in 1 ${unit}` | ||
} | ||
@@ -422,3 +421,3 @@ } else if (value === -1) { | ||
case 'week': | ||
return `last ${isShort ? unit[0] : unit}` | ||
return `last ${unit}` | ||
case 'day': | ||
@@ -429,3 +428,3 @@ return 'yesterday' | ||
case 'second': | ||
return `1 ${isShort ? unit[0] : unit} ago` | ||
return `1 ${unit} ago` | ||
} | ||
@@ -442,3 +441,3 @@ } else if (value > 1) { | ||
case 'second': | ||
return `in ${value} ${isShort ? unit[0] : unit + 's'}` | ||
return `in ${value} ${unit}s` | ||
} | ||
@@ -455,3 +454,3 @@ } else if (value < -1) { | ||
case 'second': | ||
return `${-value} ${isShort ? unit[0] : unit + 's'} ago` | ||
return `${-value} ${unit}s ago` | ||
} | ||
@@ -469,7 +468,3 @@ } | ||
if (typeof date === 'string') { | ||
date = this.props.date = | ||
// If its a unix timestamp, pass it as a number | ||
/^[0-9]+$/.test(this.props.date) | ||
? new Date(+this.props.date) | ||
: new Date(this.props.date) | ||
date = this.props.date = new Date(+this.props.date) | ||
} | ||
@@ -495,4 +490,5 @@ | ||
const t = new RelativeTime(date, locale, this.props.shortUnits) | ||
return t.toString() | ||
const t = new RelativeTime(date, locale) | ||
const s = t.toString() | ||
return this.props.shortUnits ? s.replace(/ (\w+) .*/, (_, w) => w[0]) : s | ||
} | ||
@@ -499,0 +495,0 @@ } |
278680
8709