npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jmot-lib

v2.0.0

Published

JavaScript time manipulation utility library

Downloads

10

Readme

jmot-lib (JavaScript Manipulation of Time Library) :milky_way:

A JavaScript utility library that converts decimal to time.

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 |

:information_source: 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 :facepunch:

  • :clock12: 24 Hour Format

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

  • :ghost: 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 :purple_heart:

Become a contributor to jmot!

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

All feedback welcome! :raising_hand: