Git Product home page Git Product logo

kronic's Introduction

Kronic

A dirt simple library for parsing and formatting human readable dates (Today, Yesterday, Last Monday). Both a ruby and a javascript implementation are included.

Usage

Ruby

gem install kronic

require 'kronic'
Kronic.parse("Today")     # => Date.today
Kronic.format(Date.today) # => "Today"

Supported formats: Today, yesterday, tomorrow, last thursday, this thursday, 14 Sep, 14 June 2010. Any dates without a year are assumed to be in the past (that’s what my app needs, so that’s what it does).

Javascript

Install by grabbing the latest versions direct from github:

curl http://github.com/xaviershay/kronic/raw/master/lib/js/kronic.js   > public/javascripts/kronic.js

Use with the following script:

<script src="/javascripts/kronic.js"   type="text/javascript"></script>
<script>
  Kronic.parse("Today");
  Kronic.format(new Date());
</script>

Why not Chronic or Tickle

Chronic and Tickle both parse a heap of formats. That’s not useful to me when they fail on cases I want (14 Sep), and also not useful because I don’t need times or spans. I just want to replace my calendar picker.

In addition, Kronic can take a date and give you a human readable form, neither of which Chronic nor Tickle does.

Oh yeah, Kronic is about 150 lines of ruby code with no dependencies, and provides a javascript implementation.

Compatibility

Kronic does not require ActiveSupport, but if it is present Kronic will use the current time zone. In short, everything should work as you would expect.

Kronic is tested on 1.8.7, 1.9.2, Rubinius 1.1, and JRuby 1.5.1.

Developing

git clone git://github.com/xaviershay/kronic.git
bundle install # May take a while, needs to install therubyracer/V8 to test JS
rake # Run the specs
# Dive into the code at spec/kronic_spec.rb

There are comments to help you along but it is pretty basic code, so everything should make sense pretty quickly. The javascript code is a direct translation of the ruby code, and as such it is undocumented - just refer back to the ruby code.

The exact same set of specs are run again the ruby and javascript libraries, so they should be 100% compatible.

Patches welcome! Fork and send a pull request. Please follow coding conventions already in use. If jsl (JSLint) is in your path, rake will run it over the javascript implementation. There are currently no warnings, please keep it that way.

Status

Current release is stable, and being used in production sites. Some I18n work is in yolk’s fork, but it is lagging behind the current release. I am not using this personally. Maybe also a flag to toggle the interpretation of dates without years would be nice, but not something I need.

kronic's People

Contributors

bemurphy avatar eugenebolshakov avatar ihid avatar leshill avatar stympy avatar xaviershay avatar

Stargazers

 avatar

Watchers

 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.