How to use the date-and-time.addMilliseconds function in date-and-time

To help you get started, we’ve selected a few date-and-time examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kpi-wdc / dj / dj-libs / bayes-simulator / index.js View on Github external
var varIndicators = indicators[varName];
		for(var valueName in varIndicators) {
			var indicator = varIndicators[valueName];
			var sDate = date.parse(indicator.start.stamp,
					indicator.start.format);
			var eDate = date.parse(indicator.end.stamp,
					indicator.end.format)
			var fromDate = date.parse(fromT.stamp, fromT.format);
			var toDate = date.parse(toT.stamp, toT.format);
			var pDuration = indicator.period ? new Duration(indicator.period) : undefined;
			if (pDuration) {
				interval = findPeriodicalIntervalFor(fromDate, sDate, eDate, pDuration);
				var period = pDuration.milliseconds();
				if (!isInInterval(interval.sDate, fromDate, toDate) &&
					!isInInterval(interval.eDate, fromDate, toDate) ) {
					sDate = date.addMilliseconds(interval.sDate, period);
					eDate = date.addMilliseconds(interval.eDate, period);
				} else if (isInInterval(date.addMilliseconds(interval.eDate, -period), fromDate, toDate)) {
					sDate = date.addMilliseconds(interval.sDate, -period);
					eDate = date.addMilliseconds(interval.eDate, -period);
				} else {
					sDate = interval.sDate;
					eDate = interval.eDate;
				}
			}

			do {
				var lDatePoint = sDate;
				var rDatePoint = eDate;

				if (!isInInterval(lDatePoint, fromDate, toDate) &&
					!isInInterval(rDatePoint, fromDate, toDate) &&
github kpi-wdc / dj / dj-libs / bayes-simulator / index.js View on Github external
i--;
					for(; i < distr.length; i++) {
						var fromStart = new Duration(distr[i].fromStart).milliseconds();
						iDate = date.addMilliseconds(sDate, fromStart);
						if (isInInterval(iDate, lDatePoint, rDatePoint)) {
							timePointsSet.add(iDate.getTime());
						} else {
							break;
						}
    				}
				}
				if (pDuration) {
					var period = pDuration.milliseconds();
					sDate = date.addMilliseconds(sDate, period);
					eDate = date.addMilliseconds(eDate, period);
				}
			} while(pDuration && isInInterval(sDate, fromDate, toDate));
		}
	}
	var timePointsArray = [];
	timePointsSet.forEach(v => timePointsArray.push(v));
	return timePointsArray;
}
github kpi-wdc / dj / dj-libs / bayes-simulator / index.js View on Github external
timePointsSet.add(lDatePoint.getTime());
				timePointsSet.add(rDatePoint.getTime());

				if (indicator.distribution) {
					var distr = indicator.distribution;
					var i = 0;
					var iDate;
					do {
						var fromStart = new Duration(distr[i].fromStart).milliseconds();
						iDate = date.addMilliseconds(sDate, fromStart);
					} while(++i < distr.length && date.subtract(iDate, lDatePoint).toMilliseconds() <= 0);

					i--;
					for(; i < distr.length; i++) {
						var fromStart = new Duration(distr[i].fromStart).milliseconds();
						iDate = date.addMilliseconds(sDate, fromStart);
						if (isInInterval(iDate, lDatePoint, rDatePoint)) {
							timePointsSet.add(iDate.getTime());
						} else {
							break;
						}
    				}
				}
				if (pDuration) {
					var period = pDuration.milliseconds();
					sDate = date.addMilliseconds(sDate, period);
					eDate = date.addMilliseconds(eDate, period);
				}
			} while(pDuration && isInInterval(sDate, fromDate, toDate));
		}
	}
	var timePointsArray = [];
