Issue Details (XML | Word | Printable)

Key: MDL-7645
Type: Bug Bug
Status: Reopened Reopened
Priority: Major Major
Assignee: Petr Skoda
Reporter: Paulo Matos
Votes: 0
Watchers: 1
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Problem with time representation in multilang environment with some locales

Created: 22/Nov/06 07:15 AM   Updated: 01/May/08 03:28 AM
Return to search
Component/s: Languages
Affects Version/s: 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4
Fix Version/s: None

File Attachments: 1. Text File MDL-7645_userdate_in_moodlelib.patch (0.7 kB)
2. Text File moodle-1.8.4plus-MDL7645_userdate_in_moodlelib.patch (0.8 kB)

Environment: All

Participants: David Wojak, Eloy Lafuente (stronk7), Juan Segarra Montesinos, Paulo Matos and Petr Skoda
Security Level: None
Resolved date: 23/Mar/07
Affected Branches: MOODLE_18_STABLE


 Description  « Hide
The problem:
php's strftime uses locale information and %p (ante-meridian, post-meridian modifier) is setted to null in many locales,
which is partially correct because it is not used on that locale.

If you have a multilingual environment you still have one locale, in my case portuguese and we use 24h format, however
there are pages written in english where the time representation uses %p, thus the effect is that time is represented in a
12-hour format and with a blank for %p.

Solution:
Set a default if %p is empty.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Paulo Matos added a comment - 30/Jan/07 10:23 PM
Verified against 1.6.4+, patch will apply correctly!

Paulo Matos added a comment - 22/Mar/07 02:22 AM
Simple fix, can't this be merged?

Petr Skoda added a comment - 22/Mar/07 04:22 AM
I do not think this is correct: "If you have a multilingual environment you still have one locale,..."

The setting for system locale should be now blank, instead locale for language is now defined in each language pack - you have different locale for each language.


Paulo Matos added a comment - 22/Mar/07 11:34 PM
Hi Petr!
Even with locales defined on each language pack, there are a lot of them that are untouched on time entries, and %p is present,
this simple fix would avoid %p simply being translated to null string.
Paulo

Petr Skoda added a comment - 22/Mar/07 11:49 PM
I do not understand: ... untouched on time entries
does it mean there is a problem with definition in some locales?

Could you give me some examples, so that I can replicate the problem?


Paulo Matos added a comment - 23/Mar/07 12:23 AM
I was referring to the definitions of time related strings on moodle language packs, like on lang/../moodle.php:

$string['strftimedate'] = '%%d %%B %%Y';
$string['strftimedateshort'] = '%%d %%B';
$string['strftimedatetime'] = '%%d %%B %%Y, %%H:%%M';
$string['strftimedaydate'] = '%%A, %%d %%B %%Y';
$string['strftimedaydatetime'] = '%%A, %%d %%B %%Y, %%H:%%M';
$string['strftimedayshort'] = '%%A, %%d %%B';
$string['strftimedaytime'] = '%%a, %%H:%%M';
$string['strftimemonthyear'] = '%%B %%Y';
$string['strftimerecent'] = '%%d %%b, %%H:%%M';
$string['strftimerecentfull'] = '%%a, %%d %%b %%Y, %%H:%%M';
$string['strftimetime'] = '%%I:%%M %%p';

