Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (Z && !("Z" in d)) d.Z = 0;
// The am-pm flag is 0 for AM, and 1 for PM.
if ("p" in d) d.H = d.H % 12 + d.p * 12;
// If the month was not specified, inherit from the quarter.
if (d.m === undefined) d.m = "q" in d ? d.q : 0;
// Convert day-of-week and week-of-year to day-of-year.
if ("V" in d) {
if (d.V < 1 || d.V > 53) return null;
if (!("w" in d)) d.w = 1;
if ("Z" in d) {
week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
week = utcDay.offset(week, (d.V - 1) * 7);
d.y = week.getUTCFullYear();
d.m = week.getUTCMonth();
d.d = week.getUTCDate() + (d.w + 6) % 7;
} else {
week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
week = day > 4 || day === 0 ? timeMonday.ceil(week) : timeMonday(week);
week = timeDay.offset(week, (d.V - 1) * 7);
d.y = week.getFullYear();
d.m = week.getMonth();
d.d = week.getDate() + (d.w + 6) % 7;
}
} else if ("W" in d || "U" in d) {
if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
d.m = 0;
d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
mountData(props = this.props) {
// find initial date domain (based on initialDatetimeLocation or current time)
const { extentSize, initialDatetimeLocation, timePrefs } = props;
const timezone = datetime.getTimezoneFromTimePrefs(timePrefs);
const mostRecent = datetime.getLocalizedCeiling(new Date().valueOf(), timezone);
const end = initialDatetimeLocation
? datetime.getLocalizedCeiling(initialDatetimeLocation, timezone)
: mostRecent;
const start = utcDay.offset(end, -extentSize);
const dateDomain = [start.toISOString(), end.toISOString()];
const state = {
dateDomain: { start: dateDomain[0], end: dateDomain[1] },
mostRecent: mostRecent.toISOString(),
};
this.setState(state, this.determineDataToShow);
props.onDatetimeLocationChange(dateDomain, end === mostRecent);
}
goToMostRecent() {
const { mostRecent: end } = this.state;
const start = utcDay.offset(new Date(end), -this.props.extentSize).toISOString();
const newDomain = [start, end];
this.setExtent(newDomain);
}
goForward() {
const oldDomain = _.clone(this.state.dateDomain);
const { dateDomain: { end: newStart } } = this.state;
const end = utcDay.offset(new Date(newStart), this.props.extentSize).toISOString();
const newDomain = [newStart, end];
this.setExtent(newDomain, [oldDomain.start, oldDomain.end]);
}
goForward() {
const oldDomain = _.clone(this.state.dateDomain);
const { dateDomain: { end: newStart } } = this.state;
const end = utcDay.offset(new Date(newStart), this.props.extentSize).toISOString();
const newDomain = [newStart, end];
this.setExtent(newDomain, [oldDomain.start, oldDomain.end]);
}
return (dispatch) => {
const sorted = _.sortBy(
_.filter(data, (d) => (_.includes(types, d.type))),
'time'
);
const thirtyDaysAgo = utcDay.offset(new Date(), -30).toISOString();
const indexAtThirtyDaysAgo = _.findLastIndex(sorted, (d) => (d.time < thirtyDaysAgo)) + 1;
const mostRecentThirtyDaysData = sorted.splice(indexAtThirtyDaysAgo);
dispatch(workerProcessDataRequest(id, mostRecentThirtyDaysData, timePrefs));
dispatch(workerProcessDataRequest(id, sorted, timePrefs));
};
}
goToMostRecent() {
const { mostRecent: end } = this.state;
const start = utcDay.offset(new Date(end), -this.props.extentSize).toISOString();
const newDomain = [start, end];
this.setExtent(newDomain);
}