Code Monkey home page Code Monkey logo

datetime-round's Introduction

datetime-round

Build NPM Version NPM Downloads Github Repo Size LICENSE Contributors Commit

Rounds off datetime to nearest interval

Install

npm i datetime-round

Usage

const DatetimeRound = require('datetime-round');


DatetimeRound(moment('2019-08-30 10:11:25'), 30, 'minutes', 'ceil')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:30:00

DatetimeRound(moment('2019-08-30 10:11:25'), 30, 'minutes', 'floor')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:00:00

DatetimeRound(moment('2019-08-30 10:11:25'), 10, 'minutes', 'ceil')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:20:00

DatetimeRound(moment('2019-08-30 10:11:25'), 10, 'minutes', 'floor')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:10:00

DatetimeRound(moment('2019-08-30 10:11:25'), 5, 'minutes', 'ceil')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:15:00

DatetimeRound(moment('2019-08-30 10:11:25'), 5, 'minutes', 'floor')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:10:00

Params

DatetimeRound will accept following parameters as input

  • date: String datetime / moment object
  • interval: Time interval till which time needs to be rounded to (integer)
  • intervalType: Type of interval (minutes, hours, seconds)

    Refer to moment.duration docs for all available formats.

  • method: Rounding method, floor, ceil .... (It supports all the round methods available in NodeJS Math package)

Contributing

Interested in contributing to this project? You can log any issues or suggestion related to this library here

Read our contributing guide on getting started with contributing to the codebase

datetime-round's People

Contributors

arshadkazmi42 avatar dependabot[bot] avatar jjalbuenacabuyao avatar sinumohan avatar tarannum-2002 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

datetime-round's Issues

Add badges for readme using npm-badger

  1. Install npm badger npm install npm-badger -g
  2. Clone this repository git clone https://github.com/arshadkazmi42/datetime-round
  3. Go to root directory cd datetime-round
  4. Run npm badger npm-badger
  5. Commit README.md file
  6. Create Pull Request

fix vulnerability

  • Delete package-lock.json
  • Run npm install
  • Commit the updated package-lock.json
  • Create pull request

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.