From 5ac668f2ccd88e8b6017e9ebffdad5eca66bce92 Mon Sep 17 00:00:00 2001 From: chocolateboy Date: Sun, 25 Mar 2018 22:17:41 +0100 Subject: [PATCH] doc: add String examples + fix typos --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7d2189a..43e820b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -22,7 +22,7 @@ $ bundle install ## Usage -### Works for Time, DateTime, and Date +### Works for Time, DateTime, Date, and String ```ruby # Time @@ -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 @@ -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)