PrettyDate provides a field formatter for Date types that makes use of John Resig's Prettydate JS. This allows for client side date formatting like: 5 seconds ago.. 10 seconds ago.. 2 minutes ago.. The times update every few seconds so if the user stays on one page (ajax safe using behaviors) the times update accordingly. It also allows the use of other Date Formatters incase the JS does not do anything to the date (date in future or too far in past or JS off).

Example screenshot: http://cl.ly/3m3G1i2d0E2I1q143N1C

Project Page: http://drupal.org/sandbox/twohlix/1238634

Version control: git clone --branch master twohlix@git.drupal.org:sandbox/twohlix/1238634.git prettydate

This is for Drupal 7.x

Comments

Everett Zufelt’s picture

Component: module » theme
Status: Needs review » Needs work

Nice code.

1. In the .info you should likely use the package that Date is using, no need to create a package for this one module.

2. You should likely not use scripts[] = js/prettydate.js
in the .info (this attachs the script to every page). Consider using the #attached property in the hook_field_formatter_view() render array.

3. The comment on the js file is:

* Licensed under the MIT license.
* Modified 2011 Charles Smith (phase2technology.com)
*/

Only GPL 2.0 code can be stored in the d.o repository. Can this be licensed under GPL2, or can you remove the code and give a link to where it can be downloaded from the project page?

4. Some of your comments are like " * hook_field_formatter_settings_form()" Standard implementation is " * Implements hook_field_formatter_settings_form()."

5. Some functions missing doc block, like function prettydate_field_formatter_settings_summary($field, $instance, $view_mode) {

6. You use " }else{
" we usually use:

if (condition) {
  ...
}
else {
  ...
}
twohlix’s picture

Thanks for the stuff to fix. I'll look into re-licensing (unlikely, unless i write the js from scratch) or hosting the code somewhere else.
Didn't know about the #attached property, thanks.

Everett Zufelt’s picture

Component: theme » module

Ooops, switching category back.

Everett Zufelt’s picture

@twohlix you're welcome.

FYI, MIT and GPL 2.0 are compatible licenses, so the author may be willing to release the code under a dual MIT / GPL 2.0 license, this happens quite frequently. It doesn't hurt to ask.

twohlix’s picture

The author agreed to relicense his code to both MIT + GPL. Pushed the changes to that. I just have to catch up on the other changes.

twohlix’s picture

Status: Needs work » Needs review

All right, all the changes suggested were made. Thanks EverettZ.

klausi’s picture

Status: Needs review » Needs work
  • It appears you are working in the "master" branch in git. You should really be working in a version specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git.
  • README should be README.txt
  • lines in README.txt should not exceed 80 characters, see also guidelines for in-project documentation
  • Although you asked the author: 3rd party code is not generally allowed on Drupal.org and should be deleted. This policy is described in the getting involved handbook. The Libraries API module is a recommended method for adding 3rd party dependencies without directly including the code on Drupal.org.
  • "@param array $dates An array of dates that are to be converted": the parameter description should be on a new line, see http://drupal.org/node/1354#functions
  • "//setup subformatter": all comments should start capitalized and end with a ".". Ans there should be a space after "//".
  • "else{": there should be a space after "else". Run coder to check your code style: http://drupal.org/project/coder
  • "Implements hook_field_formatter_info()": There should be a "." at the end
  • "if ( strcmp($date['value2'], $date['value']) != 0 ) {": there should be no space after "(" and before ")". Also elsewhere.
twohlix’s picture

klausi, I'll make those changes. Thanks for the feedback.

Although you asked the author: 3rd party code is not generally allowed on Drupal.org and should be deleted. This policy is described in the getting involved handbook. The Libraries API module is a recommended method for adding 3rd party dependencies without directly including the code on Drupal.org.

The library has been modified, one modification changes the behavior of the library and another modification adds Drupal.behaviors support. I believe those meet the Exception requirements.

misc’s picture

@twohlix has been contacted to ask if the application is abandoned.

After ten weeks with a status of needs work: the applicant may be contacted by a reviewer to determine whether the application was indeed abandoned. The action taken by the reviewer should be documented in the project application issue.

http://drupal.org/node/894256

twohlix’s picture

Nope, not abandoned, just been sidetracked with some site-builds / other-work.

twohlix’s picture

Status: Needs work » Needs review

Made changes suggested in #8 by Klausi. Finally found some time to do it. Thanks for the patience.

twohlix’s picture

Priority: Normal » Major

Raising priority because of no review for 2+ weeks since status change (http://drupal.org/node/539608)

klausi’s picture

The response time for a review is now approaching 5 weeks. Get a review bonus and we will come back to your application sooner.

geertvd’s picture

I think the correct way to use behaviors in d7 is like this.

(function ($) {
  Drupal.behaviors.prettydate = {
    attach: function (context, settings) {
      $('.prettydate').prettyDate();
      setInterval(function(){ $('.prettydate').prettyDate(); }, 5000);
    }
  }
})(jQuery);

You should probably think about timezone conversions here also, and your module only seems to be working on dates not older then 1 day ago. Could you make this work on older dates also?
Also something for dates in the future would be nice.

Also you have some more coding issues
http://ventral.org/pareview/httpgitdrupalorgsandboxtwohlix1238634git

geertvd’s picture

Status: Needs review » Needs work
klausi’s picture

Status: Needs work » Closed (won't fix)

Closing due to lack of activity. Feel free to reopen if you are still working on this application.