Giter Club home page Giter Club logo

pctmoment's Introduction

pctMoment

Build Status Bower version Coverage Status

Angular.js wrapper for Moment.js and potentially for moment-timezone.js.

Installation

Download it with bower:

bower install --save pct-moment

pctMoment allows you to use any version of Moment.js that is greater than version 2.0.

Optionally you can also use Moment-timezone.js, any version that is greater than 0.2.

You can use bower or any other means to download whatever Moment.js and Moment-timezone.js version you want to use (given the above constraints) just don't forget to add them to your site.

pctMoment's bower package has this both libs as dependencies, you can install other versions freely.

Use with Moment.js

<script src="moment.js"></script>
<script src="pctMoment.js"></script>

Use with Moment.js and Moment-timezone.js

<script src="moment.js"></script>
<script src="moment-timezone.js"></script>
<script src="pctMoment.js"></script>

Get an error!

<script src="pctMoment.js"></script>

How to use it

This wrapper returns a shortcut for window.moment, the same moment APIs are still there, checkout their docs

//script.js
angular.module('example', ['pctMoment'])

.controller('ExampleController', function (moment) {

    //use momentjs api!

    moment().format();

    moment().startOf('day').fromNow();


    //if you also add moment-timezone.js to your site,
    //then you can use its API too!

    moment.tz("2014-06-01 12:00", "America/New_York");

    //don't forget to load the Time Zones data when
    //using moment-timezones!


});

You can also detect if Moment-timezone has been loaded or not as a way of asserting against that parameter

angular.module('example', ['pctMoment'])

.controller('ExampleController', function(isMomentTimezoneLoaded, moment) {

    if (!isMomentTimezoneLoaded()){
        throw new Error('please load moment-timezone.js please!') 
    }

    //use moment-timezone api!

    moment().tz('Europe/Rome').format();
}); 

For more documentation check inline docs (we are still working on auto generating the docs).

Motivation

While there are other Angular.js wrappers for Moment.js, they are all too full of filters, services, directives that we are not interested in right now.

These are the motivations for creating yet another Angular.js Moment.js wrapper:

  • Wrap Moment.js the Angular way (no globals)
  • No additional filters, directives or services (we might add support for TimeZone format, but that's it!)
  • Not tied to any Moment.js version.
  • Not tied to any Moment-timezone version.
  • Motivate good practices
  • To provide as thin as possible abstraction layer from Moment's API
  • To provide a reusable module from which people can build more complex things

Inspiration

Thanks to all these resources for inspiration and learning:

Contribute

This project uses Gulp, Karma and JSCS (stylechecker). Use them and contribute!

Licence

MIT (see LICENCE file)

pctmoment's People

Contributors

franleplant avatar

Watchers

James Cloos avatar  avatar

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.