Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
timeChangeInfo: function(from, to) {
if (!to) { // guard statement
throw new Error('You have not provided a `to` datetime string');
}
// the "from" and "to" fields of a time change are always timezone-naive
// timestamps by definition (b/c they are device-relative time)
// but some (versions) of (some) browsers like to coerce timestamps without TZ info into local time
// and we need to prevent that, so we use moment.utc and then use the UTC
// variant of all JS Date methods to ensure consistency across browsers
var fromDate = from ? moment.utc(from).toDate() : undefined;
var toDate = moment.utc(to).toDate();
var type = 'Time Change';
var format = 'h:mm a';
if (fromDate && toDate) {
if (fromDate.getUTCFullYear() !== toDate.getUTCFullYear()) {
format = 'MMM D, YYYY h:mm a';
} else if (
fromDate.getUTCMonth() !== toDate.getUTCMonth() ||
fromDate.getUTCDay() !== toDate.getUTCDay()
) {
format = 'MMM D, h:mm a';
}
if (Math.abs(toDate - fromDate) <= (8*(60*1000))) { // Clock Drift Adjustment if less than 8 minutes
type = 'Clock Drift Adjustment';
const submissionEndTime: any = moment(feedbackSession.submissionEndTimestamp);
this.formattedSessionClosingTime = submissionEndTime
.tz(feedbackSession.timeZone).format(TIME_FORMAT);
this.feedbackSessionSubmissionStatus = feedbackSession.submissionStatus;
// don't show alert modal in moderation
if (!this.moderatedPerson) {
switch (feedbackSession.submissionStatus) {
case FeedbackSessionSubmissionStatus.VISIBLE_NOT_OPEN:
this.isSubmissionFormsDisabled = true;
this.modalService.open(FeedbackSessionNotOpenModalComponent);
break;
case FeedbackSessionSubmissionStatus.OPEN:
// closing in 15 minutes
if (moment.utc().add(15, 'minutes').isAfter(submissionEndTime)) {
this.modalService.open(FeedbackSessionClosingSoonModalComponent);
}
break;
case FeedbackSessionSubmissionStatus.CLOSED:
this.isSubmissionFormsDisabled = true;
this.modalService.open(FeedbackSessionClosedModalComponent);
break;
case FeedbackSessionSubmissionStatus.GRACE_PERIOD:
default:
}
}
this.loadFeedbackQuestions();
}, (resp: ErrorMessageOutput) => {
if (resp.status === 404) {
const sameDay = (utc, timezone) => {
const { years, months, date } = moment.utc(utc).toObject();
return moment.tz([years, months, date], timezone);
};
export default (start, end = undefined) => {
if (!start && !end) {
return null;
}
const diff = moment
.utc(end ? moment.utc(end) : moment.utc())
.diff(moment.utc(start), 'seconds', false);
const MINUTE = 60;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const days = Math.floor(diff / DAY);
const hours = Math.floor((diff - days * DAY) / HOUR);
const minutes = Math.floor((diff - days * DAY - hours * HOUR) / MINUTE);
const seconds = diff - days * DAY - hours * HOUR - minutes * MINUTE;
const plural = (count, word) => `${count} ${word}${count === 1 ? '' : 's'}`;
if (days > 0) {
return plural(days, 'day');
}
if (hours > 0) {
return plural(hours, 'hour');
}
componentWillUnmount () {
clearInterval(this.updateInterval);
localStorage.setItem('LAST_VISITED', moment.utc().format('YYYY-MM-DD HH:mm:ss'));
window.removeEventListener('resize', this.onWindowResized);
}
}
const sameDayUTC = (utc, timezone) => {
const { years, months, date } = moment.utc(utc).tz(timezone).toObject();
return moment.utc([years, months, date]);
};
.tz(timezone)
.subtract(1, 'day')
.toDate();
dateBoundaries.push(
startOfDate.toISOString()
);
last = startOfDate;
}
dateBoundaries.reverse();
const selected = { dataByDate: {}, dateRange: [], timezone };
for (let i = 0; i < numDays; ++i) {
const thisDateStart = dateBoundaries[i];
const thisDateEnd = dateBoundaries[i + 1];
const date = moment.utc(Date.parse(thisDateStart))
.tz(timezone)
.format('YYYY-MM-DD');
selected.dataByDate[date] = {
bounds: [Date.parse(thisDateStart), Date.parse(thisDateEnd)],
date,
data: _.mapValues(groupedData, (dataForType) => {
if (_.isEmpty(dataForType)) {
return [];
}
const filterFn = _.includes(['basal', 'bolus'], dataForType[0].type) ?
filterWithDurationFnMaker(thisDateStart, thisDateEnd) :
filterPointInTimeFnMaker(thisDateStart, thisDateEnd);
return _.sortBy(_.map(
_.filter(dataForType, filterFn),
(d) => {
const reshaped = stripDatum(d);
getScheduledBackupInstances(req, res) {
if (req.query.start_time && !moment(req.query.start_time, CONST.REPORT_BACKUP.INPUT_DATE_FORMAT, true).isValid()) {
throw new BadRequest(`Invalid start date, required format ${CONST.REPORT_BACKUP.INPUT_DATE_FORMAT}`);
}
if (req.query.end_time && !moment(req.query.end_time, CONST.REPORT_BACKUP.INPUT_DATE_FORMAT, true).isValid()) {
throw new BadRequest(`Invalid end date, required format ${CONST.REPORT_BACKUP.INPUT_DATE_FORMAT}`);
}
const start_time = req.query.start_time ? moment.utc(req.query.start_time).toDate() : undefined;
const end_time = req.query.end_time ? moment.utc(req.query.end_time).endOf('day').toDate() : undefined;
return BackupReportManager
.getInstancesWithBackupScheduled(start_time, end_time)
.then(body => res
.status(200)
.send(body));
}
if (isIndexString(indexString)) {
return indexString;
} else if (!_.isNaN(parseInt(parts[0], 10)) && !_.isNaN(parseInt(parts[1], 10))) {
const parsedYear = parseInt(parts[0], 10);
const parsedMonth = parseInt(parts[1], 10);
t = moment.utc([parsedYear, parsedMonth - 1]);
if (format) {
return t.format(format);
} else {
return t.format("MMMM");
}
}
break;
case 1:
const year = parts[0];
t = moment.utc([year]);
if (format) {
return t.format(format);
} else {
return t.format("YYYY");
}
}
return indexString;
}