moment-random
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "moment-random", | ||
"version": "1.0.3", | ||
"author": "Ivan Mrvelj <sk8raid@gmail.com>", | ||
"version": "1.0.4", | ||
"author": "Ivan Mrvelj <ivan.mrvelj@protonmail.com>", | ||
"description": "Generates a random momentjs object", | ||
@@ -41,8 +41,8 @@ "license": "MIT", | ||
"babel-jest": "^19.0.0", | ||
"babel-preset-env": "^1.4.0", | ||
"babel-preset-env": "^1.7.0", | ||
"eslint": "^3.9.1", | ||
"eslint-plugin-jest": "^19.0.1", | ||
"husky": "^0.13.3", | ||
"jest": "^19.0.2", | ||
"moment": "^2.18.1", | ||
"jest": "^23.0.0", | ||
"moment": "^2.20.1", | ||
"rimraf": "^2.6.1" | ||
@@ -49,0 +49,0 @@ }, |
@@ -11,3 +11,3 @@ const moment = require('moment'); | ||
function momentRandom(end = moment(), start) { | ||
const endMoment = moment(end); | ||
const endTime = +moment(end); | ||
const randomNumber = (to, from = 0) => | ||
@@ -17,12 +17,11 @@ Math.floor(Math.random() * (to - from) + from); | ||
if (start) { | ||
const startMoment = moment(start); | ||
if (startMoment.unix() > endMoment.unix()) { | ||
const startTime = +moment(start); | ||
if (startTime > endTime) { | ||
throw new Error('End date is before start date!'); | ||
} | ||
return moment.unix(randomNumber(endMoment.unix(), startMoment.unix())); | ||
} else { | ||
return moment.unix(randomNumber(endMoment.unix())); | ||
return moment(randomNumber(endTime, startTime)); | ||
} | ||
return moment(randomNumber(endTime)); | ||
} | ||
module.exports = momentRandom; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3700
21