Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ruby gem that chunks a time range into pieces

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 timechunker.gemspec
README.md

Timechunker

What it does

Timechunker allows you to split a time range into pieces of a defined size, like this:

require "time"
require "timechunker"

timerange = Timechunker::Timerange.new(Time.parse("2011-02-03 18:04:02"),
                                       Time.parse("2011-02-03 18:29:02"))

five_minutes = Timechunker::Chunksize.new(5, 'minutes')

chunker = Timechunker::Chunker.new
chunker.get_chunks(timerange, five_minutes)

This will give you a list of all 5-minute chunks this timerange fits into

=> [Thu Feb 03 18:00:00 +0100 2011,
    Thu Feb 03 18:05:00 +0100 2011,
    Thu Feb 03 18:10:00 +0100 2011,
    Thu Feb 03 18:15:00 +0100 2011,
    Thu Feb 03 18:20:00 +0100 2011,
    Thu Feb 03 18:25:00 +0100 2011]

Installation

gem install timechunker

TODO

Only works with 'minute' chunks, other chunk types need to be supported, too.

Something went wrong with that request. Please try again.