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

datecounter

v1.0.92

Published

A tool class library that changes the time format,format date for articles, news or comments

Downloads

10

Readme

中文 | English

Datecounter

A tool class library that changes the time format

Format date for articles, news or comments

Usage

Parameter

Datecounter receive an object parameter , and return a counter :

| key | default/type | describe | required | | - | :-: | :- | :-: | | date | none/Date| Expected is Date Object or timestamp | yes | | countDay | 7/number | Countdown days | no | | i18n | 'zh'/string | Language | no | | raw | none/boolean | Raw data | no |

Essentials

import Datecounter from 'Datecounter'
const counter=new Datecounter({countDay: 10, i18n: 'en'})
counter(new Date())

Vue

// for Vue
import Vue from 'vue'
import {vDatecounter} from 'Datecounter'
Vue.use(vDatecounter, {countDay: 10, i18n: 'en'})

/************************* Global method *************************/
this.$datecounter(new Date())
/************************* Local method *************************/
const counter=new this.$Datecounter({countDay: 10, i18n: 'en'})
counter(new Date())

Example

import Datecounter from 'Datecounter'
var now = new Date() // now : Thu Jul 05 2018 09:20:00
var twoMinutesAgo = now - (2 * 60 * 1000)
var twoHoursAgo = now - (2 * 60 * 60 * 1000)
var fiveDaysAgo = now - (5 * 24 * 60 * 60 * 1000)
var eightDaysAgo = now - (8 * 24 * 60 * 60 * 1000)
var january = now - (180 * 24 * 60 * 60 * 1000)
var aYearsAgo = now - (365 * 24 * 60 * 60 * 1000)

/************************* Default usage *************************/
const counter1=new Datecounter({i18n: 'en'})
counter1(now)           // return : 0 minutes ago
counter1(fiveDaysAgo)   // return : 5 days 0 hours ago
counter1(january)       // return : January 6, 9:20
counter1(aYearsAgo)     // return : July 5, 2017 9:20

/************************* Countdown days *************************/
const counter2=new Datecounter({countDay: 10, i18n: 'en'})
const counter3=new Datecounter({countDay: 7, i18n: 'en'})
counter2(eightDaysAgo)  // return : 8 days 0 hours ago
counter3(eightDaysAgo)  // return : June 27, 9:20

/************************* i18n *************************/
/* langList = ['zh', 'en', 'jp', 'ru', 'kr', 'fr', 'vi'] */
/* Now noly have ['zh', 'en', 'jp'] , other language are being developed */
const counter_zh=new Datecounter({i18n: 'zh'})
const counter_en=new Datecounter({i18n: 'en'})
const counter_jp=new Datecounter({i18n: 'jp'})
counter_zh(fiveDaysAgo) // return : 5天0小时前
counter_en(fiveDaysAgo) // return : 5 days 0 hours ago
counter_jp(fiveDaysAgo) // return : 5天0時間前

Get raw data

/* If you need raw data */
/* There are four kinds of data types in all ['history', 'countDown_day', 'countDown_hour', 'countDown_minute'] */
const count_raw=new Datecounter({raw: true})
count_raw(twoMinutesAgo)// return : {type: "countDown_minute", minute: 2}
count_raw(twoHoursAgo)  // return : {type: "countDown_hour", hour: "2", minute: "0"}
count_raw(fiveDaysAgo)  // return : {type: "countDown_day", day: "5", hour: "0"}
count_raw(january)      // return : {type: "history", year: null, month: 1, date: 6, hour: 9, minute: 20 }
count_raw(aYearsAgo)    // return : {type: "history", year: 2017, month: 7, date: 6, hour: 9, minute: 20 }

If you are good at these languages ['en', 'jp', 'ru', 'kr', 'fr', 'vi'], maybe you can help me.😄