Relative timestamps

This module aims to provide Facebook-like timestamps for Date fields from the Date module. As the supplied timestamp gets older, less accurate information will be shown.

The module differs from core's format_interval function in several aspects:

  • e.g. if a timestamp is 1 hour 45 minutes older than the current time, format_interval (with granularity set to 1) will return 1 hour. This module returns the more appropriate 2 hours.
    e.g.2: 1 day + 3 hours ago and 1 day + 16 hours ago both return yesterday.
  • Future dates/timestamps are also supported. Instead of 'Time ago' the module will display 'in Time'.
  • Support for the strings tomorrow and yesterday so they don't get any prefix ('in') of suffix ('ago').
  • Date fields featuring start and end dates are supported. Core's format_interval only displays the start date. Each case (past + past, past + future, ....) will get it's own constructed string.

Project page: http://drupal.org/sandbox/Propaganistas/1920568
Git: git clone --recursive --branch 7.x-1.0 http://git.drupal.org/sandbox/Propaganistas/1920568.git relative_timestamps
Earlier contributions: patch commits to ManyMail, many issue openings of bug reports.

Review bonus program:
http://drupal.org/node/1923524#comment-7094154
http://drupal.org/node/1924776#comment-7099088
http://drupal.org/node/1924326#comment-7099144
http://drupal.org/node/1912952#comment-7099228
http://drupal.org/node/1927104#comment-7108450
http://drupal.org/node/1825062#comment-7108518

Comments

abhijeetkalsi’s picture

Hi,

first of all there are quite a few issues to sort out such as indentation, whitespace.

You can find them all here:
http://ventral.org/pareview/httpgitdrupalorgsandboxpropaganistas1920568git

Here you can check source code whether it meets drupal coding standards or not, and advise you what to change in your code. You can repeat review after your commits, and can fix those errors.

# Your first branch name can be 7.x-1.0, version comes after module released.
# Move your code repository to custom branch like 7.x-1.x, then delete master branch.

Anonymous’s picture

Hi AbhijeetKalsi

Thanks for your guidelines.

All warnings and errors have been fixed. PAReview now returns an empty report!

Please re-review the module.

Anonymous’s picture

Issue summary: View changes

Enter project name as title

jbloomfield’s picture

No errors through PARreview.

Nicely written module. I didn't find any major issues. It does what it says on the tin ;)

jbloomfield’s picture

Issue summary: View changes

+ review bonus program

Anonymous’s picture

Issue summary: View changes

Review bonus program nr2

Anonymous’s picture

Issue tags: +PAreview: review bonus

Tagging

Anonymous’s picture

Issue summary: View changes

Review bonus program nr3

DanaRoseRoss’s picture

I hate, hate, HATE coding this manually all the time, so thank you for a cool module. I've got a couple notes for you. Nothing too bad, but some things to think about:

Not sure if you should refer to this style of date as "Facebook style" in the .info file. Not everyone uses Facebook, and Facebook is going to fall out of style at some point and then that association does nothing for you. The rest of your description is fine without it.

In relative_timestamps_format(), you're define()-ing some values with pretty generic names (SECOND, MINUTE), and there's a chance those constants could collide with some other module or theme's definitions. Worse, someone else's code might be using those constants to hold strings instead of numbers, which would break your calculations. Instead of using define() there, how about switching to static variables? That way, your definitions still aren't going to get re-defined every time the function is called, but they're limited to the function's scope. For example:

if (!defined("MONTH")) {
    define("MONTH", 30 * DAY);
  }

should become

static $MONTH;
if(!isset($MONTH)) {
  $MONTH = 30 * $DAY;
}
DanaRoseRoss’s picture

Status: Needs review » Needs work
Anonymous’s picture

Status: Needs work » Needs review

Hi Dave

Thanks for the great suggestions. They definitely make sense so I incorporated them right away.

Setting this back to needs review.

klausi’s picture

Assigned: Unassigned » patrickd
Status: Needs review » Reviewed & tested by the community
Issue tags: -PAreview: review bonus

Thank you for your reviews. When finishing your review comment also set the issue status either to "needs work" (you found some problems with the project) or "reviewed & tested by the community" (you found no major flaws).

manual review:

  1. relative_timestamps.info: why is there no dependency to the date module?
  2. relative_timestamps_field_formatter_view(): the switch() is not necessary since you provide only one case with that callback anyway?
  3. "return $delta >= 0 ? $timestr . ' ' . t('ago') : t('in') . ' ' . $timestr;": do not concatenate variables to t() calls, use placeholders with t() instead. Same elsewhere.
  4. I thought that you maybe could use hook_date_format_types() and friends to make this available to any date displayed in Drupal, but format_date() only works with PHP date patterns and does not support callbacks. Sad story.

But otherwise looks RTBC to me. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

Assigning to patrickd as he might have time to take a final look at this.

Anonymous’s picture

Issue summary: View changes

Review bonus program nr.4

Anonymous’s picture

Issue summary: View changes

extra PAReview

Anonymous’s picture

Issue tags: +PAreview: review bonus

Thanks klausi for your review. Issues nr. 1 and 3 have been fixed.

Concerning nr. 2: the switch() is quite necessary actually, as this is the *first* and *only* check to whatever field display format has been chosen in the UI. The code in hook_field_formatter_view() has been greatly derived from the Date module.

Concerning nr. 4: I did explore the hook system hoping to find something pluggable to format for example the node posting time, but as you stated concisely: it turned out to be indeed a sad story.

Some more reviews done so re-tagging this.

patrickd’s picture

Status: Reviewed & tested by the community » Fixed

I'm a fan of nicely structured project pages with usage examples and screenshots!
But I'm not a fan of yours, yet ;-)

"relative_timestamps_worker" is an odd function name for what it does.. maybe "relative_timestamps_generate"?

/**
  * @file
  * The basic .module file <--------- This comment is not helpful!
  */

but that's just nitpick..

I also quickly tested it on simplytest.me and everything seemed to work fine.

A small, solid module, ready to go..

Thanks for your contribution!

I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

Anonymous’s picture

Thanks patrickd for your final suggestions!

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

extra PAReview