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

timesolver

v1.2.0

Published

A small library for manipulating, validating and formatting JavaScript date object.

Downloads

108

Readme

timeSolver.js

A small library for manipulating, validating and formatting JavaScript date object. Futhermore, it can helps you log your execution time by using timelook.

Current Version : v1.2.0

Getting Start

Installation

Install via npm or download source file directly

  • npm
npm install timesolver
  • source

https://github.com/sean1093/timeSolver/tree/master/src

Usage

You need to use timeSolver object to manipulate JavaScript date object.

Include timeSolver, You can use global object in your page.

<script type="text/javascript" src="timeSolver.min.js"></script>

You also can use via require.

const timeSolver = require('./../timeSolver');

For example, if you want to get datetime string with format "YYYYMMDD", you need to do by following:

const dateString = timeSolver.getString(new Date(), "YYYYMMDD");

Method

Add and Subtract

You can use this basic manipulate on date, add or subtract, by different time unit(type)

/**
 * Add time by time unit
 * 
 * @param {date/string} [date] standard JavaScript Date object or date string
 * @param {string} [count] a number you want to add on date
 * @param {string} [type] timeSolver time unit
 * @return {date} standard JavaScript Date object
 */
const afterAdd = timeSolver.add(date, count, type);

/**
 * Subtract time by time unit
 * 
 * @param {date/string} [date] standard JavaScript Date object or date string
 * @param {string} [count] a number you want to subtract on date
 * @param {string} [type] timeSolver time unit
 * @return {date} standard JavaScript Date object
 */
const afterSubtract = timeSolver.subtract(date, count, type);

timeSolver time unit

Equal

/**
 * Check whether two dates equals or not 
 * 
 * @param {date/string} [date1] standard JavaScript Date object or date string
 * @param {date/string} [date2] standard JavaScript Date object or date string
 * @return {boolean} equals or not  
 */
const result = timeSolver.equal(date1, date2);

After

/**
 * Check whether date1 after date2 or not 
 * 
 * @param {date/string} [date1] standard JavaScript Date object or date string
 * @param {date/string} [date2] standard JavaScript Date object or date string
 * @return {boolean} date1 after date2 or not  
 */
const result = timeSolver.after(date1, date2, type);

After Today

/**
 * Check whether date after today or not 
 * 
 * @param {date/string} [date] standard JavaScript Date object or date string
 * @return {boolean} date1 after today or not  
 */
const result = timeSolver.afterToday(date);

Before

/**
 * Check whether date1 before date2 or not 
 * 
 * @param {date/string} [date1] standard JavaScript Date object or date string
 * @param {date/string} [date2] standard JavaScript Date object or date string
 * @return {boolean} date1 before date2 or not  
 */
const result = timeSolver.before(date1, date2, type);

Before Today

/**
 * Check whether date before today or not 
 * 
 * @param {date/string} [date] standard JavaScript Date object or date string
 * @return {boolean} date1 before today or not  
 */
const result = timeSolver.beforeToday(date);

Between

/**
 * Count time by time unit between two date 
 * 
 * @param {date/string} [date1] standard JavaScript Date object or date string
 * @param {date/string} [date2] standard JavaScript Date object or date string
 * @param {string} [type] timeSolver time unit
 * @return {number} return count by time unit 
 */
const result = timeSolver.between(date1, date2, type);

timeSolver time unit

Get Date String

/**
 * Get date time string by different format 
 * 
 * @param {date/string} [date] standard JavaScript Date object or date string
 * @param {string} [format] timeSolver string format
 * @return {string} return formated string
 */
const dateString = timeSolver.getString(date, format);

timeSolver string format

Get Week and Month

Get date's weekday or month name, it will return abbr. or full name by different method

const result1 = timeSolver.getAbbrWeek(date);
const result2 = timeSolver.getFullWeek(date);
const result3 = timeSolver.getAbbrMonth(date);
const result4 = timeSolver.getFullMonth(date);

isValid

/**
 * Check whether date string is valid or not and return true/ false if dateString valid or not 
 * 
 * @param {string} [dateString] date string
 * @param {string} [format] timeSolver valid format
 * @return {boolean} dateString is valid or not
 */
const result = timeSolver.isValid(dateString, format);

timeSolver valid format

getQuarterByMonth

/**
 * Get quarter by give month
 * 
 * @param {number} [month] month number
 * @return {number} return quarter number
 */
const quarter = timeSolver.getQuarterByMonth(month);

getFirstMonthByQuarter

/**
 * Get quarter's first month string by give quarter
 * 
 * @param {number} [quarter] quarter number
 * @return {number} return month number
 */
const firstMonth = timeSolver.getFirstMonthByQuarter(quarter);

timeSolver time unit

timeSolver string format

timeSolver valid format

timeLook

It can helps you log your execution time by using timeLook

  1. start timeLook
timeSolver.timeLookStart();
  1. set your break point with label text
timeSolver.timeLook("test");
...
timeSolver.timeLook("date basic function");
...
...
  1. see your time log report
timeSolver.timeLookReport();

For example, it will print on your browser console.

timeLook

It will shows every execution time between your two break point, and mark the bottleneck with red color(Chrome Console).

License

MIT

Update log

  • 1.2.0 (20180408)
    • Add unit-test
    • New feature: getQuarterByMonth and getFirstMonthByQuarter
  • 1.1.1 (20180401)
    • Add to npm
  • 1.1.1 (20170718)
    • Enhance function: isValid(), add three timestamp format
  • 1.1.0 (20170614)
    • New feature: timeLook, helps you log your execution time
  • 1.0.7 (20170613)
    • Bug fix: YYYYMMDD: 2017613 -> 20170613
  • 1.0.6 (20170110)
    • Add some new feature
    • Add minify version
  • 1.0.5 (20160813)
    • Module load compatibility
  • 1.0.4 (20160614)
    • Bug fix
  • 1.0.3 (20160425)
    • Restructure
  • 1.0.2
    • Bug fix: between()
  • 1.0.1
    • Add new function: isValid()