Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

mysql time

#5788

setting something in migration as .time and the resulting table contains date when its supposed to be just time.

this in migration

t.time :time, :default => "00:00:00"

this is what schema ends up being after running the migration

t.time "time", :default => '2000-01-01 00:00:00'

Reported by jerome187 · October 11th, 2010 @ 06:40 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Ryan Bigg
    Ryan Bigg
    • State changed from new to incomplete
    • Importance changed from to Low

    Please submit a failing test case as a patch as per the http://guides.rubyonrails.org/contributing_to_rails.html guide so that this issue can be resolved.

    October 11th, 2010 @ 11:33 PM

  2. jerome187
    jerome187
    • Tag set to activerecord

    no problem

    how is this test?

    October 12th, 2010 @ 05:12 AM

  3. Aditya Sanghi
    Aditya Sanghi
    • State changed from incomplete to invalid

    Rails maps SQL types to Ruby classes, SQL time gets mapped to Ruby's Time class. Time class in ruby has a date component. Rails defaults this to 2000-01-01. If you need to work on the time component, you need to regard bonus_time as an object of Ruby's Time class. If you need to read the Time component of bonus_time, you should refer to the Time class' documentation and send required methods.

    To get "00:00:00", you would do t.bonus_time.strftime("%H:%M:%S") or t.bonus_time.to_s(:time) to get "00:00".

    October 12th, 2010 @ 08:52 AM

  4. jerome187
    jerome187

    right my bad for using strings for comparison. well ok take a look at this test, if you try to save a time with more than 24 hours, no joy.

    October 12th, 2010 @ 03:31 PM

  5. Aditya Sanghi
    Aditya Sanghi

    Not sure what the use case here is, but 25:00:00 does not parse as a time, it will throw argument out of range.
    If you want to store the semantic "duration", you would be better off with another field not a time sql type.

    October 12th, 2010 @ 09:41 PM

  6. jerome187
    jerome187

    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview....

    quote "
    TIME

    A time. The range is '-838:59:59' to '838:59:59'. MySQL displays TIME values in 'HH:MM:SS' format, but permits assignment of values to TIME columns using either strings or numbers. "

    I want to use it for markers in video content. Having a limit of 24hrs when -838 to 838 hrs is available in mysql (not sure of other databases) seems, uh, lame, for lack of better word.

    I found it easy to write the test, I could take a crack at implementation as well.

    October 12th, 2010 @ 09:58 PM

  7. Aditya Sanghi
    Aditya Sanghi

    Awesome, please do send a patch.

    However, I do maintain, if you want to use video markers, you would be better off storing seconds from start in an integer field.

    October 12th, 2010 @ 10:56 PM

  8. jerome187
    jerome187

    We will want milliseconds or at least tenths of a second too now that I think about it. There does not seem to be support for milliseconds in any of the mysql datatypes. Probably better off storing as a floating point disguised as string, or HH:MM:SS:hundredths of a sec

    I guess means I will not implement it, at least for the time being, as I don't think we will use it.

    October 12th, 2010 @ 11:13 PM