To Patch or Not To Patch

151 visualizações
Ir para a primeira mensagem não lida

Ryan Bigg (Radar)

não lida,
07/08/2009, 01:44:1107/08/09
para rubyonra...@googlegroups.com
Recently a lot of people I've spoken with have expressed that distance_of_time_in_words sucks for accuracy, providing values such as "about 2 years" where "2 years, 5 months, 3 days, 4 hours, 6 minutes and 42 seconds" is "more appropriate". To fix this, I've written a plugin: http://github.com/radar/dotiw. I'm thinking that this should be in Rails core as it is a vast improvement over what currently exists, but I don't want to put the effort into a patch that's just going to be rejected, as per usual.

Who else would find this useful?

--
Ryan Bigg

Michael Koziarski

não lida,
07/08/2009, 01:48:3307/08/09
para rubyonra...@googlegroups.com
The whole purpose of the existing method is to provide an approximate
value, if that's not what you're looking for then you shouldn't be
calling that method :)

Given that your plugin is completely stand alone and doesn't need to
override anything messy to keep functioning, I don't think we need to
make the change unless millions of people are clamouring for it. Not
to pre-judge but this is the first time I've heard this asked for, so
I'm thinking we'll be best off leaving things as they are.

> --
> Ryan Bigg
>
> >
>



--
Cheers

Koz

Jason King

não lida,
07/08/2009, 02:34:5107/08/09
para rubyonra...@googlegroups.com
I wouldn't mind "about 2 and a half years" for the example in Ryan's
original, For the record, I can't think of any time I'd want "2
years, 5 months, 3 days, 4 hours, 6 minutes and 42 seconds" - sorry.

Ryan Bigg (Radar)

não lida,
07/08/2009, 02:46:0807/08/09
para rubyonra...@googlegroups.com
This is why I gave you :except options, so you can get 2 years, 6 months, for example.

2009/8/7 Jason King <smath...@gmail.com>



--
Ryan Bigg

Ryan Bigg (Radar)

não lida,
07/08/2009, 03:03:0807/08/09
para rubyonra...@googlegroups.com
Oh yeah, and if a value is 0 it won't show it either.

2009/8/7 Ryan Bigg (Radar) <radarl...@gmail.com>



--
Ryan Bigg

Ryan Angilly

não lida,
07/08/2009, 09:00:0707/08/09
para rubyonra...@googlegroups.com
lol @ "as per usual"  How jaded we've all become.  :)

I would use this.  I've built things like this a few times, and there's always the case where I screw up and get "1 hours" (wrong pluralization) or "80 seconds" (instead of 1 minute 20 sec).  Be nice to standardize going forward.

Andrew Kaspick

não lida,
07/08/2009, 10:00:3607/08/09
para rubyonra...@googlegroups.com
I just recently wrote my own to get exact results for everything minus
the seconds for timing purposes in some logging. So your plugin with
:except would have likely done the trick for me.

jsoo

não lida,
08/08/2009, 00:46:4208/08/09
para Ruby on Rails: Core
I'd be interested

On Aug 7, 12:44 am, "Ryan Bigg (Radar)" <radarliste...@gmail.com>
wrote:

Magne

não lida,
05/02/2015, 08:35:1705/02/15
para rubyonra...@googlegroups.com
I'd find it extremely useful. The current implementation sucks, for various reasons.

Actually, what you expect when you use distance_of_time_in_words, and what arguably should be the default in rails, is for it to output precisely what you input.
The method is not called rounded_distance_of_time_in_words, after all.

What you would expect:

helper.distance_of_time_in_words(1.hour) => "1 hour"          not "about 1 hour" which it currently does.
helper.distance_of_time_in_words(1.hour+ 15.minutes) =>   "1 hour and 15 minutes" or "one hour and a quarter."      and not "about 1 hour" which it currently does.

Fancy rounding of hours and days should be something extra, for the people that need that. 
For everyone else, there should be sane defaults, namely a convention that doesn't violate expectation.
You shouldn't have to monkey-patch the app, or use an extra gem, to get the sane defaults.

Currently, this is how fancy it has become:

helper.distance_of_time_in_words(41.hours+ 59.minutes+29.seconds) => "1 day"      eh.. WTF?      Since when did 1 day become 42 hours and not 24? Even according to the rounding principles used, this doesn't make much sense.

Or these intervals:

1 yr <-> 1 yr, 3 months                                                   # => about 1 year
1 yr, 3 months <-> 1 yr, 9 months                                         # => over 1 year

Who on earth would be able to deduce from the output that 1 year and 3 months is "about one year", and not "over 1 year"?

See all the fancy roundings here in the docs, and see if you don't agree with me.

Having the expected precision is especially important when using this in email communication towards users, or for communicating deadlines.
Precision doesn't hurt, apart from being a bit UX unfriendly at times. On the other hand, imprecision and fancy roundings can be very damaging.

I vote that the relevant parts of the dotiw gem be made a part of core rails, since the default behavior should be intuitive and straightforward.

---
If you really find the fancy roundings useful, leave it in rails, but rename it to rounded_distance_of_time_in_words, fix the bugs,
and update it to support atleast half-hours, half-days and so on. Like this:

helper.distance_of_time_in_words(1.hour+ 29.minutes) =>   "one and a half hour" or "one hour and a half."      and not "about 1 hour" which it currently gives

