Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[![Build Status](https://travis-ci.org/tmlee/time_difference.png)](https://travis-ci.org/tmlee/time_difference)

This latest version of the gem works with ActiveSupport 5.1. For prior version, check out [v0.6.x-activesupport42](https://github.com/tmlee/time_difference/tree/0.6.0-activesupport42)
This latest version of the gem works with ActiveSupport 5.1. For prior versions, check out [v0.6.x-activesupport42](https://github.com/tmlee/time_difference/tree/0.6.0-activesupport42).

# TimeDifference

TimeDifference is the missing Ruby method to calculate difference between two given time. You can do a Ruby time difference in year, month, week, day, hour, minute, and seconds.
TimeDifference is the missing Ruby method to calculate the difference between two given times. You can get the time difference in years, months, weeks, days, hours, minutes, and seconds.

## Installation

Expand All @@ -22,7 +22,7 @@ $ bundle install

## Usage

### Works for Time, DateTime, and Date
### Works for Time, DateTime, Date, and String

```ruby
# Time
Expand All @@ -45,6 +45,16 @@ end_time = Date.new(2014,1)

TimeDifference.between(start_time, end_time).in_years
=> 1.0

# String
TimeDifference.between("1970-01-01", Time.now).in_years
=> 48.23

TimeDifference.between("23:59", "23:59:59").in_seconds
=> 59.0

TimeDifference.between(10.years.ago, "13/12/2011").in_years
=> 3.72
```

### Get the time difference in various units
Expand Down Expand Up @@ -95,7 +105,7 @@ TimeDifference.between(start_time, end_time).in_general
=> {:years=>0, :months=>12, :weeks=>0, :days=>5, :hours=>0, :minutes=>0, :seconds=>0}
```

### You can also get `in_general` as a human readable string, using `humanize`
### You can also get `in_general` as a human-readable string, using `humanize`

```ruby
start_time = Time.new(2013,1)
Expand Down