Project

timerange

0.02
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Time ranges for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0

Runtime

 Project Readme

TimeRange

Time ranges for Ruby

Installation

Add this line to your application’s Gemfile:

gem 'timerange'

Features

time_range = TimeRange.new(7.days.ago..Time.now)
time_range.step(1.day)
time_range.expand(:week).step(1.day)

TimeRange.new("2014-06-01", "2014-06-07")
TimeRange.new("2014-06-01", duration: 1.week)
TimeRange.new("2014-06-01", within: 5.minutes)
TimeRange.new(4.weeks.ago).expand_start(:week) # last 4 weeks

TimeRange.today
TimeRange.yesterday

TimeRange.today + 4.weeks
TimeRange.today - 4.weeks

TimeRange.bucket(:hour, user.created_at)
TimeRange.bucket(:day, user.created_at, day_start: 2) # 2 am
TimeRange.bucket(:week, user.created_at, week_start: :mon) # start weeks on Monday
TimeRange.bucket(:month, user.created_at, time_zone: "Pacific Time (US & Canada)")

TimeRange.time_zone = "Pacific Time (US & Canada)" # defaults to Time.zone

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help: