Hi,
Just released version 0.0.9 of ‘relativity’
- What is it?
Time, Date and DateTime classes don’t have a mode for working with
relative time
inside 1 day (or 1 week, 1 month, 1 quarter, etc.). A relative time
object, relative to
a day or a week, is useful to describe e.g. opening hours of a business.
Ranges
are built on top, so the ranges of opening hours can be represented.
- Short example (more examples in the README):
require ‘relativity’
opens_at = DayTime.new(“8:35”) #=> 08:35:00
dtr = DayTimeRange.new(“8 to 12:30”) # => 08:00:00 to 12:30:00
dtr.start # => 08:00:00
dtr.to_s # => “08:00:00 to 12:30:00”
night_shift = DayTimeRange.new(“21:45…06:05”) # => 21:45:00…06:05:00
normalize is used for persisting a DayTime and DayTimeRange in
normalized format
DayTime.normalize(“8”) # => “08:00:00”
DayTime.normalize(nil) # => nil
DayTimeRange.normalize(“8…12”) # => “08:00:00…12:00:00”
DayTimeRange.normalize(“8 to 12”, :separator => “…”)
=> Relativity::InvalidRangeFormatError: Maybe the range separator was
not set correctly? Separator used was “…”
- Changes
** solved a bug with ruby 1.9.2 (thanks Bryan D. for the bug
report)
** added DayTimeRange
** added methods for normalization (used for persisting in AR)
** see Changelog for details
- TODO
** new/normalize checks hours, minutes, seconds, nanoseconds
in range (0…24, 0…60, 0…60, 0…1000_000_000)
** Add a ‘…’ range (up to, but not including)
** comparisons (==
, include?
, …)
** WeekTime
** WeekDay
** WeekTimeRange
** WeekDayRange
** …
HTH,
Peter