Skip to content

Commit

Permalink
Merge branch 'w23_MDL-32632_m23_windate' of git://github.com/skodak/m…
Browse files Browse the repository at this point in the history
…oodle
  • Loading branch information
danpoltawski committed Jun 6, 2012
2 parents 5dc4db1 + 63d5987 commit dcba513
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions lib/moodlelib.php
Expand Up @@ -2037,8 +2037,17 @@ function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour

$timezone = get_user_timezone_offset($timezone);

// If we are running under Windows convert to windows encoding and then back to UTF-8
// (because it's impossible to specify UTF-8 to fetch locale info in Win32)

if (abs($timezone) > 13) { /// Server time
$datestring = strftime($format, $date);
if ($CFG->ostype == 'WINDOWS' and ($localewincharset = get_string('localewincharset', 'langconfig'))) {
$format = textlib::convert($format, 'utf-8', $localewincharset);
$datestring = strftime($format, $date);
$datestring = textlib::convert($datestring, $localewincharset, 'utf-8');
} else {
$datestring = strftime($format, $date);
}
if ($fixday) {
$daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $date)));
$datestring = str_replace('DD', $daystring, $datestring);
Expand All @@ -2047,9 +2056,16 @@ function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour
$hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $date)));
$datestring = str_replace('HH', $hourstring, $datestring);
}

} else {
$date += (int)($timezone * 3600);
$datestring = gmstrftime($format, $date);
if ($CFG->ostype == 'WINDOWS' and ($localewincharset = get_string('localewincharset', 'langconfig'))) {
$format = textlib::convert($format, 'utf-8', $localewincharset);
$datestring = gmstrftime($format, $date);
$datestring = textlib::convert($datestring, $localewincharset, 'utf-8');
} else {
$datestring = gmstrftime($format, $date);
}
if ($fixday) {
$daystring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %d', $date)));
$datestring = str_replace('DD', $daystring, $datestring);
Expand All @@ -2060,15 +2076,6 @@ function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour
}
}

/// If we are running under Windows convert from windows encoding to UTF-8
/// (because it's impossible to specify UTF-8 to fetch locale info in Win32)

if ($CFG->ostype == 'WINDOWS') {
if ($localewincharset = get_string('localewincharset', 'langconfig')) {
$datestring = textlib::convert($datestring, $localewincharset, 'utf-8');
}
}

return $datestring;
}

Expand Down

0 comments on commit dcba513

Please sign in to comment.