Code Monkey home page Code Monkey logo

moment.twitter's Introduction

Twitter-like Date Formatter

moment.twitter.js is an extension to moment.js that formats dates like Twitter.

Works on both past and future dates.

Methods

moment().twitter()

Web-friendly formatting (alias moment().twitterLong()).

Examples:

Formats time relative to current time.

moment(moment() + (36e5 * 5)).twitter()
// 5 hours

Yes, it does smart pluralization.

moment(moment() + 36e5).twitter()
// 1 hour

Times greater than 24 hours are converted to dates like Mar 7

moment(moment() + 6048e5).twitter()
// Mar 7

moment().twitterShort()

For use on mobile.

Examples:

Units single characters, and there are no spaces.

moment(moment() + (36e5 * 5)).twitterShort()
// 5h

Times greater than 24 hours but more than 6 days are converted to days.

moment(moment() + (864e5 * 6)).twitterShort()
// 6d

Times greater than 6 days are slash-separated.

moment(moment() + 6048e5).twitterShort()
// 3/7/86

TODO

  1. Write some bad ass tests.
  2. Compile this with grunt, I guess.
  3. Get @timrwood to close timrwood/momentjs.com#24
  4. npm, require, commonjs, etc support.

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.