#4 ✓resolved
Sven Fuchs

Unify date formats and use js for date formatting

Reported by Sven Fuchs | July 8th, 2008 @ 10:33 PM | in Sprint #2

In the frontend templates use a common date format, add a span with a machine readable format (maybe there's a microformat?) and have JS distance_of_time_in_words beautify them.

Comments and changes to this ticket

  • Sven Fuchs

    Sven Fuchs July 24th, 2008 @ 08:32 PM

    • Milestone changed from First alpha to Release 0.1.0
  • Sven Fuchs

    Sven Fuchs September 22nd, 2008 @ 11:49 AM

    • State changed from “new” to “open”
    • Tag changed from default theme to default theme, i18n
  • Clemens Kofler

    Clemens Kofler September 22nd, 2008 @ 04:47 PM

    • Tag changed from default theme, i18n to default theme, enhancement, i18n

    I suggest using a timestamp (Rails' :number - 20080922164400) or the good old database format (Rails' :db - 2008-09-22 16:44:00) for that. But basically one could use pretty much every format that JS' Date.parse method can parse.

  • Sven Fuchs

    Sven Fuchs September 23rd, 2008 @ 10:27 AM

    • Tag changed from default theme, enhancement, i18n to default theme, enhancement, i18n, uncomplete

    Need to look into applicable microformats

  • Josh H

    Josh H September 25th, 2008 @ 07:52 PM

    Wow, this should be easy, but it's not. The obvious choice would be ISO 8601: 2008-09-25T16:17Z (http://en.wikipedia.org/wiki/ISO.... The problem is that many JS implementations (e.g., mozilla), don't accept it Date.parse.

    According to Mozilla:

    It accepts the IETF standard (RFC 1123 Section 5.2.14 and elsewhere) date syntax: "Mon, 25 Dec 1995 13:30:00 GMT".

    http://developer.mozilla.org/en/...

    Of course this format is useless for a microformat. Date.parse in Mozilla does know how to read a modified version of the ISO 8601 format, e.g. "2008/09/25 16:17".

    Another possibility is to use the ISO 8601 format and to parse it via a library like Datejs (http://www.datejs.com/). This library could come in handy anyway. I did notice some weirdness with how it handles UTC times though. (It seems to treat UTC times as though they are in your current timezone.) Or we could write a simple custom parser.

  • Clemens Kofler

    Clemens Kofler October 5th, 2008 @ 09:35 PM

    • Assigned user changed from “Sven Fuchs” to “Clemens Kofler”
  • Sven Fuchs

    Sven Fuchs October 6th, 2008 @ 03:22 PM

    • Milestone changed from Release 0.1.0 to Sprint #2
  • Clemens Kofler

    Clemens Kofler October 9th, 2008 @ 04:36 PM

    • State changed from “open” to “resolved”

    Implemented.

    I used an implementation similar to the one used in typo where an abbr element encloses a span, e.g.:

    
    <abbr class="datetime" title="2008-10-09T12:00:00+02:00"><span title="2008/10/09">3 hours ago</span></abbr>
    

    The major difference between our implementation and the one in typo is that we don't leave the conversion up to JS. The two main reasons are that this way we don't rely on JS so people with JS turned off will see the same output as the others, and also we don't duplicate logic in JS (typo's JS pretty much copies Rails' distance_of_time_in_words). This should also make it easier to localize once we're on Globalize 2.

    The method is called with a required date/time/datetime parameter:

    
    time_ago_in_words_with_microformat(date)
    

    You can optionally pass an options hash that, at the moment, only supports the :format option which can either be a Symbol for Time#to_s usage or a strftime string:

    
    time_ago_in_words_with_microformat(date, :format => :long)
    time_ago_in_words_with_microformat(date, :format => '%d.%m.%Y')
    

    By default, this uses :standard as the format which is, at the moment, our standard format. Once we've switched to Rails 2.2 we should probably change it to :default seeing that this is the standard key for i18n in Rails.

    We should also consider using my localized_dates plugin then since the standard Rails 2.2 implementation doesn't support direct localization with strftime (at least unless someone has implemented it since I published my plugin).

    At one point, we might also use additional options that can for example be used to modify the abbr and/or span element's HTML options (e.g. class).

    I'll mark this one as resolved for now.

  • Clemens Kofler

    Clemens Kofler October 9th, 2008 @ 04:48 PM

    • State changed from “resolved” to “open”

    Re-opened as some issues arose in IRC. Will do some more work on it.

  • Clemens Kofler

    Clemens Kofler October 10th, 2008 @ 12:35 AM

    • State changed from “open” to “resolved”

    JS is now used for datetime formatting. On pageload, all abbr elements with class="datetime" are parsed and the dates/times are replaced accordingly. That should do the trick for now.

    Will write a wiki entry tomorrow.

  • edwardhenry

    edwardhenry September 15th, 2021 @ 09:18 AM

    Carters Coupon Code is the best way to avail discounts on Carter's store shopping, there are lots of items on which you can avail the discount, amazing offers so visit the store by clicking the button and Save your Pocket now!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<p>Cutting edge cms, blog, wiki, forum ... plattform.</p>

<p>Find the code on <a href="http://github.com/svenfuchs/adva_cms/tree/master">GitHub: adva cms</a></p>

<p>Part of the business application framework <a href="http://www.advabest.org/">adva best</a>.</p>

People watching this ticket

Pages