Time range min/max inconsistency

Discussion in 'Ruby' started by Fischer Krisztián, Jul 17, 2007.

  1. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Hi!

    I created a range of Time objects. My problem (?) is, that the range's
    min() and max() methods return their values in a different format.

    I made the following test:

    ?> t1 = Time.utc(2007,7,17,10,00)
    => Tue Jul 17 10:00:00 UTC 2007

    >> t2 = Time.utc(2007,7,17,12,00)

    => Tue Jul 17 12:00:00 UTC 2007

    >> r=(t1..t2)

    => Tue Jul 17 10:00:00 UTC 2007..Tue Jul 17 12:00:00 UTC 2007

    >> r.min

    => Tue Jul 17 10:00:00 UTC 2007

    >> r.max

    => Tue Jul 17 14:00:00 +0200 2007

    As you may see r.max returns the correct value, however it is in a
    different time format as r.min's return value (and different from the
    initial value).

    If I use these values in a user interface, the max value must be
    converted to a UTC time with r.max.utc before i can format it with
    strftime().

    Do you think this is a bug, or should i read more ruby literature? :)

    I'm pretty new to ruby, so please don't slap me in the face for this. :)

    Thank you,
    Chris

    - --
    Fischer Krisztián
    Borganization Kft.
    Tel: (+36) 70/384-383-5
    Tel: (+36) 1/3360547
    email:
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQFGnMz46VUohGTtAQYRAl76AJ4jZH+mHmJzQWqn17GUJAl6yDi8lgCgxBZj
    anm75OzaJYA1v1hQyrh+w3Y=
    =cXVu
    -----END PGP SIGNATURE-----
     
    Fischer Krisztián, Jul 17, 2007
    #1
    1. Advertising

  2. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Brett Simmers wrote:
    >> => Tue Jul 17 14:00:00 +0200 2007

    > I don't know if this is related to your problem, but whenever I use
    > Marshal.load to load a marshaled Time object, it's always created in the
    > local timezone, regardless of what zone the saved object was in. This
    > is similar behavior, although I'm pretty sure Ranges don't use Marshal,
    > and it's weird that it's just the max.


    Thanks for the answer.

    Seems to me like timezone is the black sheep in ruby. Today I ran into
    the problem described above, and shortly after this into an other one.

    If you store a UTC time in mysql via rails' ActiveRecord and read it
    back, the local timezone is added to the time, which is pretty strange.

    I could fix the problem with a small hack, however as a ruby newbie it
    took me a day to figure this out. :)

    Thanks,
    Chris

    - --
    Fischer Krisztián
    Borganization Kft.
    Tel: (+36) 70/384-383-5
    Tel: (+36) 1/3360547
    email:
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQFGnVEA6VUohGTtAQYRAjR8AJ0UbIKu37o/ikmuqzsSWKmgAk11+gCeKl8H
    08K2vUyDVr1giGzH+Tb88sc=
    =RX1m
    -----END PGP SIGNATURE-----
     
    Fischer Krisztián, Jul 18, 2007
    #2
    1. Advertising

  3. Fischer Krisztián

    Pena, Botp Guest

    From: Yukihiro Matsumoto [mailto:]=20
    # <> writes:
    # |?> t1 =3D Time.utc(2007,7,17,10,00)
    # |=3D> Tue Jul 17 10:00:00 UTC 2007
    # |
    # |>> t2 =3D Time.utc(2007,7,17,12,00)
    # |=3D> Tue Jul 17 12:00:00 UTC 2007
    # |
    # |>> r=3D(t1..t2)
    # |=3D> Tue Jul 17 10:00:00 UTC 2007..Tue Jul 17 12:00:00 UTC 2007
    # |
    # |>> r.min
    # |=3D> Tue Jul 17 10:00:00 UTC 2007
    # |
    # |>> r.max
    # |=3D> Tue Jul 17 14:00:00 +0200 2007
    #=20
    # You've found a bug in Ruby. It's fixed in the repository.
    # Thank you for the report.

    matz, i find the ruby src/test very helpful. Is *updating the ruby =
    src/test available for the public or only for ruby-core?=20

    kind regards -botp
     
    Pena, Botp, Jul 18, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lois
    Replies:
    1
    Views:
    3,414
    Ryan Stewart
    Dec 27, 2004
  2. juergen
    Replies:
    3
    Views:
    584
    opalinski from opalpaweb
    Sep 20, 2006
  3. Summu82
    Replies:
    5
    Views:
    902
    Richard Heathfield
    Jun 7, 2006
  4. Albert Hopkins

    When is min(a, b) != min(b, a)?

    Albert Hopkins, Jan 21, 2008, in forum: Python
    Replies:
    31
    Views:
    864
    Albert van der Horst
    Feb 4, 2008
  5. Alexander

    Improving min/max for Range

    Alexander, Nov 25, 2005, in forum: Ruby
    Replies:
    6
    Views:
    130
    Alexander
    Nov 25, 2005
Loading...

Share This Page