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

@toreda/time

v0.1.7

Published

Simple, small footprint library for common time operations and converting between units of time.

Downloads

101

Readme

Toreda

CI Coverage Sonar Quality Gate

GitHub package.json version (branch) GitHub Release Date GitHub issues

license

 

@toreda/time

Fast & easy time math and time unit conversions.

 

Use Cases

  • Time since date
    • Get seconds or any other time unit since date, datetime, timestamp, or unix timestamp.
  • Time until date
    • Get seconds or other time unit until date, datetime, timestamp, or unix timestamp.
  • Now
    • Get current timestamp (now) in seconds or other time unit.
  • Now (with offset)`
    • Get current timestamp (now) with an offset in the past or future.
  • DateTime Parsing
    • Parse strings as DateTime strings.
    • Convert to any other time unit.
  • Unix Timestamps
    • Parse Unix Timstamps (seconds) & convert to other time units.
    • Convert DateTime strings to Unix Timestamp.

 

Highlights

  • TypeScript Native
    • All types included with package.
    • No separate @types package eliminates sync issues between types and the library.
  • Minimalist
    • Small set of library functions for time calculations.
    • Get what you need without extra bloat.
  • Lightweight
    • 253 kB unpacked.
  • Modern Alternative
    • Modern replacement for the excellent moment.js (no longer maintained).
  • Tree-Shaking
    • Package optimizations helps modern bundlers drop unused code.

 

Install

npmjs.org

NPM Package

@toreda/time is available as an NPM package.

Yarn Install (preferred)

yarn add @toreda/time

NPM Install

npm install @toreda/time

 

Source Code

@toreda/time source files can be downloaded directly from the public Github repo.

Branches

  • master branch
    • Latest release & stable code.
    • Use for production builds.
  • develop branch
    • All completed but unreleased features pending release.
    • Generally stable, but not guaranteed.
    • Not suitable for production builds.

Git Clone (ssh)

[email protected]:toreda/time.git

Git Clone (https)

https://github.com/toreda/time.git

Download Zip (https)

Download the current master branch as a zip file https://github.com/toreda/time/archive/refs/heads/master.zip

 

Usage

Time Objects

Create Time object

import type {Time} from '@toreda/time';
import {timeMake} from '@toreda/time';

// Create time object in unit 'seconds' with value 0.
const time = timeMake('s', ,0);

Set Time

// Set time using a Unix Timestamp (in seconds)
time.set(1635577204);

// Set using ISO-8601 string
time.set('2021-10-30T06:13:33+00:00');

Set current time (now)

// Set Time to current time.
time.setNow();

Timestamps

Unix Timestamp

Create unix timestamp

import {unixTimestampNow} from '@toreda/time';

// Returns current unix timestamp in seconds at time of call.
const now = unixTimestampNow();

Set current time using Unix Timestamp

import type {Time} from '@toreda/time';
import {timeMake, unixTimestampNow} from '@toreda/time';
const now = unixTimestampNow();

const time = timeMake('s');
time.set(now);

Validation

Check if string is a valid & supported time unit

import {timeUnitSupported} from '@toreda/time';

// Outputs: 'supported: true'
console.info('supported: ' + timeUnitSupported('s'));

// Outputs: 'supported: true'
console.info('supported: ' + timeUnitSupported('w'));

// Outputs: 'supported: false'
console.info('supported: ' + timeUnitSupported());

// Outputs: 'supported: false'
console.info('supported: ' + timeUnitSupported({}));

// Outputs: 'supported: false'
console.info('supported: ' + timeUnitSupported('???'));

Check if object is a Time object

import {timeValid, timeNow} from '@toreda/time';
const now = timeNow();

// Outputs `is valid: true`
console.log('is valid: ' + timeValid(time));

// Outputs `is valid: false`
console.log('is valid: ' + timeValid({}));

// Outputs `is valid: false`
console.log('is valid: ' + timeValid(null));

// Outputs `is valid: false`
console.log('is valid: ' + timeValid(undefined));

 

Source Code

@toreda/time is an open source package provided under the MIT License. Download, clone, or check the complete project source here on Github. We welcome bug reports, comments, and pull requests.

 

Legal

License

MIT © Toreda, Inc.

Copyright

Copyright © 2019 - 2022 Toreda, Inc. All Rights Reserved.

Website

Toreda's company website can be found at toreda.com