Coder Social home page Coder Social logo

moment.twitter's Introduction

Twitter-like Date Formatter Build Status

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

Usage

Works with AMD, CommonJS and browser environments.

// AMD
define(['moment-twitter'], function(moment) { moment().twitter() });
// CommonJS
var moment = require('moment-twitter');
moment().twitter()
<!-- Browser -->
<script type="text/javascript" src="/moment.js"></script>
<script type="text/javascript" src="/moment-twitter.js"></script>
<script type="text/javascript">
    moment().twitter();
</script>

Works on both past and future dates.

Methods

moment().twitterLong()

Web-friendly formatting.

Examples:

Formats time relative to current time.

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

Yes, it does smart pluralization.

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

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

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

moment().twitter()

For use on mobile (alias moment().twitterShort()).

Examples:

Units single characters, and there are no spaces.

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

Times between 24 hours and 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

moment.twitter's People

Contributors

brunowinck avatar davewasmer avatar hijonathan avatar philfreo avatar silvenon avatar twhitbeck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

moment.twitter's Issues

npm audit log

$ npm audit

                       === npm audit security report ===

┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ moment                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in>=2.19.3                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ moment-twitter                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ moment-twitter > moment                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/532                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ moment                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in>=2.11.2                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ moment-twitter                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ moment-twitter > moment                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/55                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 2 vulnerabilities (1 low, 1 moderate) in 2691 scanned packages
  2 vulnerabilities require manual review. See the full report for details.

Publishing a new version on NPM

Howdy! Big moment.twitter fan. I noticed the latest NPM version is .0.0.1, and it uses an older version of moment.

Looks like 0.0.2 fixes that, but isn't published. @hijonathan , any chance you'd have a moment to publish the new version?

Thanks!

Smash some of the TODOs

I made some changes to this code here: SpiderStrategies@9dc8eb0

This takes care of some of your listed TODOs, although it turns the project into JavaScript, which I think is better for modules that are in NPM. Let me know if you'd like a proper pull request.

moment.twitter requirejs version

I'm looking for a javascript requirejs version of the same. Its a great plugin for moment which I would like to use and is pretty urgent.

Pl help

Indication of future time

I know this script handles times in the future, but the formatting doesn't indicate whether a date is in the past or the future, which leaves things rather ambiguous. Would it be possible to prepend future times with "in" (e.g. "in 5m") or a negative symbol?

Issue with hour (over 1 hour) .fromNow() vs .twitter()

Hi there,

When I am using the .fromNow(); function in moment.js (for example, it returns "2 hours ago"), I get the correct amount of hours ago a tweet was posted, but when I use .twitter() instead, it returns the incorrect amount of hours (Instead of returning "2h" it returns "1h"). The tweets are from different feeds posted in different timezones and I convert the timestamps to UTC. Any advice on how to fix this?

Thanks!

Does not work on React-Native 0.22.2

Throws this error -


It works if I update the package.json of your repo to use moment ^2.12.0 and run npm install again.
Is there a pitfall to this solution? Or would you accept a PR for this?

License missing

Just so you know, because you're not publishing a license, I break the law in most countries by using your code.

Thanks anyway :-)

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.