2020-09-14 09:44:26 +00:00
|
|
|
import fromUnixTime from 'date-fns/fromUnixTime';
|
|
|
|
import format from 'date-fns/format';
|
2020-12-24 13:23:47 +00:00
|
|
|
import isToday from 'date-fns/isToday';
|
|
|
|
import isYesterday from 'date-fns/isYesterday';
|
2021-03-13 06:14:28 +00:00
|
|
|
import parseISO from 'date-fns/parseISO';
|
2019-12-14 18:36:01 +00:00
|
|
|
|
2020-09-14 09:44:26 +00:00
|
|
|
export const formatUnixDate = (date, dateFormat = 'MMM dd, yyyy') => {
|
|
|
|
const unixDate = fromUnixTime(date);
|
|
|
|
return format(unixDate, dateFormat);
|
|
|
|
};
|
2020-12-24 13:23:47 +00:00
|
|
|
|
|
|
|
export const formatDate = ({ date, todayText, yesterdayText }) => {
|
|
|
|
const dateValue = new Date(date);
|
|
|
|
if (isToday(dateValue)) return todayText;
|
|
|
|
if (isYesterday(dateValue)) return yesterdayText;
|
|
|
|
return date;
|
|
|
|
};
|
2021-03-13 06:14:28 +00:00
|
|
|
|
2021-03-13 08:36:25 +00:00
|
|
|
export const formatDigitToString = val => {
|
|
|
|
return val > 9 ? `${val}` : `0${val}`;
|
|
|
|
};
|
|
|
|
|
2021-03-13 06:14:28 +00:00
|
|
|
export const buildDateFromTime = (hr, min, utcOffset, date = new Date()) => {
|
|
|
|
const today = format(date, 'yyyy-MM-dd');
|
2021-03-13 08:36:25 +00:00
|
|
|
const hour = formatDigitToString(hr);
|
|
|
|
const minute = formatDigitToString(min);
|
|
|
|
const timeString = `${today}T${hour}:${minute}:00${utcOffset}`;
|
2021-03-13 06:14:28 +00:00
|
|
|
return parseISO(timeString);
|
|
|
|
};
|