So, if the portuguese language pack had (and actually it has) $string['strftimetime'] was defined as above, it will produce this results:
06h30 --> 6:30
18h30 --> 6:30
because on pt locale (at operating system level) %p is set to a blank (and that's not the only case).

You should probably say, so why not fix all language packs? That's one approach, this one will prevent the scenario I stated before.
So, with the fix, the results would be:
06h30 --> 6:30 a.m.
18h30 --> 6:30 p.m
Which of course, for us wil be incorrect since we use the 24h-format, nevetheless we will be able to distinguish the times and noticed the error so we can easly identify and correct language packs.

Is it clear now?

Regards,
Paulo


Petr Skoda added a comment - 23/Mar/07 12:50 AM
Now I understand, but I do not like this kind of workarounds - I prefer to fix language packs and keep the code simple so that everybody understands it.

If you tell me what language packs are broken I will fix them.


Paulo Matos added a comment - 23/Mar/07 01:41 AM
That's the problem! I only can tell you about portuguese: all time representation must use %H and %M instead of %I %M and %p.
Then, the locale is OS dependent, so you can have %p blank or not...

Eloy Lafuente (stronk7) added a comment - 23/Mar/07 02:58 AM
test-closing.

Petr Skoda added a comment - 23/Mar/07 03:28 AM
thanks Eloy tracker was timing out for me

I have fixed the pt locale in lang cvs and reviewed all others that use %%p, seems pt was the only one with this problem.

Thanks for the report and cooperation!


Paulo Matos added a comment - 27/Feb/08 02:49 AM
Seems that one has missed
Looking at pt lang pack messagge.php:

<?PHP // $Id: message.php,v 1.6 2008/01/15 20:31:19 villate Exp $
// message.php - created with Moodle 2.0 dev (2007101506)
(... line 64 ...)
$string['strftimedaydatetime'] = '%%A, %%d %%B %%Y, %%I:%%M %%p';
(...)

where it should be:
$string['strftimedaydatetime'] = '%%A, %%d %%B %%Y, %%H:%%M';

Cheers,

Paulo Matos


Paulo Matos added a comment - 11/Mar/08 04:28 AM
This was an old issue and I did not recalled all the minor details on my previous comments.
The problem is related with the locale set on global settings not the language settings of the user.

Using a locale setting as pt_PT on global settings %p is set to blank. An user that has defined it's own language as English,
will have %p on date format, so it will loose AM/PM information, since on system locale %p is letf to blank.

The inital patch still makes sense, the scope of this problem isnt strict for Portuguese language nor language pack.

Regards,

Paulo


Paulo Matos added a comment - 11/Mar/08 04:32 AM
Can't confirm which systems/locales have %p set to blank but would dare to say that portuguese will not be alone on this quest.

David Wojak added a comment - 02/Apr/08 09:55 PM
That's right! We have the same problem with de_DE.UTF8.

So what's to do? Setting the locale to english before printing the time and then set it back to the global settings?


David Wojak added a comment - 02/Apr/08 10:08 PM
Pardon - didn't see the patch.

Paulo Matos added a comment - 02/Apr/08 10:25 PM
Here is the patch for the 1.8.x branch.

Paulo Matos


Petr Skoda added a comment - 02/Apr/08 10:52 PM
Please contact the lang pack maintainers to fix the problems there.

Petr Skoda added a comment - 02/Apr/08 10:56 PM
fixed de and pt packs in cvs

Paulo Matos added a comment - 18/Apr/08 12:50 AM
Petr!
Seems to be a miscommunication here! Although there were some minor problems with lang packs,
THE ISSUE IS NOT WITH LANG PACKS!

If (locale is pt_PT or de_DE) AND your user has English language

it will use English language pack, and

$string['strftimetime'] = '%%I:%%M %%p';

HOWEVER %p is set to null on locale.

That's what this patch addresses.


Petr Skoda added a comment - 18/Apr/08 02:43 AM
I do not understand - user selects language and locale is specified in that language pack, where is the problem?

There is not a "single locale" anymore, this was changed around Moodle 1.5.x


Juan Segarra Montesinos added a comment - 29/Apr/08 09:45 PM
Hi Petr

Problem is that there are places where date/time format isn't taken directly from lang packs. I've "grepped" the code (1.8.4) and found the following:

calendar/lib.php:define ('CALENDAR_TF_12', '%I:%M %p');

files/index.php: $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
files/index.php: $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");

lib/editor/htmlarea/coursefiles.php: $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
lib/editor/htmlarea/coursefiles.php: $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");

mod/survey/download.php: $myxls->write_string($row,$col++, userdate($results["$user"]["time"], "%d-%b-%Y %I:%M:%S %p") );
mod/survey/download.php: $myxls->write_string($row,$col++, userdate($results["$user"]["time"], "%d-%b-%Y %I:%M:%S %p") );
mod/survey/download.php: echo userdate($results["$user"]["time"], "%d-%b-%Y %I:%M:%S %p")."\t";

Paulo's patch is one approach, but perhaps what should be done here is to take the format strings above and substitute by one of those strftimeXXX lang strings.

Thanks in advance


Petr Skoda added a comment - 30/Apr/08 12:41 AM
Oh, these should be definitely fixed, big thanks for pointing this out!

Paulo Matos added a comment - 30/Apr/08 08:51 PM
Ok in fact you are right Petr, there is a locale configuration per lang pack!
Namely:
$string['locale']= ...

However, I could not find (on 1.8.4+) any occurence of get_string('locale') in any part of the moodle source,
which means that this definition is not used at all. Please correct me if I'm wrong.

Steps to reproduce the problem:

Sometime after noon
1) Go to: Site Administration -> Language -> Language settings
and set:

lang = pt
langmenu : checked
langlist = pt_utf8,en_utf8
locale = pt_PT.UTF8

2) Go to your profile and choose English as "Preferred language"
3) Logout and login
4) Go to your profile (by clicking on your name on the right upper/lower corner of the screen)
Check the time of your Last access

You'll be able to see that ante/post-meridian information is not there.


Petr Skoda added a comment - 30/Apr/08 09:12 PM
Do not set the $CFG->locale !

"Choose a sitewide locale - this will override the format and language of dates for all language packs (though names of days in calendar are not affected). You need to have this locale data installed on your operating system (eg for linux en_US.UTF-8 or es_ES.UTF-8). In most cases this field should be left BLANK."

Lang pack locale is used, see moodle_setlocale()


Paulo Matos added a comment - 30/Apr/08 10:04 PM
Ok. I got it now! However, since locale names are OS dependent, the problem persist, for example the linux equivalent of pt_PT on Windows XP is prt_ptg, so you'll have to set $CFG->locale since it differs from the one defined on lang pack.

Petr Skoda added a comment - 01/May/08 02:05 AM
hmm, we have independent locales for *nix and windows

Paulo Matos added a comment - 01/May/08 03:28 AM
Ok, you'll cover a lot of cases then, but not all .
I rest my case, there's no point to continue this discussion.