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

day-time-seconds

v0.0.3

Published

Used to facilitate the manipulation of days measured in seconds

Downloads

2

Readme


:horse_racing: How to use

The DayTime class is used to manipulate a single day, storing a value in seconds ranging from 0 (00:00:00) to 86399 (23:59:59).

The library is available as an npm package. To install the package run:

npm install day-time-seconds --save
# or with yarn
yarn add day-time-seconds

Example usage:

const DayTime = require('day-time-seconds');
const time = DayTime.now();

console.log(time.toString());
// 23:49:59 (current time example)

:memo: Documentation

Methods

now(): The static DayTime.now() method returns the number of seconds elapsed since 00:00:00.

const time = new DayTime().now();

console.log(time.toString());
// 23:49:59 (current time example)

getTotalSeconds(): Get the total seconds elapsed since 00:00:00.

const time = new DayTime(3600);
// 01:00:00

const seconds = time.getTotalSeconds();
// seconds -> 3600

setTotalSeconds(seconds): Set the total seconds elapsed since 00:00:00.

const time = new DayTime(3600);
// 01:00:00

time.setTotalSeconds(7200);
// 02:00:00

getTotalMilliseconds(): Get the total seconds elapsed since 00:00:00, converted into milliseconds.

const time = new DayTime(3600);
// 01:00:00

const ms = time.getTotalMilliseconds();
// ms -> 3600000

setTotalMilliseconds(milliseconds): Set the total seconds elapsed since 00:00:00, converted into milliseconds.

const time = new DayTime(3600);
// 01:00:00

time.setTotalMilliseconds(7200000);
// 02:00:00

getDaySeconds(): Get only the full seconds relative to the time.

const time = new DayTime(7269);
// 02:01:09

const seconds = time.getDaySeconds();
// seconds -> 9

getDayMinutes(): Get only the full minutes relative to the time.

const time = new DayTime(7269);
// 02:01:09

const minutes = time.getDayMinutes();
// minutes -> 1

getDayHours(): Get only the full hours relative to the time.

const time = new DayTime(7269);
// 02:01:09

const hours = time.getDayHours();
// hours -> 2

addHours(hours): Add the specified number of hours to the current time.

const time = new DayTime(3605);
// 01:00:05

time.addHours(2);
// 03:00:05

addMinutes(minutes): Add the specified number of minutes to the current time.

const time = new DayTime(3605);
// 01:00:05

time.addMinutes(40);
// 01:40:05

addSeconds(seconds): Add the specified number of seconds to the current time.

const time = new DayTime(3605);
// 01:00:05

time.addSeconds(50);
// 01:00:55

subHours(hours): Subtract the specified number of hours from the current time.

const time = new DayTime(7261);
// 02:01:01

time.subHours(1);
// 01:01:01

subMinutes(minutes): Subtract the specified number of minutes from the current time.

const time = new DayTime(7261);
// 02:01:01

time.subMinutes(1);
// 02:00:01

subSeconds(seconds): Subtract the specified number of seconds from the current time.

const time = new DayTime(7261);
// 02:01:01

time.subSeconds(1);
// 02:01:00

getTimeFormatted(separator = ':'): Return the formatted time string. Options may be passed to control the string separator.

const time = new DayTime(3600);

console.log(time.getTimeFormatted());
// 01:00:00 (default separator is ':')

or with another separator params

const time = new DayTime(3602);

console.log(time.getTimeFormatted('|'));
// 01|00|02

Exceptions

The seconds values must range from 0 to 86399, otherwise, an exception will be thrown.

const time = new DayTime(86500);

// Error: The value (seconds: 86500) is out of range