timesince 'depth' parameter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

timesince 'depth' parameter

Toby Such
Hi all!

I've been a little frustrated with the timesince filter that comes with default Django. By default it always comes with 2 parts e.g. 4 hours and 3 minutes ago but I would much rather have just the 4 hours. In my own projects I've simply created my own version of the timesince filter and accompanying utils function that powers it that just has the code which adds the second part removed. However I wonder why this isn't standard as I can't think of a single website that displays time since as multiple parts.

I'm proposing adding a 'depth' parameter to the timesince function which would allow the developer to set how many parts to render. At depth one it would be "3 weeks". 2 depth: "3 weeks 2 days" (default behaviour), 3 depth: "3 weeks, 2 days, 4 hours ago" etc.

Does anyone have any thoughts related to this?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/97fbcab8-3f0f-4277-9296-fdcff7fcdab5%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

אורי
Hi,

On Sat, May 23, 2020 at 12:39 AM Toby Such <[hidden email]> wrote:
Hi all!

I've been a little frustrated with the timesince filter that comes with default Django. By default it always comes with 2 parts e.g. 4 hours and 3 minutes ago but I would much rather have just the 4 hours. In my own projects I've simply created my own version of the timesince filter and accompanying utils function that powers it that just has the code which adds the second part removed. However I wonder why this isn't standard as I can't think of a single website that displays time since as multiple parts.

I'm proposing adding a 'depth' parameter to the timesince function which would allow the developer to set how many parts to render. At depth one it would be "3 weeks". 2 depth: "3 weeks 2 days" (default behaviour), 3 depth: "3 weeks, 2 days, 4 hours ago" etc.


Actually I think it's a good idea. I don't think I ever used this feature with Django, but it's nice to have anyway.

Have you seen this question from 2011?

Also, other related questions from https://www.google.com/search?q=timesince+filter 

אורי

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CABD5YeGU2_2Bj2F%3DPW-KZVCg-2jSr1TVi9gi%3DWD3MZgjK50syw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

Toby Such
Looks like other people seemed to have the same idea as me for a little fix, seems to me like it should be part of core Django. And yes I do admit its a small thing but if it was actually useful some more people might use it?

On Friday, 22 May 2020 23:21:16 UTC+1, Uri wrote:
Hi,

On Sat, May 23, 2020 at 12:39 AM Toby Such <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="IgXlXTmQAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">to...@...> wrote:
Hi all!

I've been a little frustrated with the timesince filter that comes with default Django. By default it always comes with 2 parts e.g. 4 hours and 3 minutes ago but I would much rather have just the 4 hours. In my own projects I've simply created my own version of the timesince filter and accompanying utils function that powers it that just has the code which adds the second part removed. However I wonder why this isn't standard as I can't think of a single website that displays time since as multiple parts.

I'm proposing adding a 'depth' parameter to the timesince function which would allow the developer to set how many parts to render. At depth one it would be "3 weeks". 2 depth: "3 weeks 2 days" (default behaviour), 3 depth: "3 weeks, 2 days, 4 hours ago" etc.


Actually I think it's a good idea. I don't think I ever used this feature with Django, but it's nice to have anyway.

Have you seen this question from 2011?
<a href="https://stackoverflow.com/questions/6481788/format-of-timesince-filter" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F6481788%2Fformat-of-timesince-filter\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTqpsewLqA8AOdgVCd7ziwP27_ZQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F6481788%2Fformat-of-timesince-filter\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTqpsewLqA8AOdgVCd7ziwP27_ZQ&#39;;return true;">https://stackoverflow.com/questions/6481788/format-of-timesince-filter 

Also, other related questions from <a href="https://www.google.com/search?q=timesince+filter" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/search?q\x3dtimesince+filter&#39;;return true;" onclick="this.href=&#39;https://www.google.com/search?q\x3dtimesince+filter&#39;;return true;">https://www.google.com/search?q=timesince+filter 

אורי

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/75977497-708d-4292-bdce-ea29ec668f65%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

Tobias Kunze-2
On 20-05-22 19:02:02, Toby Such wrote:
>Looks like other people seemed to have the same idea as me for a little
>fix, seems to me like it should be part of core Django. And yes I do admit
>its a small thing but if it was actually useful some more people might use
>it?

