Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A dirt simple library for parsing and formatting human readable dates

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gemtest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 HISTORY 1.1.3, for rubygems-test again February 04, 2011
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 kronic.gemspec
README.rdoc

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 https://raw.github.com/xaviershay/kronic/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.

Something went wrong with that request. Please try again.