this.findOffsetDifferences = function(event) { var ROUND_TO_NEAREST = 30; var offsetDiff = Math.round( // Some timezones have offsets at the resolution of 30 or even 15 minutes, // so we round to the nearest 30 minutes whenever we see an offset change // to maintain some parallelism between our timezoneOffset value // and the actual timezone offsets that exist in the world. // We used to round to the nearest 15 minutes, but that was too low of a // resolution for some users' clock drift adjustments. sundial.dateDifference(event.change.from, event.change.to, 'minutes')/ROUND_TO_NEAREST ) * ROUND_TO_NEAREST; return { offsetDifference: offsetDiff, rawDifference: sundial.dateDifference(event.change.from, event.change.to, 'seconds') * MS_IN_SEC }; };
getDiagnosisText: function(patient, currentDate) { var patientInfo = personUtils.patientInfo(patient) || {}; var diagnosisDate = patientInfo.diagnosisDate; if (!diagnosisDate) { return; } var now = new Date(); currentDate = currentDate || Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()); var yrsAgo = sundial.dateDifference(currentDate, diagnosisDate, 'years'); if (yrsAgo === 0) { return 'Diagnosed this year'; } else if (yrsAgo === 1) { return 'Diagnosed 1 year ago'; } else if (yrsAgo > 1) { return 'Diagnosed ' + yrsAgo + ' years ago'; } else if (yrsAgo === 0) { return 'Diagnosed this year'; } else { return 'Diagnosis date not known'; } },
calculateTimeAgoMessage(timestamp) { const { t } = this.props; /* The following is for the translation extracter */ // t('year', {context: 'timeago'});t('years', {context: 'timeago'}); // t('month', {context: 'timeago'});t('months', {context: 'timeago'}); // t('week', {context: 'timeago'});t('weeks', {context: 'timeago'}); // t('day', {context: 'timeago'});t('days', {context: 'timeago'}); // t('hour', {context: 'timeago'});t('hours', {context: 'timeago'}); // t('minute', {context: 'timeago'});t('minutes', {context: 'timeago'}); if (timestamp) { for (const units of ['year', 'month', 'week', 'day', 'hour', 'minute']) { let diff = sundial.dateDifference(this.state.now, timestamp, units); if (diff > 1) { const unit = t(units+'s', {context: 'timeago'}); return t('{{diff}} {{unit}} ago_plural', {diff, unit}); } else if (diff > 0) { const unit = t(units, {context: 'timeago'}); return t('{{diff}} {{unit}} ago', {diff, unit}); } else if (diff < 0) { return t('unknown'); } } return t('a few seconds ago'); } return t('unknown'); }
handleCarbHover = carb => { var rect = carb.rect; // range here is -12 to 12 var hoursOffset = sundial.dateDifference(carb.data.normalTime, this.state.datetimeLocation, 'h'); carb.top = rect.top + (rect.height / 2) if(hoursOffset > 5) { carb.side = 'left'; carb.left = rect.left; } else { carb.side = 'right'; carb.left = rect.left + rect.width; } this.setState({ hoveredCarb: carb }); };
handleSMBGHover = smbg => { const rect = smbg.rect; // range here is -12 to 12 const hoursOffset = sundial.dateDifference(smbg.data.normalTime, this.state.datetimeLocation, 'h'); smbg.top = rect.top + (rect.height / 2) if(hoursOffset > 5) { smbg.side = 'left'; smbg.left = rect.left; } else { smbg.side = 'right'; smbg.left = rect.left + rect.width; } this.setState({ hoveredSMBG: smbg }); };
handleBolusHover = bolus => { const rect = bolus.rect; // range here is -12 to 12 const hoursOffset = sundial.dateDifference(bolus.data.normalTime, this.state.datetimeLocation, 'h'); bolus.top = rect.top + (rect.height / 2) if(hoursOffset > 5) { bolus.side = 'left'; bolus.left = rect.left; } else { bolus.side = 'right'; bolus.left = rect.left + rect.width; } this.setState({ hoveredBolus: bolus }); };
handleCBGHover = cbg => { this.throttledMetric('hovered over daily cgm tooltip'); var rect = cbg.rect; // range here is -12 to 12 var hoursOffset = sundial.dateDifference(cbg.data.normalTime, this.state.datetimeLocation, 'h'); cbg.top = rect.top + (rect.height / 2) if(hoursOffset > 5) { cbg.side = 'left'; cbg.left = rect.left; } else { cbg.side = 'right'; cbg.left = rect.left + rect.width; } this.setState({ hoveredCBG: cbg }); };
getAgeText: function(patient) { var patientInfo = personUtils.patientInfo(patient) || {}; var birthday = patientInfo.birthday; if (!birthday) { return; } var yrsAgo = sundial.dateDifference(new Date(), birthday, 'years'); if (yrsAgo === 1) { return '1 year old'; } else if (yrsAgo > 1) { return yrsAgo +' years old'; } else { return 'Birthdate not known'; } },
getDiagnosisText: function(patient) { var patientInfo = personUtils.patientInfo(patient) || {}; var diagnosisDate = patientInfo.diagnosisDate; if (!diagnosisDate) { return; } var yrsAgo = sundial.dateDifference(new Date(), diagnosisDate, 'years'); if (yrsAgo === 0) { return 'Diagnosed this year'; } else if (yrsAgo === 1) { return 'Diagnosed 1 year ago'; } else if (yrsAgo > 1) { return 'Diagnosed ' + yrsAgo + ' years ago'; } else { return 'Diagnosis date not known'; } },
getAgeText: function(patient, currentDate) { var patientInfo = personUtils.patientInfo(patient) || {}; var birthday = patientInfo.birthday; if (!birthday) { return; } var now = new Date(); currentDate = currentDate || Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()); var yrsAgo = sundial.dateDifference(currentDate, birthday, 'years'); if (yrsAgo === 1) { return '1 year old'; } else if (yrsAgo > 1) { return yrsAgo +' years old'; } else if (yrsAgo === 0) { return 'Born this year'; } else { return 'Birthdate not known'; } },
isValidDate: function(dateString){ // check to see if date is proper and not in the future return (sundial.isValidDateForMask(dateString, 'YYYY-MM-DD')) && (sundial.dateDifference(new Date(), dateString, 'd') > 0); },