Coder Social home page Coder Social logo

timemark's Introduction

timemark

timemark

a tool for humanizing time

中文文档(TODO)

Usage

npm i timemark
or
yarn add timemark

/**
 * timemark
 *
 * it tells the mark of (endDate - startDate)
 * startDate is an optional parament, default by current time // new Date()
 *
 * @param    {string | number | Date}  endDate
 * @param    {string | number | Date}  startDate
 *
 * @returns  string
 */

import timemark from 'timemark';


const mark = timemark(Date.now()); // == timemark(Date.now(), new Data())
console.log(mark); // -> '今天'

const mark2 = timemark(1546272000000, 1546358400000) // as (2019-1-1, 2019-1-2)
console.log(mark2); // -> '昨天'

Rule

Calculate the delta of endDay to startDay. The mark will fall into one of these methods by delta range.

  • closest days '昨天', '今天', '明天', '后天'
    current range is [-1, 2]
    configurable only in source code

  • little futher days '周六', '下周一'
    current range is delta from startDay in [3, 6]
    configurable only in source code

  • others
    simple formatter by pattern 'YYYY-MM-DD', such as '2019-02-03'
    if you want more, try moment.js.

'2019-02-03',
'2019-02-04',
'昨天', 
'今天', 
'明天', 
'后天', 
'周六', 
'周日', 
'下周一', 
'下周二',
'2019-02-13',
'2019-02-14',

Source Code

npm run test
or
yarn test

Further

  • better README
  • more �test
  • more option �for the function (see the code)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.