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>
This commit is contained in:
Nithin David Thomas
2021-03-13 11:44:28 +05:30
committed by GitHub
parent 1d2e1a2823
commit 6c87001a0e
8 changed files with 119 additions and 21 deletions

View File

@@ -2,6 +2,7 @@ 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);
@@ -14,3 +15,13 @@ export const formatDate = ({ date, todayText, yesterdayText }) => {
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}`;
};

View File

@@ -1,4 +1,9 @@
import { formatDate, formatUnixDate } from '../DateHelper';
import {
formatDate,
formatUnixDate,
buildDateFromTime,
formatDigitToString,
} from '../DateHelper';
describe('#DateHelper', () => {
it('should format unix date correctly without dateFormat', () => {
@@ -39,4 +44,27 @@ describe('#DateHelper', () => {
})
).toEqual('Yesterday');
});
describe('#buildDate', () => {
it('returns correctly parsed date', () => {
const date = new Date();
date.setFullYear(2021);
date.setMonth(2);
date.setDate(5);
const result = buildDateFromTime(12, 15, '.465Z', date);
expect(result + '').toEqual(
'Fri Mar 05 2021 12:15:00 GMT+0000 (Coordinated Universal Time)'
);
});
});
describe('#formatDigitToString', () => {
it('returns date compatabile string from number is less than 9', () => {
expect(formatDigitToString(8)).toEqual('08');
});
it('returns date compatabile string from number is greater than 9', () => {
expect(formatDigitToString(11)).toEqual('11');
});
});
});