Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return __awaiter(this, void 0, void 0, function* () {
let client = this.client;
let field = (options && options.field !== undefined) ? options.field : undefined;
// Validate
try {
if (field && !moment.isDuration(field)) {
throw new Error('field must be of type moment.duration.');
}
}
catch (error) {
return Promise.reject(error);
}
let complexBody;
if (field !== null && field !== undefined) {
complexBody = {};
complexBody.field = field;
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'complex/primitive/duration';
// Create HTTP transport objects
let httpRequest = new WebResource();
timePeriod = undefined;
if (firstLineMatch && lastLineMatch) {
const firstMoment = moment(firstLineMatch);
const lastMoment = moment(lastLineMatch);
if (firstMoment.isValid() && lastMoment.isValid()) {
// used for ISO Dates like '2018-09-29' and '2018-09-29 13:12:11.001'
timePeriod = moment.duration(lastMoment.diff(firstMoment));
} else {
const firstDuration = moment.duration(firstLineMatch);
const lastDuration = moment.duration(lastLineMatch);
if (moment.isDuration(firstDuration) && moment.isDuration(lastDuration)) {
// Used for non ISO dates like '13:12:11.001'
timePeriod = moment.duration(lastDuration.asMilliseconds() - firstDuration.asMilliseconds());
}
}
}
return timePeriod;
}
.map(part => Number.parseInt(part))
.find(number => number !== 0) !== undefined;
if (anyDuration) {
duration = moment.duration(valueToParse);
if (duration.isValid() && duration.asMilliseconds() === 0) {
// set to invalid duration
duration = moment.duration.invalid();
}
} else {
duration = moment.duration(0);
}
}
if (moment.isDuration(duration) && duration.isValid() && duration.asMinutes() < maxDuration) {
possibleTimes.push(now.clone().add(duration));
}
}
if (timeMode !== TimeMode.RELATIVE) {
const enteredDate = moment(valueToParse, ['hmm a', 'Hmm', 'h:m a', 'H:m', 'M-D hmm a', 'M-D Hmm', 'M-D h:m a', 'M-D H:m', 'M-D h a', 'M-D H']);
if (enteredDate.isValid()) {
possibleTimes.push(...TimeType.generateTimes(enteredDate, arg.key, raidHatchTime));
}
}
if (possibleTimes.length === 0) {
return `"${value}" is not a valid duration or time!\n\n${arg.prompt}`;
}
minutes: this.minutes(),
seconds: this.seconds(),
milliseconds: this.milliseconds()
})
} else { // setter
this._ambigTime = false // mark that the moment now has a time
if (!moment.isDuration(time) && !moment.isMoment(time)) {
time = moment.duration(time)
}
// The day value should cause overflow (so 24 hours becomes 00:00:00 of next day).
// Only for Duration times, not Moment times.
let dayHours = 0
if (moment.isDuration(time)) {
dayHours = Math.floor(time.asDays()) * 24
}
// We need to set the individual fields.
// Can't use startOf('day') then add duration. In case of DST at start of day.
return this.hours(dayHours + time.hours())
.minutes(time.minutes())
.seconds(time.seconds())
.milliseconds(time.milliseconds())
}
}
if (!interval || interval === 'auto') {
this._i = 'auto';
return;
}
if (_.isString(interval)) {
input = interval;
interval = parseInterval(interval);
if (+interval === 0) {
interval = null;
}
}
// If the value wasn't converted to a duration, and isn't already a duration, we have a problem
if (!moment.isDuration(interval)) {
throw new TypeError('"' + input + '" is not a valid interval.');
}
this._i = interval;
};
Header.prototype.paramDuration = function (scenario, value, options, callback) {
var client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
// Validate
try {
if (scenario === null || scenario === undefined || typeof scenario.valueOf() !== 'string') {
throw new Error('scenario cannot be null or undefined and it must be of type string.');
}
if(!value || !moment.isDuration(value)) {
throw new Error('value cannot be null or undefined and it must be of type moment.duration.');
}
} catch (error) {
return callback(error);
}
// Construct URL
var baseUrl = this.client.baseUri;
var requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'header/param/prim/duration';
// Create HTTP transport objects
var httpRequest = new WebResource();
httpRequest.method = 'POST';
httpRequest.headers = {};
httpRequest.url = requestUrl;
// Set Headers
function isValid(value) {
return moment.isDuration(value);
},
'Duration'
parse: function(eventInput, source) {
if (
isTimeString(eventInput.start) || moment.isDuration(eventInput.start) ||
isTimeString(eventInput.end) || moment.isDuration(eventInput.end)
) {
return RecurringEventDef.parse(eventInput, source)
} else {
return SingleEventDef.parse(eventInput, source)
}
}
export function orderXValues(obj, orderBucketsBySum = false) {
if (!_.isObject(obj)) {
throw new Error('orderXValues expects an object');
}
const uniqKeys = getUniqKeys(obj);
const uniqKeysPairs = [...uniqKeys.entries()];
const interval = _.get(obj, 'ordered.interval');
const dateInterval = moment.isDuration(interval) ? interval : false;
return _(uniqKeysPairs)
.sortBy(function (d) {
if (d[1].isDate || d[1].isOrdered) {
return +d[0];
}
return orderBucketsBySum ? -d[1].sum : d[1].index;
})
.map(function (d, i, list) {
if (!d[1].isNumber) return d[0];
const val = +d[0];
if (interval == null) return val;
const gapEdge = parseFloat(_.get(list, [i + 1, 0]));
if (isNaN(gapEdge)) return val;
if (!(value instanceof Date ||
(typeof value.valueOf() === "string" && !isNaN(Date.parse(value))))) {
throw new Error(objectName + " must be an instanceof Date or a string in RFC-1123 format.");
}
value = (value instanceof Date) ? value.toUTCString() : new Date(value).toUTCString();
}
else if (typeName.match(/^UnixTime$/ig) !== null) {
if (!(value instanceof Date ||
(typeof value.valueOf() === "string" && !isNaN(Date.parse(value))))) {
throw new Error(objectName + " must be an instanceof Date or a string in RFC-1123/ISO8601 format " +
"for it to be serialized in UnixTime/Epoch format.");
}
value = this.dateToUnixTime(value);
}
else if (typeName.match(/^TimeSpan$/ig) !== null) {
if (!(moment_1.isDuration(value) || (value.constructor && value.constructor.name === "Duration" && typeof value.isValid === "function" && value.isValid()))) {
throw new Error(objectName + " must be a TimeSpan/Duration.");
}
value = value.toISOString();
}
}
return value;
};
Serializer.prototype.serializeSequenceType = function (mapper, object, objectName) {