Forum: Ruby on Rails Time without date

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4ba2711791e20a0e28ba675c5bf9757d?d=identicon&s=25 reu (Guest)
on 2010-08-31 05:46
(Received via mailing list)
Rails automatically appends a dummy date when you use the TIME type on
your database. My point is: if you are using a time data type on your
database, you are doing that exactly because you don't want the date
included.

Anyway, I am storing a integer column with the total seconds on the
database and then transforming that with composed_of. Is there a
better way to do that? Anyone know if there is a gem or something to
handle cases like these?
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2010-08-31 10:09
(Received via mailing list)
On 31 August 2010 04:44, reu <rnavarro1@gmail.com> wrote:
> Rails automatically appends a dummy date when you use the TIME type on
> your database. My point is: if you are using a time data type on your
> database, you are doing that exactly because you don't want the date
> included.
>
> Anyway, I am storing a integer column with the total seconds on the
> database and then transforming that with composed_of. Is there a
> better way to do that? Anyone know if there is a gem or something to
> handle cases like these?

I just use a datetime column and ignore the date part.

Colin
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2010-08-31 20:46
reu wrote:
> Rails automatically appends a dummy date when you use the TIME type on
> your database. My point is: if you are using a time data type on your
> database, you are doing that exactly because you don't want the date
> included.
>
> Anyway, I am storing a integer column with the total seconds on the
> database and then transforming that with composed_of. Is there a
> better way to do that? Anyone know if there is a gem or something to
> handle cases like these?

Time without data is useless and extremely prone to error. Internally
time is stored as millisecond offsets from a reference date (e.g. UNIX
time is the number of milliseconds from midnight January 1, 1970 UTC).
The date and time related objects in Ruby depend on this underlying
offset.

a value of 14:00 is meaningless without relating that to some date, in
some time zone, and applying the geopolitical rules for daylight savings
(or other adjustments to the normal flow of time).

I personally don't know why MySQL even bothers providing a TIME field
type.

Of course, as always, I could be missing some specific use case for it.
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2010-08-31 20:47
Robert Walker wrote:
> Time without data is useless and extremely prone to error. Internally
> time is stored as millisecond offsets from a reference date (e.g. UNIX
> time is the number of milliseconds from midnight January 1, 1970 UTC).
> The date and time related objects in Ruby depend on this underlying
> offset.

Correction: Time without date...
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2010-08-31 20:59
(Received via mailing list)
On Tue, Aug 31, 2010 at 1:46 PM, Robert Walker <lists@ruby-forum.com>
wrote:
> I personally don't know why MySQL even bothers providing a TIME field
> type.
>
> Of course, as always, I could be missing some specific use case for it.

Repeating events, "Tuesdays at 4:00pm" for example.

PostgreSQL also provides a time field type where no date is stored.


--
Greg Donald
destiney.com | gregdonald.com
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2010-08-31 21:15
Greg Donald wrote:
> On Tue, Aug 31, 2010 at 1:46 PM, Robert Walker <lists@ruby-forum.com>
> wrote:
>> I personally don't know why MySQL even bothers providing a TIME field
>> type.
>>
>> Of course, as always, I could be missing some specific use case for it.
>
> Repeating events, "Tuesdays at 4:00pm" for example.
>
> PostgreSQL also provides a time field type where no date is stored.

As I said meaningless without applying the date part to it. If today is
Saturday, and the event is scheduled at 4:00 p.m. Tuesday, what happens
if the time changes to, or from, daylight savings time at 2:00 a.m.
Sunday. The value "4:00 p.m." must be translated based on the specific
date the Tuesday lands on. Might as well just store the time as a string
at that point. The time has no value as a Time (object) (i.e it must be
parsed based on the date anyway).
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2010-08-31 21:16
Robert Walker wrote:
> As I said meaningless without applying the date part to it. If today is
> Saturday, and the event is scheduled at 4:00 p.m. Tuesday, what happens
> if the time changes to, or from, daylight savings time at 2:00 a.m.
> Sunday. The value "4:00 p.m." must be translated based on the specific
> date the Tuesday lands on. Might as well just store the time as a string
> at that point. The time has no value as a Time (object) (i.e it must be
> parsed based on the date anyway).

I suppose though that the TIME field would provide some basic
validation, which would be it's only benefit as far as I see it.
56b7e1808013614acdb73cbaaa6938a1?d=identicon&s=25 Michael Pavling (Guest)
on 2010-08-31 21:19
(Received via mailing list)
On 31 August 2010 20:15, Robert Walker <lists@ruby-forum.com> wrote:
> Greg Donald wrote:
> As I said meaningless without applying the date part to it. If today is
> Saturday, and the event is scheduled at 4:00 p.m. Tuesday, what happens
> if the time changes to, or from, daylight savings time at 2:00 a.m.
> Sunday. The value "4:00 p.m." must be translated based on the specific
> date the Tuesday lands on. Might as well just store the time as a string
> at that point. The time has no value as a Time (object) (i.e it must be
> parsed based on the date anyway).


