Created
May 1, 2014 23:54
-
-
Save StephenOTT/93e8f02941e3b23cb156 to your computer and use it in GitHub Desktop.
Example of using Chronic gem and TimeDifference gem to get the duration between two statements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chronic' | |
require 'time_difference' | |
humanStatement1 = "this tuesday 1pm" | |
humanStatement2 = "this tuesday 3pm" | |
humanStatement1Parsed = Chronic.parse(humanStatement1) | |
humanStatement2Parsed = Chronic.parse(humanStatement2) | |
# very human readable version | |
puts TimeDifference.between(humanStatement1Parsed, humanStatement2Parsed).in_hours #=> 2.0 | |
# No need for the Prased Variables version | |
puts TimeDifference.between(Chronic.parse(humanStatement1), Chronic.parse(humanStatement2)).in_hours #=> 2.0 | |
# Single Line version | |
puts TimeDifference.between(Chronic.parse("this tuesday 1pm"), Chronic.parse("this tuesday 3pm")).in_hours #=> 2.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment