LocalTimes

Summary: Display RecentChanges and History timestamps in the local timezone of each visitor.
Version: 20201220
Prerequisites: JavaScript
Status: Beta
Maintainer: Petko
Users: +4 (view / edit)
Discussion: LocalTimes-Talk
License: GPL3+

Note: a function similar to this recipe was added to the PmWiki core for 2.3.0, with some changes, outlined below.

Description

When people from different countries use a wiki, it is annoying to see the date/time stamps in a single timezone, different from their own. For a reader in Europe or in New Zealand, having the dates in the Dallas/TX timezone makes it hard to estimate when an edit was actually made.

The recipe rewrites the timestamps in RecentChanges pages and on page histories to show the time in the local timezone of each reader. The original date/time string is moved to a tooltip/title and appears when the mouse cursor is positioned over the link.

If you reopen the RecentChanges page, any new changes since your previous visit on that page will be highlighted in a light-yellow background. Different RecentChanges pages retain their own last-visited-timestamps.

For the changes from the last 24 hours, after the page entry, a "+" plus sign is appended. Clicking on it will fetch and display the authors and summaries of the changes to that page from the last 48 hours.

The recipe is now enabled on pmwiki.org, see for example Site.AllRecentChangesShort.

Core function based on the recipe

A derivative of this recipe was added to the PmWiki core for version 2.3.0, with some differences and improvements.

If you have previously used the recipe, you can either continue using it, or disable it and enable the core function.

To enable the core function, please first disable the old recipe if you used it, and add to config.php:

  • $EnableLocalTimes = 2; # Enable long local times, in the visitor's timezone:
    • the full date+time are shown, as in MM/DD/YYYY HH:MM:SS (or DD/MM/YYYY HH:MM:SS);
    • the server's time format ($TimeFmt) appears in a tooltip title when the mouse cursor is over the localized format.
  • $EnableLocalTimes = 1; # Enable compact (short) local times, in the visitor's timezone:
    • if within 24 hours, only the time HH:MM is shown;
    • if within 11 months, only the month and date MM/DD (or DD/MM) are shown;
    • if more than 11 months, the month, date and year MM/DD/YYYY (or DD/MM/YYYY) are shown.
    • The full localized format appears in a tooltip title when the mouse cursor is over the short format.

Enabling $EnableLocalTimes will also make user signatures with 4 tildes to produce a time format that can be localized in the reader's timezone.

By default the "plus" button pulls the page history from 3 days (72 hours), plus one additional edit. To change this, set the number of days in $EnableLocalTimes:

Like the recipe, the core function rewrites the dates and times to the visitor's time zone, both in RecentChanges, and in page histories (?action=diff).

Differences between the core function and the recipe

In addition to be easier to update and maintained, the core version has the following differences:

  • It does not modify the $RecentChangesFmt array; in fact, it relies on a new core variable $CurrentLocalTime which is now used by default in the $RecentChangesFmt array. Consequently, the *RecentChanges pages will have a different, and much simpler/shorter wiki text.
  • It is possible to have a short or a long format for the dates and times.
  • The core function detects whether the visitor's local date format is "Day/Month" (like in Europe) or "Month/Day" (like in the US), and will print that disposition.
  • In RecentChanges, it will move the date-time at the beginning of the line; this aligns the times, and also the page names like in columns, easier to scan the list looking either for pages, or for dates/times.
  • The number of days that allow pulling the history (the "plus" button) is set to 3 days instead of 2.
  • When the "plus" button is clicked, it will pull the page history from the last 3 days, plus one earlier edit, regardless of the time of the earlier edit. This is always useful when monitoring changes.
  • The pulled page history also shows the dates/times aligned with the date/time above.
  • The times of visits to recent changes pages are stored in a single LocalStorage entry, rather than one for each page. (These are used to highlight newly added lines since you last opened the RecentChanges page.)
  • Some of the CSS has different class names, .rcnew and .rcreload instead of .ltnew and .ltreload.

The new core function should recognize old recent changes from the recipe and integrate those in the new format. If you never used the recipe, only pages modified after the 2.3.0 upgrade will have localized times in RecentChanges.

Similarly to the recipe, the core function has built-in the functionality "Better RecentChanges" from TrackChanges, and you cannot have the latter and $EnableLocalTimes at the same time. If you previously used TrackChanges, please remove its installation code from config.php.

Installation (recipe only)

Place the file localtimes.phpΔ into your pmwiki/cookbook directory.

Copy localtimes.js to your pmwiki/pub directory. Add near the end of local/config.php such code:

  include_once("$FarmD/cookbook/localtimes.php");

Note that the installation code changed in version 20150906.

Note that LocalTimes has built-in the functionality of the recipe "Better RecentChanges" from TrackChanges, but you cannot have the two recipes at the same time. If you previously used TrackChanges, please remove its installation code from config.php.

Configuration

You can configure the duration of the fetched page history.

In config.php, set

  $LastTimesHours = 24; // 24 hours; default is 48

To disable the "+" plus button and the fetching of recent history, set this variable to 0:

  $LastTimesHours = 0;

To change the highlight color for new/unseen changes, add this to pub/css/local.css:

  .ltnew{ background-color: orange; }

Usage

In a RecentChanges page, or in a Page History, you will see the timestamps in the local time zone of your operating system.

Note that in RecentChanges, only pages modified after the installation of the recipe will have their timestamps localized.

Click on the "+" plus sign after a page entry to see its recent history.

Notes

The visitors' browsers need to have JavaScript enabled or they will see the date/time in the timezone of the server.

The recipe expects the RecentChanges format to be in standard bulleted or numbered lists. Other formats are not supported, eg. Tables may produce unexpected results and errors.

If the skin has a <div id="wikitext"> block, the recipe will only scan links in it and will work faster. If the page heading has the class "pagetitle", the recipe will append the current local time to the heading in light gray. (The default "pmwiki" and "pmwiki-responsive" skins and many other skins contain these elements.)

Change log / Release notes

  • 20201220 - middle-click on the highlighted entries (except on the links) will now clear the background.
  • 20191117 - add a CSS class "ltreload" to the 'time' reload text, used by PendingChanges.
  • 20190818 - the browser will now save the last timestamp into localStorage, and will highlight entries that were added or modified since that last timestamp.
  • 20160515 - click on the pagetitle timestamp will now reload the page.
  • 20150906 - fix "+" plus signs, no longer displayed if no more edits in 48 hours (takes effect up to 48 hours after upgrade). No more need to edit localtimes.js. Added styles for the "+" signs. Please note that the installation code changed.
  • 20150830a - silently ignore missing elements in skins, without generating JavaScript errors.
  • 20150830 - bug fix: escape special characters in the fetched page summaries.
  • 20150804 - add Ajax fetching of recent page history.
  • 20150621 - append time to pagetitle heading.
  • 20121231 - minor refactoring, changes from less than 24 hours show just the time.
  • 20121109 - changed today's changes to show just the time.
  • 20110607 - fix tooltip titles in Internet Explorer.
  • 20110605 - first public release, ready to be tested.

See also

Contributors

  • Petko is author and maintainer of this recipe (5ko [snail] 5ko [period] fr).
  • If this recipe helps you or saves you time, you can help support its continued development by .

Comments

See discussion at LocalTimes-Talk

User notes +4: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.