Units.create :time do |m| m.system :base do |s| s.unit :name => :nanosecond, :equals => 0.000000001.seconds, :abbrev => [:ns, :nsec] s.unit :name => :microsecond, :equals => 0.000001.seconds, :abbrev => [:us, :usec] s.unit :name => :millisecond, :equals => 0.001.seconds, :abbrev => [:ms, :msec] s.unit :name => :second, :abbrev => [:s, :sec] s.unit :name => :minute, :equals => 60.seconds, :abbrev => [:m, :min] s.unit :name => :hour, :equals => 60.minutes, :abbrev => [:h, :hr] s.unit :name => :day, :equals => 24.hours, :abbrev => [:d, :dy] s.unit :name => :week, :equals => 7.days, :abbrev => [:w, :wk] s.format :name => :weeks_and_days, :format => lambda { |u| weeks = u.weeks.floor days = (u-weeks).days.round weeks == 0 ? (days == 0 ? "#{weeks}" : "#{days}") : "#{weeks} #{days}" } end m.system :common do |s| s.unit :name => :month, :equals => [30.days, 4.weeks], :abbrev => [:m, :mo] s.unit :name => :year, :equals => [365.days, 12.months, 52.weeks], :abbrev => [:y, :yr] end m.system :long do |s| s.unit :name => :decade, :equals => 10.years s.unit :name => :century, :plural => :centuries, :equals => 100.years s.unit :name => :millenium, :plural => :millenia, :equals => 1000.years end m.system :old_english do |s| s.unit :name => :fortnight, :equals => 2.weeks end m.system :months do |s| s.unit :name => :january, :equals => 31.days, :singular => true, :sequence => 1 s.unit :name => :february, :equals => [28.days, 29.days], :singular => true, :sequence => 2 s.unit :name => :march, :equals => 31.days, :singular => true, :sequence => 3 s.unit :name => :april, :equals => 30.days, :singular => true, :sequence => 4 s.unit :name => :may, :equals => 31.days, :singular => true, :sequence => 5 s.unit :name => :june, :equals => 30.days, :singular => true, :sequence => 6 s.unit :name => :july, :equals => 31.days, :singular => true, :sequence => 7 s.unit :name => :august, :equals => 31.days, :singular => true, :sequence => 8 s.unit :name => :september, :equals => 30.days, :singular => true, :sequence => 9 s.unit :name => :october, :equals => 31.days, :singular => true, :sequence => 10 s.unit :name => :november, :equals => 30.days, :singular => true, :sequence => 11 s.unit :name => :december, :equals => 31.days, :singular => true, :sequence => 12 end end