MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / bubble

Function bubble

tests/test_code/js/moment/moment.js:5217–5270  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5215 }
5216
5217 function bubble() {
5218 var milliseconds = this._milliseconds,
5219 days = this._days,
5220 months = this._months,
5221 data = this._data,
5222 seconds,
5223 minutes,
5224 hours,
5225 years,
5226 monthsFromDays;
5227
5228 // if we have a mix of positive and negative values, bubble down first
5229 // check: https://github.com/moment/moment/issues/2166
5230 if (
5231 !(
5232 (milliseconds >= 0 && days >= 0 && months >= 0) ||
5233 (milliseconds <= 0 && days <= 0 && months <= 0)
5234 )
5235 ) {
5236 milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
5237 days = 0;
5238 months = 0;
5239 }
5240
5241 // The following code bubbles up values, see the tests for
5242 // examples of what that means.
5243 data.milliseconds = milliseconds % 1000;
5244
5245 seconds = absFloor(milliseconds / 1000);
5246 data.seconds = seconds % 60;
5247
5248 minutes = absFloor(seconds / 60);
5249 data.minutes = minutes % 60;
5250
5251 hours = absFloor(minutes / 60);
5252 data.hours = hours % 24;
5253
5254 days += absFloor(hours / 24);
5255
5256 // convert days to months
5257 monthsFromDays = absFloor(daysToMonths(days));
5258 months += monthsFromDays;
5259 days -= absCeil(monthsToDays(monthsFromDays));
5260
5261 // 12 months -> 1 year
5262 years = absFloor(months / 12);
5263 months %= 12;
5264
5265 data.days = days;
5266 data.months = months;
5267 data.years = years;
5268
5269 return this;
5270 }
5271
5272 function daysToMonths(days) {
5273 // 400 years have 146097 days (taking into account leap year rules)

Callers

nothing calls this directly

Calls 4

absCeilFunction · 0.85
monthsToDaysFunction · 0.85
absFloorFunction · 0.85
daysToMonthsFunction · 0.85

Tested by

no test coverage detected