Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getBlocksForYear(year, data, fullYear) {
const now = new Date();
const firstDate = fullYear ? subYears(now, 1) : parse(`${year}-01-01`);
const lastDate = fullYear ? now : parse(`${year}-12-31`);
let weekStart = firstDate;
// The week starts on Sunday - add days to get to next sunday if neccessary
if (getDay(firstDate) !== 0) {
weekStart = addDays(firstDate, getDay(firstDate));
}
// Fetch graph data for first row (Sundays)
const firstRowDates = [];
while (weekStart <= lastDate) {
const date = format(weekStart, DATE_FORMAT);
firstRowDates.push({
date,
async submit() {
const { operation, submodel, assetStart, assetEnd } = this.state;
const { location } = this.context.user;
const startDate = parse(assetStart);
const endDate = parse(assetEnd);
if (!this.state.operation)
return alert('Please specify required operation');
if (!this.state.assetStart || !startDate || !isValid(startDate) || !isFuture(startDate))
return alert('Please enter a valid date/time when the request starts');
if (!this.state.assetEnd || !endDate || !isValid(endDate) || compareDesc(startDate, endDate) !== 1)
return alert('Please enter a valid date/time when the request ends');
const submodelValues = {};
submodel.forEach(({ semanticId, value, valueType }) => {
if (['date', 'dateTime', 'dateTimeStamp'].includes(valueType)) {
submodelValues[semanticId] = Date.parse(value);
} if (valueType === 'boolean') {
submodelValues[semanticId] = Boolean(value);
value(value, oldValue) {
const newDate = parse(value);
const oldDate = parse(oldValue);
if (isEqual(newDate, oldDate))
return;
this.initDate();
},
},
updateYears(props = this.props) {
this._min = parse(props.min);
this._max = parse(props.max);
this._minDate = parse(props.minDate);
this._maxDate = parse(props.maxDate);
const min = this._min.getFullYear();
const minMonth = this._min.getMonth();
const max = this._max.getFullYear();
const maxMonth = this._max.getMonth();
const months = [];
let year, month;
for (year = min; year <= max; year++) {
for (month = 0; month < 12; month++) {
if (
year === min && month < minMonth ||
year === max && month > maxMonth
) {
continue;
}
function parseDate(str, format, locale) {
const parsed = dateFnsParse(str, format, { locale });
if (DateUtils.isDate(parsed)) {
return parsed;
}
return undefined;
}
export const formatTime = (time, options = DEFAULT_TIME_FORMAT) => {
const parsedTime = dateParse(time);
return dateFormat(parsedTime, options);
};
dateFormat = dateFormat
.match(longFormattingTokensRegExp)
.map(function(substring) {
var firstCharacter = substring[0];
if (firstCharacter === "p" || firstCharacter === "P") {
var longFormatter = longFormatters[firstCharacter];
return localeObject
? longFormatter(substring, localeObject.formatLong)
: firstCharacter;
}
return substring;
})
.join("");
if (value.length > 0) {
parsedDate = parse(value, dateFormat.slice(0, value.length), new Date());
}
if (!isValid(parsedDate)) {
parsedDate = new Date(value);
}
}
return isValid(parsedDate) && strictParsingValueMatch ? parsedDate : null;
}
export function queryStringTo(): Date {
const { to } = currentQueryString();
if (!to) {
return endOfWeek(new Date(), { weekStartsOn: 1 });
}
return parse(to);
}
function handleYearSelect(date, {displayKey, onSelect, selected, setScrollDate}) {
setScrollDate(date);
onSelect(getSortedSelection(
Object.assign({}, selected, {[displayKey]: parse(date)}))
);
}