On 14 October 2010 15:52, voidstar <[email protected]> wrote:
> I need a date/time object due to domain requirements although at this
> point I don't care about the time object, I just want it to be
> midnight.  There are other ways for the user to enter data into this
> table where the time element becomes relevant.

My understanding of this issue (which may be flawed) is that if you
have a datetime field on a form the rails assumes the value entered is
in local time, and converts it to gmt ready to be put in the database.
 I _think_ that if, in environment.rb you put
config.time_zone = 'UTC'
then it will assume that the value entered is already in UTC and will
not apply the timezone offset.

Colin

>
> Where do I have the rails source?  Also do you know what file/class
> handles receiving a post request from a form?
>
> If anyone else is interested here's the code I'm using to reset the
> time to midnight.
>
>   �...@gas_reading = @user.gas_readings.build(params[:gas_reading])
>
>   �...@gas_reading.start_date = @gas_reading.start_date.change(:hour =>
> 0, :min => 0, :second => 0) unless @gas_reading.start_date.nil?
>   �...@gas_reading.end_date = @gas_reading.end_date.change(:hour =>
> 0, :min => 0, :second => 0) unless @gas_reading.end_date.nil?
>
>
>
> On Oct 14, 1:34 pm, Marnen Laibow-Koser <[email protected]> wrote:
>> voidstar wrote in post #950126:
>>
>> > Hey,
>> > Thanks for the reply, I could easily write some code to discard the
>> > time field, which is what I'll probably do now
>>
>> You don't have to discard anything.  Just ignore it.
>>
>> Check Rails' field types; I think if you define the field in the
>> migration as date instead of datetime, you will get a Date object from
>> the DB, not the DateTime you currently have.
>>
>> > but I'd just like to
>> > know how rails is doing this, I guess is should go about downloading
>> > the rails source and grok it myself.
>>
>> You've already got the Rails source.
>>
>>
>>
>> > I'm in GMT but using daylight savings.
>>
>> > I guess if I just reset the time members of the DateTime object its
>> > returning to me I'm relatively insulated from errors if this
>> > translation changes in a future release.
>>
>> There's no need to reset.   There's no translation, really; Rails is
>> creating a DateTime object, so it needs a time value.  Again, you're
>> overthinking it and persuading yourself into more complex code than is
>> actually necessary.
>>
>>
>>
>> > Thanks
>> > Barry
>>
>> Best,
>> --
>> Marnen Laibow-Koserhttp://www.marnen.org
>> [email protected]
>>
>> --
>> Posted viahttp://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to