Fullstack software engineer and indie hacker
imrvelj / moment-random Goto Github PK
View Code? Open in Web Editor NEWGenerates a random momentjs object
License: MIT License
Generates a random momentjs object
License: MIT License
How to reproduce:
$ npm install moment-random
+ [email protected]
added 1 package in 2.56s
$ node -e "require ('moment-random')"
module.js:471
throw err;
^
Error: Cannot find module 'moment-random'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at [eval]:1:1
at ContextifyScript.Script.runInThisContext (vm.js:25:33)
at Object.runInThisContext (vm.js:97:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:570:32)
at evalScript (bootstrap_node.js:353:27)
This appears to be due to a missing dist/index.js
in ./node_modules/moment-random/
after the npm install. It also appears that the contents of src/
are also missing after the npm install.
System configuration:
There is no change log associated with this project.
I am trying to generate a Date between 2021-02-10 23:59:59
and 2021-02-10 00:00:00
and then create a Date
object. Although I am still trying to understand how this works internally, I think it is using my local timezone prior to creating the Date obj, which leads to Date objects outside of the range I specified.
Example:
let ramdon = momentRandom(
moment().tz("UTC").format("2021-02-10 23:59:59"),
moment().tz("UTC").format("2021-02-10 00:00:00")
).format("YYYY-MM-DD HH:mm:ss");
console.log(ramdon);
console.log(new Date(ramdon))
From the code above, I can get the following outputs
2021-02-10 16:30:38
2021-02-10T21:30:38.000Z
2021-02-10 05:08:59
2021-02-10T10:08:59.000Z
But eventually, if I keep generating Dates, the Date obj may go out of the range based on the value generated randomly
2021-02-10 21:54:58
2021-02-11T02:54:58.000Z <-- outside the range [2021-02-10 00:00:00, 2021-02-10 23:59:59]
Any way to solve this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.