Sounds good to me, especially since it's easy to keep the default behaviour
*and* provide the new flexible behaviour. I'd definitely be more willing to
use `timesince` instead of my cobbled up solutions if it had the behaviour you
suggest.

Tobias

--
You received this message because you are subscribed to the Google Groups "Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/20200523090408.n4vaffayujbzspn4%40cordelia.localdomain.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

Adam Johnson-2
+1 

I belive I’ve copy-paste-modified timesince in a past project to implement “depth=1”

On Sat, 23 May 2020 at 10:04, Tobias Kunze <[hidden email]> wrote:
On 20-05-22 19:02:02, Toby Such wrote:
>Looks like other people seemed to have the same idea as me for a little
>fix, seems to me like it should be part of core Django. And yes I do admit
>its a small thing but if it was actually useful some more people might use
>it?

Sounds good to me, especially since it's easy to keep the default behaviour
*and* provide the new flexible behaviour. I'd definitely be more willing to
use `timesince` instead of my cobbled up solutions if it had the behaviour you
suggest.

Tobias

--
You received this message because you are subscribed to the Google Groups "Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/20200523090408.n4vaffayujbzspn4%40cordelia.localdomain.
--
Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM1satQ86fwvxOPg2qyPcsehLQW5JB%3Dp9gxfhzQ8FRT98A%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

Tom Forbes
In reply to this post by Toby Such
I like this idea. However while `depth=1` makes sense for shorter time periods where the difference between `4 hours` and `4 hours and 3 minutes ago` is not required to be displayed, when you get a value that is over a year ago it loses a lot of granularity. The difference between `1 year` and `1 year and 11 months` is much more important.

In this case you probably want `depth=2` (“1 year, 6 months ago”), but only for values over a year ago. Given that, maybe a simple depth flag isn’t enough? I think what we really want here is a `compact=True` flag.

On 22 May 2020, at 16:59, Toby Such <[hidden email]> wrote:

Hi all!

I've been a little frustrated with the timesince filter that comes with default Django. By default it always comes with 2 parts e.g. 4 hours and 3 minutes ago but I would much rather have just the 4 hours. In my own projects I've simply created my own version of the timesince filter and accompanying utils function that powers it that just has the code which adds the second part removed. However I wonder why this isn't standard as I can't think of a single website that displays time since as multiple parts.

I'm proposing adding a 'depth' parameter to the timesince function which would allow the developer to set how many parts to render. At depth one it would be "3 weeks". 2 depth: "3 weeks 2 days" (default behaviour), 3 depth: "3 weeks, 2 days, 4 hours ago" etc.

Does anyone have any thoughts related to this?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/97fbcab8-3f0f-4277-9296-fdcff7fcdab5%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/DCC0D41F-A34F-4FFD-B8CC-39988EBE357E%40tomforb.es.
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

Matthias Kestenholz-7
The same could be said for "1 day, 23 hours" vs "1 day".

The way I implemented it in a former project was to only switch to days after 48 hours, and/or only switch to years after 24 months etc.

Best regards,
Matthias

On Sat, May 23, 2020 at 12:00 PM Tom Forbes <[hidden email]> wrote:
I like this idea. However while `depth=1` makes sense for shorter time periods where the difference between `4 hours` and `4 hours and 3 minutes ago` is not required to be displayed, when you get a value that is over a year ago it loses a lot of granularity. The difference between `1 year` and `1 year and 11 months` is much more important.

In this case you probably want `depth=2` (“1 year, 6 months ago”), but only for values over a year ago. Given that, maybe a simple depth flag isn’t enough? I think what we really want here is a `compact=True` flag.

On 22 May 2020, at 16:59, Toby Such <[hidden email]> wrote:

Hi all!

I've been a little frustrated with the timesince filter that comes with default Django. By default it always comes with 2 parts e.g. 4 hours and 3 minutes ago but I would much rather have just the 4 hours. In my own projects I've simply created my own version of the timesince filter and accompanying utils function that powers it that just has the code which adds the second part removed. However I wonder why this isn't standard as I can't think of a single website that displays time since as multiple parts.

