HiveBrain v1.2.0
Get Started
← Back to all entries
patternrubyrailsMinor

Date and time columns conversion to Time(WithZone)

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
conversioncolumnswithzonetimedateand

Problem

I have two columns representing a date and a time.

{dateproc: '2012-03-23', horproc: '2000-01-01 16:15:23 UTC'}


Both are read as a TimeWithZone by Rails. I need to combine them.

This is what I've done. It works, but it doesn't feel elegant, and it just doesn't seem readable.

date_time_combined = dateproc + horproc.seconds_since_midnight.seconds


Any advice on improving it?

Solution

Nope. That's about as clean as it'll get, though like Flambino said, you can skip the last .seconds call. It's a bit clunky, but that's just how it works out.

Context

StackExchange Code Review Q#10330, answer score: 2

Revisions (0)

No revisions yet.