mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-20 21:15:01 +00:00
* feat: Show next available hour and minutes on widget * chore: Adds spec * chore: Show days * chore: Code clean up * chore: Review fixes * chore: Minor fixes * chore: Review suggestion fixes * chore: Minor fixes * Added timezone to widget payload * chore: Adds time zone * chore: Review fixes * chore: Adds comments * chore: Rounded up min with nearest multiple of 5 * chore: Review fixes * chore: Review fixes * chore: Review fixes * chore: Review fixes * chore: Fix specs * chore: Review fixes * chore: Fix specs * chore: Review fixes * chore: Moved day names to i18n * chore: Review fixes * chore: Fix specs --------- Co-authored-by: Tejaswini Chile <tejaswini@chatwoot.com> Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
40 lines
982 B
JavaScript
40 lines
982 B
JavaScript
import fromUnixTime from 'date-fns/fromUnixTime';
|
|
import format from 'date-fns/format';
|
|
import isToday from 'date-fns/isToday';
|
|
import isYesterday from 'date-fns/isYesterday';
|
|
|
|
export const formatUnixDate = (date, dateFormat = 'MMM dd, yyyy') => {
|
|
const unixDate = fromUnixTime(date);
|
|
return format(unixDate, dateFormat);
|
|
};
|
|
|
|
export const formatDate = ({ date, todayText, yesterdayText }) => {
|
|
const dateValue = new Date(date);
|
|
if (isToday(dateValue)) return todayText;
|
|
if (isYesterday(dateValue)) return yesterdayText;
|
|
return date;
|
|
};
|
|
|
|
export const formatDigitToString = val => {
|
|
return val > 9 ? `${val}` : `0${val}`;
|
|
};
|
|
|
|
export const isTimeAfter = (h1, m1, h2, m2) => {
|
|
if (h1 < h2) {
|
|
return false;
|
|
}
|
|
|
|
if (h1 === h2) {
|
|
return m1 >= m2;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
export const generateRelativeTime = (value, unit, languageCode) => {
|
|
const rtf = new Intl.RelativeTimeFormat(languageCode, {
|
|
numeric: 'auto',
|
|
});
|
|
return rtf.format(value, unit);
|
|
};
|