Chatwoot/app/javascript/shared/helpers/DateHelper.js
Nithin David Thomas 6c87001a0e
Feat: Show working hours on widget (#1823)
Feat: Display out of office message based on business hours

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
2021-03-13 11:44:28 +05:30

27 lines
897 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';
import parseISO from 'date-fns/parseISO';
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 buildDateFromTime = (hr, min, utcOffset, date = new Date()) => {
const today = format(date, 'yyyy-MM-dd');
const timeString = `${today}T${hr}:${min}:00${utcOffset}`;
return parseISO(timeString);
};
export const formatDigitToString = val => {
return val > 9 ? `${val}` : `0${val}`;
};