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

@typinghare/hour-minute-second

v2.0.3

Published

A simple hour-minute-second library.

Downloads

67

Readme

Hour Minute Second

This library provides a flexible and efficient solution for handling time durations based on hours, minutes, and seconds. It offers two implementations, SlowHourMinuteSecond and QuickHourMinuteSecond, catering to different use cases. Whether you need real-time updates or fast calculations, this library empowers you with essential features and a clean API.

There are two implementations of the HourMinuteSecond abstract class: SlowHourMinuteSecond and QuickHourMinuteSecond. These implementations represent time in hours, minutes, and seconds. The main difference between them lies in how they handle time calculations and updates.

The SlowHourMinuteSecond class computes the hours, minutes, and seconds dynamically when they are accessed. This means that whenever you retrieve the hour, minute, or second value, it performs the calculation based on the total time stored in milliseconds. This approach is suitable when you have a fixed time value and need to access the components multiple times without frequent updates.

The QuickHourMinuteSecond class takes a different approach by computing the hour, minute, and second values only when the time is updated. It stores the time in milliseconds and updates the components accordingly. This implementation is suitable when you frequently update the time value and need fast access to the individual components.

Despite their different implementations, both the SlowHourMinuteSecond and QuickHourMinuteSecond classes are created, updated, and accessed using the same approach. Therefore, this documentation only takesSlowHourMinuteSecond as an example.

Create Time

import {SlowHourMinuteSecond} from '@typinghare/hour-minute-second'

// Create a SlowHourMinuteSecond instance with 4532500 milliseconds
new SlowHourMinuteSecond(4532500)

// By default, the time is set to 0 milliseconds
new SlowHourMinuteSecond()

// Create a SlowHourMinuteSecond instance with 100 seconds
SlowHourMinuteSecond.ofSeconds(100)

// Create a SlowHourMinuteSecond instance with 50 minutes
SlowHourMinuteSecond.ofMinutes(50)

// Create a SlowHourMinuteSecond instance with 10 hours
SlowHourMinuteSecond.ofHours(10)

Since v1.1.0

import {HourMinuteSecond, QuickHourMinuteSecond} from '@typinghare/hour-minute-second'

// Create a SlowHourMinuteSecond (default) by using `HourMinuteSecond.create` method
const slowTime = HourMinuteSecond.create(1000)

// Custom the static initiatiate class
HourMinuteSecond.setStaticInitiateClass(QuickHourMinuteSecond)

// Then the instance created is an instance of QuickHourMinuteSecond
const quickTime = HourMinuteSecond.create(1000)

// ofSeconds, ofMinutes, and ofHours
HourMinuteSecond.ofSeconds(32)
HourMinuteSecond.ofMinutes(15)
HourMinuteSecond.ofHours(1)

Since v1.2.0

import {HourMinuteSecond} from "@typinghare/hour-minute-second";

// Create an hour-minute-second instance by a specified milliseconds
HourMinuteSecond.of(114514)

Access Time

import {SlowHourMinuteSecond} from '@typinghare/hour-minute-second'

// This time represents 1:15:32
const time = new SlowHourMinuteSecond(4532500)

console.log(time.ms)        // >> 4532500
console.log(time.hour)      // >> 1
console.log(time.minute)    // >> 15
console.log(time.second)    // >> 32

Extend Time

import {SlowHourMinuteSecond} from '@typinghare/hour-minute-second'

const time = new SlowHourMinuteSecond()

// Extend 500 milliseconds
time.extend(500)

// Extend 1 hour
time.extendHour(1)

// Extend 5 minutes
time.extendMinute(5)

// Extend 20 seconds
time.extendSecond(20)

// Chain programming is supported
time.extendHour(1)
    .extendMinute(5)
    .extendSecond(20)

Consume Time

import {SlowHourMinuteSecond} from '@typinghare/hour-minute-second'

const time = new SlowHourMinuteSecond(10000000)

// Consume 500 milliseconds
time.consume(500)

// Consume 1 hour
time.consumeHour(1)

// Consume 5 minutes
time.consumeMinute(5)

// Consume 20 seconds
time.consumeSecond(20)

// Chain programming is supported
time.consumeHour(1)
    .consumeMinute(5)
    .consumeSecond(20)

Clone Time

const time = new SlowHourMinuteSecond(500)
const cloneTime = time.clone(500)

time.extend(500)

console.log(cloneTime.ms === 500)  // >> true

toString

import {SlowHourMinuteSecond} from '@typinghare/hour-minute-second'

// This time represents 1:15:32
const time = new SlowHourMinuteSecond(4532500)

// The toString() method is overried
console.log(time)    // >> 1:15:32

// You can specify the format of the string
console.log(time.toString('hh-mm-ss'))  // >> 1-15-32

To Seconds, Minutes, and Hours

const time = HourMinuteSecond.of(75048245);
console.log(time.toSeconds())   // >> 75048.245
console.log(time.toMinutes())   // >> 1250.8040833333334
console.log(time.toHours())     // >> 20.846734722222223
const time = HourMinuteSecond.of(75048245);
console.log(time.toSecondsInt())    // >> 75048
console.log(time.toMinutesInt())    // >> 1250
console.log(time.toHoursInt())      // >> 20