I'm proposing adding a 'depth' parameter to the timesince function which would allow the developer to set how many parts to render. At depth one it would be "3 weeks". 2 depth: "3 weeks 2 days" (default behaviour), 3 depth: "3 weeks, 2 days, 4 hours ago" etc.

Does anyone have any thoughts related to this?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/97fbcab8-3f0f-4277-9296-fdcff7fcdab5%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/DCC0D41F-A34F-4FFD-B8CC-39988EBE357E%40tomforb.es.


--
Feinheit AG - Matthias Kestenholz - Direkt +41 79 444 78 96 - Zentrale +41 555 11 11 41

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CANvPqgBMMeFxkyFtk3D1OeafYRKJq2YfBNOP4odwuTsHsuMEkA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

Mark Bailey
In reply to this post by Toby Such
+1 There are lots of subtleties for how it can behave, and I have written my own when I want specific behaviour.  Other times I want something quick, and I've used timesince, and usually just put up with the fact that it's a bit longer than I want.  Having that control would make it a lot more useful.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/dd59da93-ee9d-4118-8cc0-ee83da5d0fc5%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

Toby Such
In reply to this post by Tom Forbes
I see your point but its tricky to know where you draw the line. Where do months stand? That answer will change depending on the project requirements. I wonder if there is a way of changing how the "time_strings" parameter works to control the depth more granularly but this does put a higher overhead on using the function, and certainly couldn't be used with the html filter.

I think adding the depth parameter increases the usefulness without to large of an overhead and that more specific requirements can carry on being implemented on a case by case basis.

Maybe the logic for calculating the time before formatting could be taken out of the function? That way it would be far easier to implement your own custom versions of the function without copying and pasting, and makes the code more readable too.

On Saturday, 23 May 2020 11:00:33 UTC+1, Tom Forbes wrote:
I like this idea. However while `depth=1` makes sense for shorter time periods where the difference between `4 hours` and `4 hours and 3 minutes ago` is not required to be displayed, when you get a value that is over a year ago it loses a lot of granularity. The difference between `1 year` and `1 year and 11 months` is much more important.

In this case you probably want `depth=2` (“1 year, 6 months ago”), but only for values over a year ago. Given that, maybe a simple depth flag isn’t enough? I think what we really want here is a `compact=True` flag.

On 22 May 2020, at 16:59, Toby Such <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="32gSRmK2AAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">to...@...> wrote:

Hi all!

I've been a little frustrated with the timesince filter that comes with default Django. By default it always comes with 2 parts e.g. 4 hours and 3 minutes ago but I would much rather have just the 4 hours. In my own projects I've simply created my own version of the timesince filter and accompanying utils function that powers it that just has the code which adds the second part removed. However I wonder why this isn't standard as I can't think of a single website that displays time since as multiple parts.

I'm proposing adding a 'depth' parameter to the timesince function which would allow the developer to set how many parts to render. At depth one it would be "3 weeks". 2 depth: "3 weeks 2 days" (default behaviour), 3 depth: "3 weeks, 2 days, 4 hours ago" etc.

Does anyone have any thoughts related to this?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="32gSRmK2AAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-d...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-developers/97fbcab8-3f0f-4277-9296-fdcff7fcdab5%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-developers/97fbcab8-3f0f-4277-9296-fdcff7fcdab5%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-developers/97fbcab8-3f0f-4277-9296-fdcff7fcdab5%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-developers/97fbcab8-3f0f-4277-9296-fdcff7fcdab5%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d5c26ed2-b1f7-499b-b279-6961b978cfc8%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: timesince 'depth' parameter

Claude Paroz
Le samedi 23 mai 2020 16:41:04 UTC+2, Toby Such a écrit :
Maybe the logic for calculating the time before formatting could be taken out of the function? That way it would be far easier to implement your own custom versions of the function without copying and pasting, and makes the code more readable too.

I like that, make it easy to customize, in the same spirit as the Truncator class.
Feel free to ping me regarding the strings stuff and translatability, I worked a bit on that in the past.

Claude

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/9dca9cb1-b2cb-4556-95e3-1f80c425c03f%40googlegroups.com.