Skip to content
/ chronicle Public

Chronicle groups collections of ruby objects into time periods.

Notifications You must be signed in to change notification settings

zeke/chronicle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chronicle

Chronicle groups collections of ruby objects into time periods. It uses Chronic to parse natural language date strings.

# Before:
[obj_1, obj_2, obj_3, obj_4, obj_5, obj_6, obj_7, obj_8, obj_9, obj_10]

# After:
{
  "just now": [obj_10, obj_9],
  "two hours ago": [obj_8, obj_7, obj_6],
  "yesterday": [obj_5, obj_4, obj_3],
  "6 months ago": [obj_2],
  "1 year ago": [obj_1]
}

Chronicle was created for Sniphr, a pet project of mine that makes bookmarking awesome. I wanted to reduce UI chatter by displaying a minimal timeline beside the content, instead of a timestamp under every element. Here's what it looks like:

"Chronicle on Sniphr"

Installation

# Put this in your Gemfile and smoke it.
# Ruby 1.9 or greater is required, because chronicle relies on ordered hashes.
gem 'chronicle'

Usage

# Fetch some objects (presumably ActiveRecord)
things = Thing.all

# Put them into buckets, using Chronicle's default eras
chronicle = Chronicle.new(things)

# To deviate from the default eras...
chronicle = Chronicle.new(things, :eras => ["5 minutes ago", "2 hours ago", "three weeks ago"])

# To sort based on an attribute other than :created_at
chronicle = Chronicle.new(things, :date_attr => :updated_at)

To see the default eras used by Chronicle, have a look at chronicle.rb.

Other Noteworthy Time Tools

  • chronic_between, a natural language parser for validating complex date ranges.
  • chronic_duration, a simple Ruby natural language parser for elapsed time
  • 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.

License

MIT License. Do whatever you want.

About

Chronicle groups collections of ruby objects into time periods.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages