Coder Social home page Coder Social logo

juration's Introduction

Juration.js

A simple natural language duration parser written in javascript. Time ranges (in seconds) can also be converted to human readable strings. Check out the demo.

Inspired by chronic, and chronic_duration.

Usage

Parsing

juration.parse("3mins 5secs"); // returns 185

Stringifying

juration.stringify(185); // returns "3 mins 5 secs"
juration.stringify(185, { format: 'small' }); // returns "3 mins 5 secs"
juration.stringify(185, { format: 'micro' }); // returns "3m 5s"
juration.stringify(185, { format: 'long' });  // returns "3 minutes 5 seconds"
juration.stringify(185, { format: 'long', units: 1 });  // returns "3 minutes"
juration.stringify(3601, { format: 'micro', units: 2 });  // returns "1h"

Examples

Parse-able strings:

  • 12.4 secs
  • 3 mins 4 sec
  • 2 hrs 20 min
  • 2h20min
  • 6 mos 1 day
  • 47 yrs 6 mos and 4d
  • 3 weeks and 2 days

Todo

  • Add customisable default unit option, e.g. juration.parse("10", { defaultUnit: 'minutes' }) // returns 600
  • Parse chrono format i.e. hh:mm:ss

Licence

Juration is copyright © 2011 Dom Christie and released under the MIT license.

juration's People

Contributors

boivie avatar domchristie avatar jotto avatar miguelff 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

juration's Issues

Parsing months in micro format fails

I use the micro format to parse back and forth. The months and minutes both use m as unit which causes issues when parsing the dates. I would like to be more compatible with general date formats which uses M for months and m for minutes.

Create release

Hi,

Could you please create an 'official' release for 0.0.1? Then I can point to a real version when using bower :-)

Thanks!

bower install

@domchristie First off, awesome library! I've looked high and low for something like juration.

It'd be fantastic if juration was available via bower.

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.