(Minor) problem with dates in plain text, and solution.

(Minor) problem with dates in plain text, and solution.

by Paul Vaughan -
Number of replies: 0

I'm working on an extension of Moodle's Notes system, mainly the ability to export them, initially as plain text.

I've noticed when exporting date information as plain text, there are extraneous spaces, which obviously don't appear in HTML due to multiple spaces collapsing. Below is an example of the extra spaces (hopefully this will appear correctly):

User test test by me - Monday, 11 January 2010, 02:57 PM (created: Monday, 11 January 2010, 11:17 AM)

The extra spaces are created before the day's number (11) and I believe is caused by the 'fixday' routines in the userdate function in moodlelib.php.

I have modified the function and am posting the diff here for testing. (It doesn't seem like a big enough issue for the tracker yet.) I've tested on a number of notes and everything seems okay.

diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 8502f4d..1cafcdd 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -1253,7 +1253,7 @@ function userdate($date, $format='', $timezone=99, $fixday = true) {
 if (abs($timezone) > 13) { /// Server time
 if ($fixday) {
 $datestring = strftime($formatnoday, $date);
- $daystring = str_replace(' 0', '', strftime(' %d', $date));
+ $daystring = str_replace(' 0', '', strftime('%d', $date));
 $datestring = str_replace('DD', $daystring, $datestring);
 } else {
 $datestring = strftime($format, $date);
@@ -1262,7 +1262,7 @@ function userdate($date, $format='', $timezone=99, $fixday = true) {
 $date += (int)($timezone * 3600);
 if ($fixday) {
 $datestring = gmstrftime($formatnoday, $date);
- $daystring = str_replace(' 0', '', gmstrftime(' %d', $date));
+ $daystring = str_replace(' 0', '', gmstrftime('%d', $date));
 $datestring = str_replace('DD', $daystring, $datestring);
 } else {
 $datestring = gmstrftime($format, $date);

(Edit to attach diff file, as the on-screen version isn't entirely right.)
Average of ratings: -