(units)
| 5281 | } |
| 5282 | |
| 5283 | function as(units) { |
| 5284 | if (!this.isValid()) { |
| 5285 | return NaN; |
| 5286 | } |
| 5287 | var days, |
| 5288 | months, |
| 5289 | milliseconds = this._milliseconds; |
| 5290 | |
| 5291 | units = normalizeUnits(units); |
| 5292 | |
| 5293 | if (units === 'month' || units === 'quarter' || units === 'year') { |
| 5294 | days = this._days + milliseconds / 864e5; |
| 5295 | months = this._months + daysToMonths(days); |
| 5296 | switch (units) { |
| 5297 | case 'month': |
| 5298 | return months; |
| 5299 | case 'quarter': |
| 5300 | return months / 3; |
| 5301 | case 'year': |
| 5302 | return months / 12; |
| 5303 | } |
| 5304 | } else { |
| 5305 | // handle milliseconds separately because of floating point math errors (issue #1867) |
| 5306 | days = this._days + Math.round(monthsToDays(this._months)); |
| 5307 | switch (units) { |
| 5308 | case 'week': |
| 5309 | return days / 7 + milliseconds / 6048e5; |
| 5310 | case 'day': |
| 5311 | return days + milliseconds / 864e5; |
| 5312 | case 'hour': |
| 5313 | return days * 24 + milliseconds / 36e5; |
| 5314 | case 'minute': |
| 5315 | return days * 1440 + milliseconds / 6e4; |
| 5316 | case 'second': |
| 5317 | return days * 86400 + milliseconds / 1000; |
| 5318 | // Math.floor prevents floating point math errors here |
| 5319 | case 'millisecond': |
| 5320 | return Math.floor(days * 864e5) + milliseconds; |
| 5321 | default: |
| 5322 | throw new Error('Unknown unit ' + units); |
| 5323 | } |
| 5324 | } |
| 5325 | } |
| 5326 | |
| 5327 | // TODO: Use this.as('ms')? |
| 5328 | function valueOf$1() { |
nothing calls this directly
no test coverage detected