Skip to content

toxaq/timespan

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timespan

Creation of a timespan obect for simple formating of time differences. Forked from the very useful time_diff

Setup in rails

gem 'timespan', :git => 'git://github.com/toxaq/timespan.git'

Usage

require 'timespan'

time_span_from_dates = Time.diff(start_date_time, end_date_time)
time_span_from_seconds = Time.new(duration_in_seconds)

This will return a Timespan object of time difference with properties of years, months, weeks, days, hours, minutes and seconds.

Formatted Time difference

%y - year

%M - month

%w - week

%d - day

%H - hour

%N - minute

%S - second

%h - hour (without adding 'hour' text to the hours. eg: 3 for 3 hours)

%m - minute (without adding 'minute' text)

%s - second (without adding 'second' text)

By default the format is

'%y, %M, %w, %d and %h:%m:%s'

and is called by

time_span.to_format

and will return

'1 year, 2 months, 3 weeks, 4 days and 12:05:52'.

You can pass a custom format like this

time_span.to_format('%h:%m:%s')

The output of the format is cummulative. If you give ‘%d %h’ as the format to the Timespan.to_format() method, then the output will be calculated only in days and hours.

Copyright © 2011 abhidsm. See LICENSE.txt for further details.

About

Gem which calculates the difference between two time

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%