Active
Project:
Date
Version:
7.x-2.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Apr 2013 at 18:20 UTC
Updated:
12 Nov 2018 at 17:06 UTC
Jump to comment: Most recent
I needed a date/time format to be in Chinese. Example: 2013年 4月 30日 - 13:00. Where 年 = Year, 月 = Month, 日 = date.
After creating a date format with chinese input Y年 n月 j日 - H:i, the time display got messed up.
To reproduce this bug:
Y年 n月 j日 - H:iChinese and select the Date Format from aboveThe output: 2013年 4月 30日 - 13:00 年月日, which is wrong.
The correct output should be: 2013年 4月 30日 - 13:00 to 14:00
After digging into the module, I found out that the function date_formatter_process is not stripping non-english characters from the formatted time and timezone.
Thankfully, the Date API allowed me to quickly hook into and clean up the formatter with the non-english string(or whatever you call it).
function mymodule_date_formatter_dates_alter(&$dates) {
$dates['value']['formatted_time'] = preg_replace('/[^\00-\255]+/u', '', $dates['value']['formatted_time']); // Strip non-english characters
$dates['value2']['formatted_time'] = preg_replace('/[\s-]+/u', '', $dates['value2']['formatted_time']);// Strip hyphens and spaces
$dates['value2']['formatted_time'] = preg_replace('/[^\00-\255]+/u', '', $dates['value2']['formatted_time']); // Strip non-english characters
$dates['value']['formatted_timezone'] = preg_replace('/[^\00-\255]+/u', '', $dates['value2']['formatted_timezone']); // Strip non-english characters
$dates['value2']['formatted_timezone'] = preg_replace('/[^\00-\255]+/u', '', $dates['value2']['formatted_timezone']); // Strip non-english characters
}
Comments
Comment #1
monish_deb commentedThere is a similar issue When placing an '@' sign in a custom Date Format, it moves it to the end of the string. for which special character/non-latin character were not stripped from the formatted time and timezone due to which it is appended at the end of the date string. The patch I have provided was just to highlight the possible spot where to fix the changes (as overridden by your Date API ), but I think there should be a generalize solution to fix this issue like suggested at #3.
Comment #2
nocean commentedI have the exact same problem as the OP (right down to the Chinese characters). Despite being a bit hackish, the custom module hook worked like a charm (thanks logii). Looking forward to a fix making its way into the core module.
Comment #3
steinmb commented