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

verbose-time-travel

v1.0.3

Published

Semantic lightweight date/time change with verbose alises

Downloads

103

Readme

verbose-time-travel

verbose-time-travel is a lightweight (under 70 lines) date-time processing library with semantic interface and verbose arguments. The library allows to set a base date-time and get a changed Date object based on any free text string. Fluctuation model and calculations are based on simple integer arithmetics.

Examples

Travel to 10 minutes in past from the current moment

import { travel } from 'verbose-time-travel';

console.log('Travel to 10 minutes in past from the current moment');
const newDate: Date = travel('10 min').back();
console.log(newDate);

Travel to 2 weeks and 4 hours in the future

import { travel } from 'verbose-time-travel';

console.log('Travel to 2 weeks and 4 hours in the future');
const newDate: Date = travel('2 weeks 4 h').forward();
console.log(newDate);

Travel to 1 day in the future from start of Unix

import { travelFrom } from 'verbose-time-travel';

console.log('Travel to 1 day in the future from start of Unix');
const newDate: Date = travelFrom(new Date(0)).forward('1 day');
console.log(newDate);

Travel to the future based on free text input

import { travel } from 'verbose-time-travel';

console.log('Travel to the future based on free text input');
// ignores unrecognized terms like '1 time'
const newDate: Date = travel('I want to get 3 days 5 hours and 34 msec to the future at least 1 time').forward();
console.log(newDate);

API Reference

Class VerboseTimeTravel

Constructors:

  • constructor(fluctuation: string, fixed: Date | number = Date.now())
    fluctuation - any text containing date/time parts the fixed date should be changed by fixed - either Date object or number (representing number of epoch msec Date.now()) which sets a fixed point in time of an instance of VerboseTimeTravel. By default a current moment (Date.now())

Methods:

  • back(fluctuation?: string): Date
    fluctuation - any text containing date/time parts the fixed date should be changed by. Overrides the value that can be passed to constructor. Returns Date object date in the past by fluctuation
  • forward(fluctuation?: string): Date
    fluctuation - any text containing date/time parts the fixed date should be changed by. Overrides the value that can be passed to constructor. Returns Date object date in the future by fluctuation

Utils

  • travel(fluctuation: string): VerboseTimeTravel
    fluctuation - any text containing date/time parts the fixed date should be changed by. Returns an instance of VerboseTimeTravel with a fluctuation set to the parameter value and fixed point in current moment.
  • travelFrom(from: Date): VerboseTimeTravel
    from - Date object representing a fixed point. Returns an instance of VerboseTimeTravel with a fixed point set to the parameter value and 0 fluctuation.

Supported aliases for time parts

NOTE: Due to a very lightweight fluctuation calculation based on simple number arithmetics in the logic for the moment library does not support months and years, those can be replaced by a needed amount of other supported parts. Support for month and year will be added in further versions

  • millisecond - ms, millisec, millisecond, milliseconds, msec
  • second - s, sec, second, seconds
  • minute - m, min, minute, minutes
  • hour - h, hour, hours
  • day - d, day, days
  • week - w, week, weeks