https://github.com/xaviershay/kronic
A dirt simple library for parsing and formatting human readable dates
https://github.com/xaviershay/kronic
Last synced: 8 months ago
JSON representation
A dirt simple library for parsing and formatting human readable dates
- Host: GitHub
- URL: https://github.com/xaviershay/kronic
- Owner: xaviershay
- License: mit
- Created: 2010-09-19T16:59:08.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2014-08-10T20:28:00.000Z (over 11 years ago)
- Last Synced: 2025-03-30T17:09:35.200Z (8 months ago)
- Language: Ruby
- Homepage: http://github.com/xaviershay/kronic
- Size: 250 KB
- Stars: 149
- Watchers: 4
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.rdoc
- Changelog: HISTORY
- License: LICENSE
Awesome Lists containing this project
- nlp-with-ruby - kronic - (High Level Tasks / Numbers, Dates, and Time Parsing)
README
= 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:
Kronic.parse("Today");
Kronic.format(new Date());
== 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 Ruby 2.0+.
== Developing
git clone git://github.com/xaviershay/kronic.git
bundle install # May take a while, needs to install therubyracer/V8 to test JS
bin/test # Run the tests
# 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.