github kpi-wdc / dj / dj-libs / bayes-simulator / index.js View on Github external
var findPeriodicalIntervalFor = function(tDate, sDate, eDate, pDuration) {
	var period = pDuration.milliseconds();
	var difference = date.subtract(tDate, sDate).toMilliseconds();
	var remainder = difference % period;
	var offset = difference - remainder;
	offset += remainder >= 0 ? 0 : - period;
	var result = {};
	result.sDate = date.addMilliseconds(sDate, offset);
	result.eDate = date.addMilliseconds(eDate, offset);
	return result;
}
github kpi-wdc / dj / dj-libs / bayes-simulator / index.js View on Github external
var findPeriodicalIntervalFor = function(tDate, sDate, eDate, pDuration) {
	var period = pDuration.milliseconds();
	var difference = date.subtract(tDate, sDate).toMilliseconds();
	var remainder = difference % period;
	var offset = difference - remainder;
	offset += remainder >= 0 ? 0 : - period;
	var result = {};
	result.sDate = date.addMilliseconds(sDate, offset);
	result.eDate = date.addMilliseconds(eDate, offset);
	return result;
}
github kpi-wdc / dj / dj-libs / bayes-simulator / index.js View on Github external
var sDate = date.parse(indicator.start.stamp,
					indicator.start.format);
			var eDate = date.parse(indicator.end.stamp,
					indicator.end.format)
			var fromDate = date.parse(fromT.stamp, fromT.format);
			var toDate = date.parse(toT.stamp, toT.format);
			var pDuration = indicator.period ? new Duration(indicator.period) : undefined;
			if (pDuration) {
				interval = findPeriodicalIntervalFor(fromDate, sDate, eDate, pDuration);
				var period = pDuration.milliseconds();
				if (!isInInterval(interval.sDate, fromDate, toDate) &&
					!isInInterval(interval.eDate, fromDate, toDate) ) {
					sDate = date.addMilliseconds(interval.sDate, period);
					eDate = date.addMilliseconds(interval.eDate, period);
				} else if (isInInterval(date.addMilliseconds(interval.eDate, -period), fromDate, toDate)) {
					sDate = date.addMilliseconds(interval.sDate, -period);
					eDate = date.addMilliseconds(interval.eDate, -period);
				} else {
					sDate = interval.sDate;
					eDate = interval.eDate;
				}
			}

			do {
				var lDatePoint = sDate;
				var rDatePoint = eDate;

				if (!isInInterval(lDatePoint, fromDate, toDate) &&
					!isInInterval(rDatePoint, fromDate, toDate) &&
					!isInInterval(fromDate, lDatePoint, rDatePoint)) {
					break;
				}
github kpi-wdc / dj / dj-libs / bayes-simulator / index.js View on Github external
lDatePoint = fromDate;
				}

				if (!isInInterval(rDatePoint, fromDate, toDate)) {
					rDatePoint = toDate;
				}
				timePointsSet.add(lDatePoint.getTime());
				timePointsSet.add(rDatePoint.getTime());

				if (indicator.distribution) {
					var distr = indicator.distribution;
					var i = 0;
					var iDate;
					do {
						var fromStart = new Duration(distr[i].fromStart).milliseconds();
						iDate = date.addMilliseconds(sDate, fromStart);
					} while(++i < distr.length && date.subtract(iDate, lDatePoint).toMilliseconds() <= 0);

					i--;
					for(; i < distr.length; i++) {
						var fromStart = new Duration(distr[i].fromStart).milliseconds();
						iDate = date.addMilliseconds(sDate, fromStart);
						if (isInInterval(iDate, lDatePoint, rDatePoint)) {
							timePointsSet.add(iDate.getTime());
						} else {
							break;
						}
    				}
				}
				if (pDuration) {
					var period = pDuration.milliseconds();
					sDate = date.addMilliseconds(sDate, period);
github kpi-wdc / dj / dj-libs / bayes-simulator / index.js View on Github external
indicator.start.format);
			var eDate = date.parse(indicator.end.stamp,
					indicator.end.format)
			var fromDate = date.parse(fromT.stamp, fromT.format);
			var toDate = date.parse(toT.stamp, toT.format);
			var pDuration = indicator.period ? new Duration(indicator.period) : undefined;
			if (pDuration) {
				interval = findPeriodicalIntervalFor(fromDate, sDate, eDate, pDuration);
				var period = pDuration.milliseconds();
				if (!isInInterval(interval.sDate, fromDate, toDate) &&
					!isInInterval(interval.eDate, fromDate, toDate) ) {
					sDate = date.addMilliseconds(interval.sDate, period);
					eDate = date.addMilliseconds(interval.eDate, period);
				} else if (isInInterval(date.addMilliseconds(interval.eDate, -period), fromDate, toDate)) {
					sDate = date.addMilliseconds(interval.sDate, -period);
					eDate = date.addMilliseconds(interval.eDate, -period);
				} else {
					sDate = interval.sDate;
					eDate = interval.eDate;
				}
			}

			do {
				var lDatePoint = sDate;
				var rDatePoint = eDate;

				if (!isInInterval(lDatePoint, fromDate, toDate) &&
					!isInInterval(rDatePoint, fromDate, toDate) &&
					!isInInterval(fromDate, lDatePoint, rDatePoint)) {
					break;
				}