Does Ruby have an equivalent to TimeSpan in C#?

ruby, timespan

Solution

In the end I forked the suggestion in @tokland's answer. Not quite sure how to make it a proper gem but it's currently working for me:

Timespan fork of time_diff

Problem

In C# there is a TimeSpan class. It represents a period of time and is returned from many date manipulation options. You can create one and add or subtract from a date etc. In Ruby and specifically rails there seems to be lots of date and time classes but nothing that represents a span of time? Ideally I'd like an object that I could use for outputting formatted dates easily enough using the standard date formatting options. eg. ``` ts.to_format("%H%M") ``` Is there such a class? Even better would be if I could do something like ``` ts = end_date - start_date ``` I am aware that subtracting of two dates results in the number of seconds separating said dates and that I could work it all out from that.

Original source