There is already established a precedence for including halves. It currently supports half-minutes:

helper.distance_of_time_in_words(0, 39.seconds, include_seconds: true) => "half a minute"

---

cheers,

Magne Gåsland

Matt Jones

não lida,
05/02/2015, 22:01:4805/02/15
para rubyonra...@googlegroups.com
On Feb 5, 2015, at 8:35 AM, Magne <mag...@gmail.com> wrote:

I'd find it extremely useful. The current implementation sucks, for various reasons.

Actually, what you expect when you use distance_of_time_in_words, and what arguably should be the default in rails, is for it to output precisely what you input.
The method is not called rounded_distance_of_time_in_words, after all.

What you would expect:

helper.distance_of_time_in_words(1.hour) => "1 hour"          not "about 1 hour" which it currently does.
helper.distance_of_time_in_words(1.hour+ 15.minutes) =>   "1 hour and 15 minutes" or "one hour and a quarter."      and not "about 1 hour" which it currently does.

Fancy rounding of hours and days should be something extra, for the people that need that. 

Which, presumably, would be *everybody* who is using this helper now.

For everyone else, there should be sane defaults, namely a convention that doesn't violate expectation.
You shouldn't have to monkey-patch the app, or use an extra gem, to get the sane defaults.

You brought a 5+-year-old thread back to life to insist that the current behavior is not “sane”. [citation needed]
 
Currently, this is how fancy it has become:

helper.distance_of_time_in_words(41.hours+ 59.minutes+29.seconds) => "1 day"      eh.. WTF?      Since when did 1 day become 42 hours and not 24? Even according to the rounding principles used, this doesn't make much sense.

Or these intervals:

1 yr <-> 1 yr, 3 months                                                   # => about 1 year
1 yr, 3 months <-> 1 yr, 9 months                                         # => over 1 year

Who on earth would be able to deduce from the output that 1 year and 3 months is "about one year", and not "over 1 year"?

See all the fancy roundings here in the docs, and see if you don't agree with me.

Having the expected precision is especially important when using this in email communication towards users, or for communicating deadlines.
Precision doesn't hurt, apart from being a bit UX unfriendly at times. On the other hand, imprecision and fancy roundings can be very damaging.

I vote that the relevant parts of the dotiw gem be made a part of core rails, since the default behavior should be intuitive and straightforward.

Make a PR then. Nobody has done it in the last 5 years, so I’m unconvinced it is a thing anyone wants.


---
If you really find the fancy roundings useful, leave it in rails, but rename it to rounded_distance_of_time_in_words, fix the bugs,
and update it to support atleast half-hours, half-days and so on. Like this:


I dunno who “you” is in the sentence above. If it bugs you this much, again, submit a PR for discussion. You’ll need to explain why you want to make a breaking change in every app that uses a function that hasn’t changed in years, and you’ll need to provide a patch to deprecate the old names in the next 4.x series release.

—Matt Jones


helper.distance_of_time_in_words(1.hour+ 29.minutes) =>   "one and a half hour" or "one hour and a half."      and not "about 1 hour" which it currently gives

There is already established a precedence for including halves. It currently supports half-minutes:

helper.distance_of_time_in_words(0, 39.seconds, include_seconds: true) => "half a minute"

---

cheers,

Magne Gåsland

fredag 7. august 2009 07.44.11 UTC+2 skrev Ryan Bigg følgende:
Recently a lot of people I've spoken with have expressed that distance_of_time_in_words sucks for accuracy, providing values such as "about 2 years" where "2 years, 5 months, 3 days, 4 hours, 6 minutes and 42 seconds" is "more appropriate". To fix this, I've written a plugin: http://github.com/radar/dotiw. I'm thinking that this should be in Rails core as it is a vast improvement over what currently exists, but I don't want to put the effort into a patch that's just going to be rejected, as per usual.

Who else would find this useful?

--
Ryan Bigg

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Brian Dear

não lida,
06/02/2015, 09:49:0806/02/15
para rubyonra...@googlegroups.com
I would argue that this should be a method, Ryan's patch is actually a more accurate implementation of the current method. The current version should really be called something like approximate_time_in_words. However, it would be unrealistic to do that. I do think perhaps "exact_time_in_words" (or something similar) would be a good place for Ryan's method to exist. I think if people had it available, more would certainly use it. As it is now, most people don't think too much about it.

--
Brian Dear

queenn...@gmail.com

não lida,
14/03/2016, 14:45:5314/03/16
para Ruby on Rails: Core

I think this thing is difficult to implement given the fact that months and years/leap-years lack symmetry. Implementing it would take lines and lines and lines of code and some headache unless someone devised something clever and concise thinking out of the box. The core team wont admit the fact that this got difficult and just excuse themselves that it is not needed instead of putting it out there for people to solve like Ryan has tried.
Any rational person can of course see that in a web application, display of exact time is very important, especially is you have to count down deadlines(long or short), or allowed time for a user to access a resource. For it to look fair, a user got to see exact time.

Rails core have done a good job with the framework itself and no demands can be made on them, But it is important to admit that such a method as ryan syggests is needed. Like Yrs, Mths, days, hrs, mins, secs. and of course with a method to truncate accuracy.
Responder a todos
Responder ao autor
Reencaminhar
0 mensagens novas