Skip to content

Commit

Permalink
Use intldateformatter for getting day/month names instead of relying …
Browse files Browse the repository at this point in the history
…on locales
  • Loading branch information
flack committed Nov 3, 2017
1 parent 4c9863b commit 5837397
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/midcom/services/i18n/formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public function datetime($value = null, $dateformat = 'medium', $timeformat = 's
return $this->date($value, $dateformat, $timeformat);
}

public function customdate($value, $pattern)
{
$formatter = new IntlDateFormatter($this->get_locale(), IntlDateFormatter::FULL, IntlDateFormatter::FULL);
$formatter->setPattern($pattern);
return $formatter->format($value);
}

public function timeframe($start, $end, $mode = 'both', $range_separator = null, $fulldate = false)
{
$ranger = new Ranger($this->get_locale());
Expand Down
3 changes: 2 additions & 1 deletion lib/net/nehmer/blog/handler/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ private function _compute_welcome_data()
private function _get_month_names()
{
$names = [];
$formatter = $this->_l10n->get_formatter();
for ($i = 1; $i < 13; $i++) {
$timestamp = mktime(0, 0, 0, $i, 1, 2011);
$names[$i] = strftime('%B', $timestamp);
$names[$i] = $formatter->customdate($timestamp, 'MMMM');
}
return $names;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/expenses/style/hours_week.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$i = 6;
while ($time < $data['week_end']) {
$date_identifier = date('Y-m-d', $time);
$data['grid']->set_column($date_identifier, strftime('%a', $time), 'fixed: true, headerTitle: "' . $formatter->date($time) . '" , width: 40, summaryType: calculate_subtotal, align: "right"', 'float');
$data['grid']->set_column($date_identifier, $formatter->customdate($time, 'E'), 'fixed: true, headerTitle: "' . $formatter->date($time) . '" , width: 40, summaryType: calculate_subtotal, align: "right"', 'float');
// Hop to next day
$date_columns[] = $date_identifier;
$time = $time + 3600 * 24;
Expand Down
2 changes: 1 addition & 1 deletion lib/org/openpsa/invoices/handler/scheduled.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function get_row(midcom_core_dbaobject $at_entry)
{
$invoice = [
'time' => strftime('%Y-%m-%d %H:%M:%S', $at_entry->start),
'month' => strftime('%B %Y', $at_entry->start),
'month' => $this->_l10n->get_formatter()->customdate($at_entry->start, 'MMMM y'),
'index_month' => strftime('%Y-%m', $at_entry->start),
];
try {
Expand Down
3 changes: 2 additions & 1 deletion lib/org/openpsa/reports/style/invoices_report-grid.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
$prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
$l10n = midcom::get()->i18n->get_l10n('org.openpsa.invoices');
$formatter = $l10n->get_formatter();

$status_options = [
'scheduled' => $l10n->get('scheduled'),
Expand Down Expand Up @@ -62,7 +63,7 @@
if ($invoice->{$data['date_field']} > 0) {
$entry['date'] = strftime('%Y-%m-%d', $invoice->{$data['date_field']});
$entry['year'] = strftime('%Y', $invoice->{$data['date_field']});
$entry['month'] = strftime('%B %Y', $invoice->{$data['date_field']});
$entry['month'] = $formatter->customdate($invoice->{$data['date_field']}, 'MMMM y');
$entry['index_month'] = strftime('%Y%m', $invoice->{$data['date_field']});
}
try {
Expand Down

0 comments on commit 5837397

Please sign in to comment.