From: Hal Fulton Date: 2003-12-04T16:30:33+09:00 Subject: Re: Swatch's internet time in Ruby [Code Inside] Hal Fulton wrote: > Pablo Lorenzzoni wrote: > >> Hello ALL! >> >> Just wanted to share... maybe someone have a better way to do this: >> >> ---------- >> class Time >> >> def bmt_hour >> h = self.gmtime.hour + 1 >> return 0 if h == 24 >> return h >> end >> >> def beats >> ((self.bmt_hour * 60 * 60) + (self.min * 60) + >> self.sec) / 86.4 >> end >> protected :bmt_hour >> end >> ---------- >> >> require('beats.rb') and Time.now.beats returns the Internet Time in beats > > > I have no problem with the coding style... there are various > ways of doing it. > > But is this correct? Beat 0 isn't midnight GMT, is it? Isn't there > a time zone difference? Maybe I'm wrong. > > I wrote similar code in _The Ruby Way_, but I've forgotten the details. Oh, sorry to reply to myself. I now see you added 1 to the hour. I overlooked that. BTW, if you want a style comment, here's one: Explicit returns are rarely needed, especially as the last expression becomes the return value. Also you don't really need "self" in all those places. How about this: def bmt_hour h = gmtime.hour + 1 h == 24 ? 0 : h end Cheers, Hal