import moment from 'moment-timezone';
/**
* Convert the users weigh in date to take into account there timezone
*
* @param {string} weighInDate - The users next weigh in date in UTC format
* @param {string} timeZoneId - The users timezone set in the account
*
* @example
* convertWeighInDay({
* weighInDate: '2019-08-21T15:17:36.2445068Z',
* timeZoneId: 'America/Chicago'
* })
* @return {object} A moment object
*/
export const convertWeighInDay = ({ weighInDate, timeZoneId }) =>
moment(weighInDate).tz(timeZoneId);
/**
* Check if the users weighInDay is before today's day of the week
*
* @param {object} weighInDay - Numeric value 1 - 7 from users profile
*)
* @return {bool} - A bool value depending if the users weigh in day today or
* in the past
*/
export const onOrAfterWeighInDay = weighInDay => {
const weighInDayDate = moment()
.startOf('week')
.add(weighInDay, 'd');
return moment().isSameOrAfter(weighInDayDate, 'd');
};
/**
* Check if the user has a saved weigh in for the current week
*
* @param {(object\|undefined)} savedWeighIn - If set
* will include information about the current week weigh in
*
* @example noCurrentWeekWeighIn({ savedWeighIn })
* @return {bool} If there savedWeighIn object is not undefined it will return
* has false
*/
export const noCurrentWeekWeighIn = ({ savedWeighIn }) => savedWeighIn === undefined;
/**
* Check if the user has set a weekly commitment for the current weigh in
*
* @param {bool} isCurrentWeighInFinished - If user has completed there current
* weeks weigh in
* @param {(object\|undefined)} savedWeighIn - If set
* will include information about the current week weigh in
*
* @example weeklyGoalSet({isCurrentWeighInFinished: true, savedWeighIn })
* @return {bool} - If weekly goal is set will return this will result true
* otherwise it will return false
*/
export const weeklyGoalSet = ({ isCurrentWeighInFinished, savedWeighIn }) => {
if (isCurrentWeighInFinished !== null) {
const { emotion, commitment } = savedWeighIn || {};
if (emotion === null || commitment === null) {
return false;
}
}
return true;
};