GithubHelp home page GithubHelp logo

lynzz / time-number Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yury-dymov/time-number

0.0 2.0 0.0 16 KB

Converts time representation from string to number or from number to string

License: MIT License

JavaScript 100.00%

time-number's Introduction

time-number

npm version Build Status Coverage Status

Converts time representation from string to number or from number to string.

Note: It was extracted from react-bootstrap-time-picker and has very limited functionality.

Installation

npm install time-number

Functions

timeFromInt(timeNumber: number, validate: boolean)

validate is true by default. Fill free to disable validations for performance gains if you are that sure in your data.

Note: Number should be provided in seconds

Note: function returns time in either "HH:mm" or "HH:mm:ss" format. No localization is supported yet.

Usage example

import { timeFromInt } from 'time-number';

console.log(timeFromInt(64800));     // -> '18:00'
console.log(timeFromInt(64805));     // -> '18:00:05'

timeToInt(timeString: string, validate: boolean)

validate is true by default

Note: function expects to receive 24-hour format. "18", "18:00" and "18:00:05" are acceptable but "6:00 PM" is not.

Usage example

import { timeToInt } from 'time-number';

console.log(timeToInt('18'));        // -> 64800
console.log(timeToInt('18:00'));     // -> 64800
console.log(timeToInt('18:00:05'));  // -> 64805

License

MIT (c) Yury Dymov

time-number's People

Watchers

 avatar  avatar

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.