Coder Social home page Coder Social logo

jmot-lib's Introduction

jmot-lib (JavaScript Manipulation of Time Library) 🌌

A JavaScript utility library that converts decimal to time, add decimal to time and get current time based on locale.

Give it a whirl on RunKit:

This link takes you to RunKit + npm in browser playground to test jmot-lib

ℹī¸ https://npm.runkit.com/jmot-lib

Sometimes we end up having to work with non-standard time values. For example 1.5 hrs means one and a half hours.

This library aims to make it easy to do manipulations on time. So that, 1.5 hrs becomes 1:30 and where 1.5 + 14:00 returns 15:30.

Hours Time Hours Time
0 0:00 12 12:00
0.083333 0:05 12.083333 12:05
0.166667 0:10 12.166667 12:10
0.25 0:15 12.25 12:15
0.333333 0:20 12.333333 12:20
0.416667 0:25 12.416667 12:25
0.5 0:30 12.5 12:30
0.583333 0:35 12.583333 12:35
0.666667 0:40 12.666667 12:40
0.75 0:45 12.75 12:45
0.833333 0:50 12.833333 12:50
0.916667 0:55 12.916667 12:55
1 1:00 13 13:00

ℹī¸ 1 hour is equal to 60 minutes.

Usage

Installation

using npm:

npm install jmot-lib

Code Example

ESM support:

import { dectotime, adddectotime } from 'jmot-lib';

var x = dectotime('4.5');
console.log('result: ', x);
// result: 4:30

var y = adddectotime('1.75','14:00');
console.log('result: ', y);
// result: 15:45

CJS(CommonJS) and UMD(Universal Module Definition) also supported.

String -> String

dectotime takes a string as input and outputs a string.

Gotchas 👊

  • 🕛 24 Hour Format

The api supports up to 24-hour decimal time. However, it will allow all values.

  • đŸ‘ģ Boo O'Clock

dectotime takes a string as input.

dectotime('boo');
// boo:00

Ensure you validate the value being passed in beforehand.

Functions

adddectotime takes two string inputs ('1.0','12:00') a decimal and a time. The two values are summed together and returned as a string.

currenttime returns current time based on your locale setting. The default currenttime() returns your local short(HH:MM)time in UTC format.

Optional parameters: currenttime(_locale_,_timeformat_). locale(specify a language format and or location) and timeformat Use 'HH:MM:SS' to return a long time. See examples below:

import { currenttime } from 'jmot-lib';

currenttime();
// "13:15"

currenttime('en');
// "1:15 PM"

currenttime('en-GB');
// "13:15"

currenttime('in-ID');
// "ā§§:ā§§ā§Ģ PM"

currenttime('en-US', 'HH:MM:SS');
// "1:15:03 PM"

List of supported locales and example outputs.

dectotime takes a decimal string as input and returns a string time HH:MM.

Contribute 💜

Become a contributor to jmot!

If you've found a bug, please create a new issue or a pull request.

All feedback welcome! 🙋

jmot-lib's People

Contributors

sasinclair avatar

Watchers

 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.