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?

On 31 August 2010 04:44, reu [email protected] 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

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

On Tue, Aug 31, 2010 at 1:46 PM, Robert W. [email protected]
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 D.
destiney.com | gregdonald.com

Greg D. wrote:

On Tue, Aug 31, 2010 at 1:46 PM, Robert W. [email protected]
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 W. 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.

Michael P. wrote:

On 31 August 2010 20:15, Robert W. [email protected] wrote:

Greg D. 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 :slight_smile:

In what time zone?

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

On 31 August 2010 20:15, Robert W. [email protected] wrote:

Greg D. 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 :slight_smile:

On Tue, Aug 31, 2010 at 2:21 PM, Robert W. [email protected]
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?

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 D.
destiney.com | gregdonald.com

On 31 August 2010 20:21, Robert W. [email protected] 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?

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.

On Tue, Aug 31, 2010 at 2:30 PM, Robert W. [email protected]
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 D.
destiney.com | gregdonald.com

On Tue, Aug 31, 2010 at 2:41 PM, Robert W. [email protected]
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 D.
destiney.com | gregdonald.com

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

Greg D. wrote:

On Tue, Aug 31, 2010 at 2:41 PM, Robert W. [email protected]
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.

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

It can be useful in some cases.

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 L.
[email protected]