MCPcopy Create free account
hub / github.com/csev/py4e / as

Function as

code/gmane/Chart.bundle.js:4516–4541  ·  view source on GitHub ↗
(units)

Source from the content-addressed store, hash-verified

4514 }
4515
4516 function as (units) {
4517 var days;
4518 var months;
4519 var milliseconds = this._milliseconds;
4520
4521 units = normalizeUnits(units);
4522
4523 if (units === 'month' || units === 'year') {
4524 days = this._days + milliseconds / 864e5;
4525 months = this._months + daysToMonths(days);
4526 return units === 'month' ? months : months / 12;
4527 } else {
4528 // handle milliseconds separately because of floating point math errors (issue #1867)
4529 days = this._days + Math.round(monthsToDays(this._months));
4530 switch (units) {
4531 case 'week' : return days / 7 + milliseconds / 6048e5;
4532 case 'day' : return days + milliseconds / 864e5;
4533 case 'hour' : return days * 24 + milliseconds / 36e5;
4534 case 'minute' : return days * 1440 + milliseconds / 6e4;
4535 case 'second' : return days * 86400 + milliseconds / 1000;
4536 // Math.floor prevents floating point math errors here
4537 case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
4538 default: throw new Error('Unknown unit ' + units);
4539 }
4540 }
4541 }
4542
4543 // TODO: Use this.as('ms')?
4544 function duration_as__valueOf () {

Callers

nothing calls this directly

Calls 3

normalizeUnitsFunction · 0.85
daysToMonthsFunction · 0.85
monthsToDaysFunction · 0.85

Tested by

no test coverage detected