#!/usr/bin/ruby # a class to convert time to mountyhall dates # (c) 2009 YGuillot - WtfPLv2 class Day Mundi = ['de la Saison du Hum', 'du Phoenix', 'de la Mouche', 'du Dindon', 'du Goblin', "du D\xe9mon", 'de la Limace', 'du Rat', 'de l\'Hydre', 'du Ver', 'du Fungus', 'de la Vouivre', 'du Gnu', "du Scarab\xe9e"] Zero = Time.mktime(2001, 8, 26, 12) # 12PM to avoid DST bugs attr_accessor :time, :day, :month, :cycle # initialize with a string ('31/12/2008') or a Time object def initialize(str=Time.now) @day = 0 @month = 0 @cycle = 1 @time = str.kind_of?(Time) ? str : Time.mktime(*str.split('/').reverse.map { |i| i.to_i }) @day = (@time - Zero).to_i / (24*3600) fixup end # add d days to the current date (returns a new object) def +(d) o = dup o.time += d * 24 * 3600 o.day += d o.fixup o end def -(d) self + -d end # forward in time 1 mundidey def nextmundi; self + mundilen end # forward in time 1 cycle def nextcycle; self + 14 + (Mundi.length-1) * 28 end # days is this mundidey def mundilen; ((@month % Mundi.length) == 0) ? 14 : 28 end # fixup after changing day (16e j de la saison du hum => 2e j du Phoenix) def fixup while @day >= mundilen @day -= mundilen @month += 1 end while @day < 0 @month -= 1 @day += mundilen end while @month >= Mundi.length @month -= Mundi.length @cycle += 1 end while @month < 0 @cycle -= 1 @month += Mundi.length end end def to_s @time.strftime('%d/%m/%Y: ') + (@day == 0 ? 'Mundidey' : "#{@day+1}e jour") + " #{Mundi[@month]} du #{@cycle}e cycle apr\xe8s Ragnarok" end end if __FILE__ == $0 case ARGV.first when /^\d+$/ abort 'pas de cycle n.0' if ARGV.first.to_i == 0 t = Day.new(Day::Zero) t = t.nextcycle until t.cycle == ARGV.first.to_i Day::Mundi.each { puts t t = t.nextmundi } when /^\d+\/\d+\/\d+$/ puts Day.new(ARGV.shift) else puts Day.new end end