Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function formatDTSTART(string, tz) {
if (!string) {
return 'DTSTART:' + moment().format('YYYYMMDD');
}
if (tz) {
// Form #3: DATE WITH LOCAL TIME AND TIME ZONE REFERENCE
return 'DTSTART;TZID=' + tz + ':' + moment(string).format('YYYYMMDDTHHmm00');
}
if (isDateTime(string) && moment.parseZone(string).utcOffset() === 0 && !isUTC(string)) {
// Form #1: DATE WITH LOCAL TIME
return 'DTSTART:' + moment(string).format('YYYYMMDDTHHmm00');
}
if (isDateTime(string)) {
// Form #2: DATE WITH UTC TIME
return 'DTSTART:' + moment.utc(string).format('YYYYMMDDTHHmm00') + 'Z';
}
return 'DTSTART;VALUE=DATE:' + moment(string).format('YYYYMMDD');
}
activity = _.sortBy( activity, a => ( moment.parseZone( a.created_at ) ) );
// attempting to match the logic in the computervision/score_observation endpoint
const date = (...args) => {
let d;
if (args.length === 1) {
const arg = args[0];
if (typeof arg === 'string') {
try {
d = arg === '' ? moment.parseZone(UTCTimePart, time_ISO_8601) : parseDate(arg);
} catch (err) {
throw err;
}
} else if (typeof arg === 'object') {
if (arg instanceof Date) {
const ISO = arg.toISOString();
const dateTime = moment.parseZone(ISO);
const datePart = dateTime.format(date_ISO_8601);
d = moment.parseZone(`${datePart}${UTCTimePart}`);
} else if (arg.isDateTime) {
const dateTime = moment.tz(arg.format(), UTC);
const datePart = dateTime.format(date_ISO_8601);
d = moment.parseZone(`${datePart}${UTCTimePart}`);
}
if (!d.isValid()) {
throw new Error('Invalid date. Parsing error while attempting to create date from date and time');
}
} else {
throw new Error('Invalid format encountered. Please specify date in one of these formats :\n- "date("2012-12-25")"\n- date_and_time object');
}
} else if (args.length === 3 && isNumber(args)) {
const [year, month, day] = args;
d = moment.tz({ year, month, day, hour: 0, minute: 0, second: 0 }, UTC);
const valueDT = (obj) => {
const e = moment.parseZone(epoch, date_ISO_8601);
const duration = moment.duration(obj.diff(e));
return duration.asSeconds();
};
const parseDate = (str) => {
try {
const d = moment.parseZone(`${str}${UTCTimePart}`);
if (d.isValid()) {
return d;
}
throw new Error('Invalid date. This is usually caused by an inappropriate format. Please check the input format.');
} catch (err) {
return err;
}
};
taxon={taxon}
url={noTaxonLink ? null : `/taxa/${taxon.id}`}
noParens
target={linkTarget}
user={config.currentUser}
showMemberGroup
/>
{ item.body && ( ) }
);
} else {
header = I18n.t( "user_commented", { user: ReactDOMServer.renderToString( userLink ) } );
contents = ( );
}
const relativeTime = moment.parseZone( item.created_at ).fromNow( );
let panelClass;
const headerItems = [];
const unresolvedFlags = _.filter( item.flags || [], f => !f.resolved );
if ( unresolvedFlags.length > 0 ) {
panelClass = "flagged";
headerItems.push(
<span>
<a rel="nofollow noopener noreferrer" href="{`/${isID">
<i>
{ " " }
{ I18n.t( "flagged_" ) }
</i></a></span>
const valueInverseDT = (value, offset = 'Z') => {
const e = moment.parseZone(epoch, date_ISO_8601);
return dateAndTime(e.add(value, 'seconds').utcOffset(offset).format());
};
onChangeDate = (value) => {
const yyyymmdd = moment.parseZone(value).format('YYYY-MM-DD');
const timezone = toTimezone(this.props.timezone || this.props.orgTimezone);
const z = moment(yyyymmdd).tz(timezone).format('Z');
this.onChangeCriterion(this.getOperator(), `${yyyymmdd}T00:00${z}`);
};
const date = (...args) => {
let d;
if (args.length === 1) {
const arg = args[0];
if (typeof arg === 'string') {
try {
d = arg === '' ? moment.parseZone(UTCTimePart, time_ISO_8601) : parseDate(arg);
} catch (err) {
throw err;
}
} else if (typeof arg === 'object') {
if (arg instanceof Date) {
const ISO = arg.toISOString();
const dateTime = moment.parseZone(ISO);
const datePart = dateTime.format(date_ISO_8601);
d = moment.parseZone(`${datePart}${UTCTimePart}`);
} else if (arg.isDateTime) {
const dateTime = moment.tz(arg.format(), UTC);
const datePart = dateTime.format(date_ISO_8601);
d = moment.parseZone(`${datePart}${UTCTimePart}`);
}
if (!d.isValid()) {
throw new Error('Invalid date. Parsing error while attempting to create date from date and time');
}
} else {
throw new Error('Invalid format encountered. Please specify date in one of these formats :\n- "date("2012-12-25")"\n- date_and_time object');
}
} else if (args.length === 3 && isNumber(args)) {
const [year, month, day] = args;
d = moment.tz({ year, month, day, hour: 0, minute: 0, second: 0 }, UTC);
if (!d.isValid()) {
throw new Error('Invalid date. Parsing error while attempting to create date from parts');