Time without date

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

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.

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...

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

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

Greg Donald 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).

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.

If I have a date at 4pm on Tuesday, the date is at 4pm regardless of
the state of daylight savings time :slight_smile:

Michael Pavling 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.

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.

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 :slight_smile:

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.

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 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.

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.

> 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..

Greg Donald 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.

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 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

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.

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 ?