If I have a date at 4pm on Tuesday, the date is at 4pm regardless of
the state of daylight savings time :-)
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2010-08-31 21:21
Michael Pavling wrote:
> On 31 August 2010 20:15, Robert Walker <lists@ruby-forum.com> wrote:
>> Greg Donald wrote:
>> As I said meaningless without applying the date part to it. If today is
>> Saturday, and the event is scheduled at 4:00 p.m. Tuesday, what happens
>> if the time changes to, or from, daylight savings time at 2:00 a.m.
>> Sunday. The value "4:00 p.m." must be translated based on the specific
>> date the Tuesday lands on. Might as well just store the time as a string
>> at that point. The time has no value as a Time (object) (i.e it must be
>> parsed based on the date anyway).
>
>
> If I have a date at 4pm on Tuesday, the date is at 4pm regardless of
> the state of daylight savings time :-)

In what time zone?
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2010-08-31 21:30
Robert Walker wrote:
>> If I have a date at 4pm on Tuesday, the date is at 4pm regardless of
>> the state of daylight savings time :-)
>
> In what time zone?

My point being again that any interpretation of whatever gets stored as
a time only, must be translated into a Time or DateTime object based on
a specific date, in a specific locale. That's really all I'm saying.
4:00 p.m. from your locale may mean 7:30 p.m. in my locale. It's
dependent on geopolitical rules.
56b7e1808013614acdb73cbaaa6938a1?d=identicon&s=25 Michael Pavling (Guest)
on 2010-08-31 21:31
(Received via mailing list)
On 31 August 2010 20:21, Robert Walker <lists@ruby-forum.com> wrote:
>> If I have a date at 4pm on Tuesday, the date is at 4pm regardless of
>> the state of daylight savings time :-)
>
> In what time zone?

Hopefully she'll be in the same as me wherever it is, otherwise it
probably won't be a very good date.

But, if there is a risk in the implementation that timezones confusion
could cause problems, then store a timezone value in addition to the
time. There's not that much more confusion with timezones caused when
storing just time than with datetime.
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2010-08-31 21:31
(Received via mailing list)
On Tue, Aug 31, 2010 at 2:21 PM, Robert Walker <lists@ruby-forum.com>
wrote:
>> If I have a date at 4pm on Tuesday, the date is at 4pm regardless of
>> the state of daylight savings time :-)
>
> In what time zone?

Not all apps require multi-timezone capabilities.  Like when everyone
is in one office, using the same calendar app.

Dreaming up edge cases isn't going to make those time (without date)
fields any less useful to those of us who use them.


--
Greg Donald
destiney.com | gregdonald.com
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2010-08-31 21:38
(Received via mailing list)
On Tue, Aug 31, 2010 at 2:30 PM, Robert Walker <lists@ruby-forum.com>
wrote:
> My point being again that any interpretation of whatever gets stored as
> a time only, must be translated into a Time or DateTime object based on
> a specific date, in a specific locale. That's really all I'm saying.
> 4:00 p.m. from your locale may mean 7:30 p.m. in my locale. It's
> dependent on geopolitical rules.

Lots of web apps, certainly dozens I've built, are just for a single
company, with a single office, in a single time zone.

That's great that you build apps where time zone does matter, and that
you build apps for companies where time zone does matter, but it
doesn't make the time (without date) field any less useful to me.


--
Greg Donald
destiney.com | gregdonald.com
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2010-08-31 21:41
Greg Donald wrote:
> Not all apps require multi-timezone capabilities.  Like when everyone
> is in one office, using the same calendar app.
>
> Dreaming up edge cases isn't going to make those time (without date)
> fields any less useful to those of us who use them.

You're still missing my point entirely. We're talking about representing
a time with a Time object. It matters not whether you need to support
multi-timezone or not. AFAIK there is no Ruby object that represents
time without date. The Time object represents an instant in date/time,
not some offset from midnight.

I hope that makes my meaning more clear.
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2010-08-31 21:56
(Received via mailing list)
On Tue, Aug 31, 2010 at 2:41 PM, Robert Walker <lists@ruby-forum.com>
wrote:
> You're still missing my point entirely. We're talking about representing
> a time with a Time object. It matters not whether you need to support
> multi-timezone or not.

I agree, you brought it up.

> AFAIK there is no Ruby object that represents
> time without date.

It's called a Fixnum, works great.


