Git Product home page Git Product logo

moment-random's Introduction

๐Ÿ‘‹ Howdy

Fullstack software engineer and indie hacker


moment-random's People

Contributors

dependabot[bot] avatar imrvelj avatar ucorpor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

izagz ucorpor

moment-random's Issues

dist/index.js does not exist after npm install

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:

  • OS: Ubuntu 14.04.4 LTS
  • Node: v6.11.3
  • NPM: 5.4.2

How to treat randomly generated Date as UTC time

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.