summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/moment/src/lib/duration/as.js
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/moment/src/lib/duration/as.js')
-rw-r--r--bin/wiki/ImportarDesdeURL/node_modules/moment/src/lib/duration/as.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/moment/src/lib/duration/as.js b/bin/wiki/ImportarDesdeURL/node_modules/moment/src/lib/duration/as.js
new file mode 100644
index 00000000..122204a1
--- /dev/null
+++ b/bin/wiki/ImportarDesdeURL/node_modules/moment/src/lib/duration/as.js
@@ -0,0 +1,61 @@
+import { daysToMonths, monthsToDays } from './bubble';
+import { normalizeUnits } from '../units/aliases';
+import toInt from '../utils/to-int';
+
+export function as (units) {
+ if (!this.isValid()) {
+ return NaN;
+ }
+ var days;
+ var months;
+ var milliseconds = this._milliseconds;
+
+ units = normalizeUnits(units);
+
+ if (units === 'month' || units === 'year') {
+ days = this._days + milliseconds / 864e5;
+ months = this._months + daysToMonths(days);
+ return units === 'month' ? months : months / 12;
+ } else {
+ // handle milliseconds separately because of floating point math errors (issue #1867)
+ days = this._days + Math.round(monthsToDays(this._months));
+ switch (units) {
+ case 'week' : return days / 7 + milliseconds / 6048e5;
+ case 'day' : return days + milliseconds / 864e5;
+ case 'hour' : return days * 24 + milliseconds / 36e5;
+ case 'minute' : return days * 1440 + milliseconds / 6e4;
+ case 'second' : return days * 86400 + milliseconds / 1000;
+ // Math.floor prevents floating point math errors here
+ case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
+ default: throw new Error('Unknown unit ' + units);
+ }
+ }
+}
+
+// TODO: Use this.as('ms')?
+export function valueOf () {
+ if (!this.isValid()) {
+ return NaN;
+ }
+ return (
+ this._milliseconds +
+ this._days * 864e5 +
+ (this._months % 12) * 2592e6 +
+ toInt(this._months / 12) * 31536e6
+ );
+}
+
+function makeAs (alias) {
+ return function () {
+ return this.as(alias);
+ };
+}
+
+export var asMilliseconds = makeAs('ms');
+export var asSeconds = makeAs('s');
+export var asMinutes = makeAs('m');
+export var asHours = makeAs('h');
+export var asDays = makeAs('d');
+export var asWeeks = makeAs('w');
+export var asMonths = makeAs('M');
+export var asYears = makeAs('y');