Week days and months naming problem with localisation

Bug #684907 reported by NIXin
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Eventum
Fix Released
Low
Elan Ruusamäe

Bug Description

Hi,

I'd like to report a small bug with localisation of week days and months. I use Eventum in Polish, and it works nicely, everything is sent in UTF-8 but the date fails. Thus if the three leter "code" for date contains Polish diacritics, it will fail and display some unknown characters instead. This behavior is the same both in Eventum 2.2 and 2.3. Here's an example (HTML source), this is the Creation date for a ticket:

<b>Data utworzenia:</b>
</td>
<td bgcolor="#DDDDDD" class="default">
pi�, 03 gru 2010, 17:10:11 CET
</td>

Now Friday in Polish is "piątek", but the proper abbreviation, according to a Polish dictionary is "pt.", not "pią". Here's what I think happends: Eventum just cuts the three bytes (chars) from the full day name, and since the third letter is a Unicode letter, thus is comprised of two bytes. Eventum only takes the first byte of the two-byte letter ą and that in the end is displayed as �. A similar problem is observed with month names - October is "październik", so the third letter would be badly displayed again.
Switching to just different style formatting would be brilliant - so having full weekday like Friday 2010-12-03 instead. Is there an easy way to do this?

Thanks a lot!
Cheers,
NIXin

Revision history for this message
Elan Ruusamäe (glen666) wrote :

that's a know bug, the fix is to rework date handling classes, which is huge work

because current version is idiot, it just copies first 3 octal bytes to get short date, even if pear provides function for short dates.

easy way is to use english ui :)

Changed in eventum:
status: New → Confirmed
Revision history for this message
NIXin (nixin) wrote :

Updating to latest alpha of Pear Date-1.5.0a1:
http://pear.php.net/package/Date/download/
Solves this, but it's not really a great solution - would be better just to use PHP5's native date() formatting in the class.date.php.
It's not that much work, I might create a branch and do it later.

Revision history for this message
Elan Ruusamäe (glen666) wrote :

Date-1.5.0 is not compatible with Eventum, at least at some point i tested, maybe it's better now.

anyway the problem I noticed was that all timezones went -2 hours for me (I live in GMT+2)

Revision history for this message
NIXin (nixin) wrote :

I don't have any problems with Date-1.5.0 so far and it was working well with the timezones conversion (I am GMT+1).

Anyway, it's no longer developed cause there's no need for it, strftime replaces the ->format function and date_default_timezone_set handles the UTC conversion. It should be depracated and removed from Eventum altogether.

Here's a little workaround, just got getFormattedDate function:

    function getFormattedDate($ts, $timezone = FALSE)
    {
        if ($timezone === FALSE) {
            $timezone = Date_API::getPreferredTimezone();
        }
        // now convert to another timezone and return the date
        date_default_timezone_set('UTC');
        $date = strtotime($ts);
        if($timezone == 'CEST') $timezone = 'Europe/Warsaw';
        date_default_timezone_set($timezone);
        return strftime("%a, %d %b %Y, %H:%M:%S %Z", $date);
    }

It would be best to send $ts already in unix time format, cause then there's no need for this charade with setting UTC and proper timezone after.

The problem is, Eventum allows the $timezone to be in loads of different formats, instead of just allowing one from the standard list of timezones available in PHP:
http://www.php.net/manual/en/timezones.php

That's why I have to manually change if($timezone == 'CEST') $timezone = 'Europe/Warsaw'.

It should be a simple fix nontheless for an update. Just update every user's timezone to a compliant one and enforce options in the user configuration.

Revision history for this message
NIXin (nixin) wrote :

Here's a proper, working solution, but requires PHP 5 >= 5.3.0.
Replace function getFormattedDate to this:

    function getFormattedDate($ts, $timezone = FALSE)
    {
        if ($timezone === FALSE) {
            $timezone = Date_API::getPreferredTimezone();
        }
        $dateTimeZone = new DateTimeZone($timezone);
        $dateTime = new DateTime($ts, new DateTimeZone('GMT'));
        $dateTime->setTimeZone($dateTimeZone);
        date_default_timezone_set(timezone_name_get($dateTimeZone));
        return strftime("%A, %d %b %Y, %H:%M:%S %Z", $dateTime->getTimestamp());
    }

One comment on this -
This way would be ideal, but there's no support for locales in the DateTime object (so I have to use strftime):
        $dateTimeZone = new DateTimeZone($timezone);
        $dateTime = new DateTime($ts, new DateTimeZone('GMT'));
        $dateTime->setTimeZone($dateTimeZone);
        return $dateTime->format("l, d M Y, H:i:s T");

Cheers

Revision history for this message
NIXin (nixin) wrote :

