Swatch's internet time in Ruby [Code Inside]

  • Thread starter Pablo Lorenzzoni
  • Start date
P

Pablo Lorenzzoni

Hello ALL!

Just wanted to share... maybe someone have a better way to do this:

-----<beats.rb>-----
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
-----<EOF beats.rb>-----

require('beats.rb') and Time.now.beats returns the Internet Time in beats

[]s

Pablo
 
W

Wesley J Landaker

--Boundary-02=_Zdrz/5ksi//sHZa
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Description: signed data
Content-Disposition: inline

Hello ALL!

Just wanted to share... maybe someone have a better way to do this:

-----<beats.rb>-----
class Time

def bmt_hour
h =3D self.gmtime.hour + 1
return 0 if h =3D=3D 24
return h
end

def beats
((self.bmt_hour * 60 * 60) + (self.min * 60) +
self.sec) / 86.4 end

protected :bmt_hour
end
-----<EOF beats.rb>-----

require('beats.rb') and Time.now.beats returns the Internet Time in
beats

Personally, I prefer my Internet Time in seconds: Time.now.utc

=3D)

=2D-=20
Wesley J. Landaker - (e-mail address removed)
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2


--Boundary-02=_Zdrz/5ksi//sHZa
Content-Type: application/pgp-signature
Content-Description: signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQA/zrdZ8KmKTEzW49IRAqzBAJ0bG0loGSnxR2qUW3vAR/8K9vEGrACeIR2x
TsvKh4Pv/Mwm3GIghNq5UQ8=
=BZr/
-----END PGP SIGNATURE-----

--Boundary-02=_Zdrz/5ksi//sHZa--
 
H

Hal Fulton

Pablo said:
Hello ALL!

Just wanted to share... maybe someone have a better way to do this:

-----<beats.rb>-----
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
-----<EOF beats.rb>-----

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.


Cheers,
Hal
 
H

Hal Fulton

Hal said:
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
 
R

Robert Klemme

Hal Fulton said:
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

Another alternative:

def bmt_hour
( gmtime.hour + 1 ) % 24
end

:)

robert
 
P

Pablo Lorenzzoni

Hello!


Em Qui, 04 Dez 2003, Hal Fulton escreveu:
| But is this correct? Beat 0 isn't midnight GMT, is it? Isn't there
| a time zone difference? Maybe I'm wrong.

Beat 0 is midnight in the BMT timezone, not GMT. BMT is GMT+1

[]s

Pablo
 
P

Pablo Lorenzzoni

Hello (again :))

Em Qui, 04 Dez 2003, Hal Fulton escreveu:
| Oh, sorry to reply to myself. I now see you added 1 to the hour.
| I overlooked that.

Yes... It is the BMT stuff...

| BTW, if you want a style comment, here's one: Explicit returns are
| rarely needed, especially as the last expression becomes the
| return value.

Thanx... I come from a explicit-return-needed-world... Sometimes I just
forget it's Ruby I am using... ;-)

| Also you don't really need "self" in all those places.

Noted again.

| How about this:
|
| def bmt_hour
| h = gmtime.hour + 1
| h == 24 ? 0 : h
| end

Good! I didn't know Ruby had the (cond) ? (if-true) : (if-false)
syntax...

[]s

Pablo
 
J

Joey Gibson

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.


I remember reading your Swatch time stuff in TRW and I thought then as
now: where does this 'Internet Time' get used? I'd never seen it before
I read TRW and I've not seen it since until this discussion. Is it
actually useful for anything? Is anyone really using it? Am I behind the
curve?

Joey

--
Never trust a girl with your mother's cow,
never let your trousers go falling down in the green grass...

http://www.joeygibson.com
http://www.joeygibson.com/blog/life/Wisdom.html
 
H

Hal Fulton

Joey said:
I remember reading your Swatch time stuff in TRW and I thought then as
now: where does this 'Internet Time' get used? I'd never seen it before
I read TRW and I've not seen it since until this discussion. Is it
actually useful for anything? Is anyone really using it? Am I behind the
curve?

It's mostly a novelty. It has some limited usefulness but it's
mostly just a nerd toy and a Swatch marketing gimmick.

Part of the idea is: Let's make a universal time zone that's the
same for the whole world. ("Fine," you say, "just use GMT.")

This is so people around the world can meet in chat rooms at
prearranged times, etc.

It's base 10 (1000 beats per day) as that's the one holdout in
our units that's not "metric" (even in SI, I suppose). Obviously
it's a full-day clock, no am or pm.

The 86.4-second unit allows one to be fashionably late, as the
time is more "grainy"; and the cool at-sign ("Meet me @365")
reminds one of an email address.

There's desktop software available that will display the Internet
time, and Swatch does/did make watches that displayed it (in
addition to the traditional time). I'm the only person I know
who has one, though.

In short, it's just a novelty and has no real significance, and
you're not behind the curve. :)

Hal
 
D

Dave Brown

: Just wanted to share... maybe someone have a better way to do this:
:
: -----<beats.rb>-----
: 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
: -----<EOF beats.rb>-----
:
: require('beats.rb') and Time.now.beats returns the Internet Time in beats

Since we're doing silly time hacks...

#!/usr/bin/ruby

class Time
@@hours=[
"zero", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve"
]

def fuzzytime

myhour=self.hour

if self.min==0 && self.sec==0 then
timestring = "exactly"
else
timestring = case min%5
when 0 then "just about"
when 1..2 then "about"
when 3..4 then "nearly"
end
end

if self.min>=33 then
myhour+=1
end

timestring += " " + case self.min
when 0..2, 57..59 then "%s o'clock"
when 3..7 then "five past %s"
when 8..12 then "ten past %s"
when 13..17 then "quarter past %s"
when 18..22 then "twenty past %s"
when 23..27 then "twenty-five past %s"
when 28..32 then "half past %s"
when 33..37 then "twenty-five to %s"
when 38..42 then "twenty to %s"
when 43..47 then "quarter to %s"
when 48..52 then "ten to %s"
when 53..57 then "five to %s"
end

if myhour == 0 || myhour == 24 then
timestring=timestring.sub(/ o'clock/,'')
timestring = timestring % "midnight"
else
timestring += " " + case myhour
when 1..4 then "in the middle of the night"
when 5..11 then "in the morning"
when 12..17 then "in the afternoon"
when 18..20 then "in the evening"
when 21..23 then "at night"
end
end

myhour -= 12 if myhour > 12

return timestring % @@hours[myhour]
end
end

class Fuzzytime < Time
alias :to_s :fuzzytime
end

if __FILE__ == $0 then
print "It's #{Fuzzytime.new}.\n"
end

--Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,816
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top