--
Greg Donald
destiney.com | gregdonald.com
00c2ec5c197b2de8e55997e594ba4c0a?d=identicon&s=25 Klaus D. (kdiddy)
on 2010-08-31 22:07
(Received via mailing list)
> > In what time zone?
>
To produce a specific part it takes our machine 1 hour and 15 minutes
=> 01:15:00
And I would like to store this value in the database.
Btw it wouldn't matter if this part will be produced on Mondays or
Tuesdays or in which time zone the factory is..
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2010-08-31 22:07
Greg Donald wrote:
> On Tue, Aug 31, 2010 at 2:41 PM, Robert Walker <lists@ruby-forum.com>
> wrote:
>> You're still missing my point entirely. We're talking about representing
>> a time with a Time object. It matters not whether you need to support
>> multi-timezone or not.
>
> I agree, you brought it up.
>
>> AFAIK there is no Ruby object that represents
>> time without date.
>
> It's called a Fixnum, works great.

Yep. I apologize for the misunderstanding. I knew we were arguing the
same side of the issue. It just took me a few tries to get to the heart
of the matter.

Fixnum (INTEGER) is exactly what I typically use as well (i.e. an offset
from midnight).

reu wrote:
> Rails automatically appends a dummy date when you use the TIME type on
> your database. My point is: if you are using a time data type on your
> database, you are doing that exactly because you don't want the date
> included.

My original intent was an effort to explain this question in original
post. Rails is applying a "dummy date" because it must. However, that
time representation is subject to interpretation. And that depends on
what time zone Rails applies to that interpretation.
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2010-08-31 23:20
(Received via mailing list)
> Time without date is useless and extremely prone to error. Internally
> time is stored as millisecond offsets from a reference date (e.g. UNIX
> time is the number of milliseconds from midnight January 1, 1970 UTC).
> The date and time related objects in Ruby depend on this underlying
> offset.
>
> a value of 14:00 is meaningless without relating that to some date, in
> some time zone, and applying the geopolitical rules for daylight savings
> (or other adjustments to the normal flow of time).

Just for the sake of argument... how about the time it takes runners to
finish a marathon?  Sure you could use seconds as an integer field, but
time without date make sense...

I agree that "4pm" is kind of pointless, but "16 hours" can be handy.

If only to save me from having to convert from seconds to hh:mm:ss and
back, etc...

-philip
808842a18055c7cfc323b7ecce62cd24?d=identicon&s=25 Denis P. (denis_p)
on 2012-10-26 09:43
Philip Hallstrom wrote in post #937228:

> Just for the sake of argument... how about the time it takes runners to
> finish a marathon?  Sure you could use seconds as an integer field, but
> time without date make sense...

I'm currently developing application, where I need to store beginning
date (date only, without time) and amount of time passed.

I found a gem, that deals with 'time without date' issue:
https://github.com/lailsonbm/time_of_day

It can be useful in some cases.
8b1719b70dc02b69393330f5c64ecf86?d=identicon&s=25 Klaus G. (klaus_g)
on 2012-10-26 16:35
(Received via mailing list)
Am Dienstag, 31. August 2010 23:12:51 UTC+2 schrieb Philip:
> -philip
>
 So we have to differentiate between
-  "Time" which means Point of Time in a specific day, and
-  "Duration" which means the difference between two Points in Time

Is there a "Duration" gem for RoR ?
59a33b3125d7c10d38c6f5ae136b015b?d=identicon&s=25 Zhi-Qiang Lei (Guest)
on 2012-10-26 17:27
(Received via mailing list)
Yes, check ActiveSupport, RoR has it.

On Oct 26, 2012, at 10:34 PM, KlausG wrote:

> -  "Time" which means Point of Time in a specific day, and
>
>


Best regards,
Zhi-Qiang Lei
zhiqiang.lei@gmail.com
Db3bea38beb7530ebde20d0849251449?d=identicon&s=25 Vitaliy Yanchuk (fuksito)
on 2017-01-24 17:24
We have this issue as well. There is lots of use cases for just Time,
specially to remove problems and errors with time zones. For instance I
want to store time of standard pickup window, for instance from 10 till
17. And then apply this "Time" to specific date in some timezone. On
ruby side I would expect such object to contain validation of input
hour/minute values
4dbbe772797a2b16ee59230114e578e9?d=identicon&s=25 Sam Ivon (sammyicon)
on 2017-04-28 13:48
Thanks for the advises, cuz last week my developers noticed similar
issue, and I've searched for the solution everywhere. We mostly working
with maths and geometry tutoring  so if there's a need to solve complex
assignment or even to get the deep understanding of analytical geometry,
the tutors at  https://answershark.com/geometry can always find an
answer for you and explain the subject
This topic is locked and can not be replied to.