Forgot to mention, this also works with custom names for timezones, like Eventum's CEST or these ones mentioned here:
http://us.php.net/manual/en/timezones.others.php
So no need to hack around.

Cheers
NIXin

Revision history for this message
NIXin (nixin) wrote :

One more update. Sometimes the $ts parameter sent was already in timestamp format, so there was a PHP fatal error.
Here's a final fix, hopefully this is that last one needed. Inside the function, after the $timezone check:

        (is_int($ts)) ? ($dateTime = new DateTime("@$ts", new DateTimeZone('GMT'))) : ($dateTime = new DateTime($ts, new DateTimeZone('GMT')));
        $dateTimeZone = new DateTimeZone($timezone);
        $dateTime->setTimeZone($dateTimeZone);
        date_default_timezone_set(timezone_name_get($dateTimeZone));
        return strftime("%a, %d %b %Y, %H:%M:%S (%Z)", $dateTime->getTimestamp());

Revision history for this message
NIXin (nixin) wrote :
Revision history for this message
Elan Ruusamäe (glen666) wrote :

Sorry, but not going to accept the PHP 5.3 as minimum requirement, not at this time.

Revision history for this message
NIXin (nixin) wrote :

Okay, no problem. To be fair, I think only $dateTime->getTimestamp() requires >=5.3, so it would be possible to work around that some more and it should work >=5.2. If you like, I'll give it a try, but I don't know if >=5.2 still would be acceptable for you.

Anyway, if anybody's interested and is already running PHP 5.3, my branch is a bit more edgy:
1. switched to innoDB (temporarily disabling full-text searching, will add this by sphinx in future)
2. added the above fix for dates
3. and rewritten more functions for dates (now showing proper list of timezones when configuring the user)
4. some other small fixes like setting static memory_limit which was sometimes not enough

Soon more performance fixes, such as changing the MySQL row counting scheme to a quicker one, cause the current one with 700k issues was taking 8 seconds to complete, so for now on our production server we just put a static number there and the list.php loads 3-5 times faster than before.

http://bazaar.launchpad.net/~bart8472/eventum/hugedb_edge/

Revision history for this message
Elan Ruusamäe (glen666) wrote :

PHP 5.2.x is ok

Elan Ruusamäe (glen666)
Changed in eventum:
milestone: none → 2.3.4
Elan Ruusamäe (glen666)
Changed in eventum:
milestone: 2.3.4 → 2.4
Revision history for this message
Elan Ruusamäe (glen666) wrote :

looks like user's account is no longer there, therefore no branch either
http://launchpad.net/~bart8472

Revision history for this message
NIXin (nixin) wrote :

Hey Elan, I'm here, just changed my username.
My branch is on GitHub now, as a fork of the eventum there.
Take a look at my commits, I address a few issues, including this one:
https://github.com/niieani/eventum-es/commits/master

There's things like date helper, using innoDB instead of MyISAM, some bug fixes, updated GetText, better font (with free license), using proper PHP locales and so on. Would be happy if you'll integrate most of those into the master.

Cheers,
NIXin aka bArT8472

Revision history for this message
Elan Ruusamäe (glen666) wrote :

so, i did not know that and i reworked based on initial info from this ticket whole date helper class and pear Date out of codebase

https://github.com/eventum/eventum/pull/5

will check your branch too, but if you can you can probably help testing this!

Revision history for this message
Elan Ruusamäe (glen666) wrote :

So, we switched to use DateTime, but there's problem now, DateTime format function is not localized at all!

http://php.net/manual/en/datetime.format.php: "This method does not use locales. All output is in English."

Revision history for this message
Elan Ruusamäe (glen666) wrote :

looks there are two choices:
1. use strftime
2. use IntlDateFormatter & setPattern

IntlDateFormatter & setPattern requires php 5.3.0, i think this is fine, but totally dislike it's complexity

any opinion?

Revision history for this message
Elan Ruusamäe (glen666) wrote :

strftime problem is that it formats in local timezone, can't tell it to format in GMT timezone:

Expected :Thu, 01 Jan 1970, 00:00:00 UTC
Actual :Thu, 01 Jan 1970, 03:00:00 MSK

Revision history for this message
Elan Ruusamäe (glen666) wrote :

but if i use gmstrftime then the GMT timezone is named differently:

Failed asserting that two strings are equal.
Expected :Thu, 01 Jan 1970, 00:00:00 UTC
Actual :Thu, 01 Jan 1970, 00:00:00 GMT

Revision history for this message
Elan Ruusamäe (glen666) wrote :
Revision history for this message
Elan Ruusamäe (glen666) wrote :

fixed in master. comment if not

Changed in eventum:
assignee: nobody → Elan Ruusamäe (glen666)
importance: Undecided → Low
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.