Browse Source

Switch between date and IntlDateFormatter

pull/558/merge
danpros 2 years ago
parent
commit
89b637e9f5
5 changed files with 42 additions and 26 deletions
  1. +1
    -1
      config/config.ini.example
  2. +7
    -1
      system/admin/views/backup.html.php
  3. +20
    -14
      system/admin/views/config.html.php
  4. +2
    -2
      system/htmly.php
  5. +12
    -8
      system/includes/functions.php

+ 1
- 1
config/config.ini.example View File

@ -5,7 +5,7 @@ site.url = ""
timezone = "Asia/Jakarta"
; Date format. See: https://www.php.net/manual/en/function.strftime
date.format = "%d %B %Y"
date.format = "d F Y"
; Your language (example "en_US" for English or "de_DE" for German. See lang directory for available language)
language = "en_US"


+ 7
- 1
system/admin/views/backup.html.php View File

@ -11,8 +11,14 @@ if (login()) {
}
}
?>
<?php if (!extension_loaded('zip')) { ?>
<div class="callout callout-info">
<h5><i class="fa fa-info"></i> Note:</h5>
Please install the ZIP extension to use the backup feature.
</div>
<?php } ?>
<h2><?php echo i18n('Your_backups');?></h2>
<br>
<a class="btn btn-primary" href="<?php echo site_url() ?>admin/backup-start"><?php echo i18n('Create_backup');?></a>
<a class="btn btn-primary <?php if (!extension_loaded('zip')) { ?>disabled<?php } ?>" href="<?php echo site_url() ?>admin/backup-start"><?php echo i18n('Create_backup');?></a>
<br><br>
<?php echo get_backup_files() ?>

+ 20
- 14
system/admin/views/config.html.php View File

@ -1,6 +1,12 @@
<?php if (!defined('HTMLY')) die('HTMLy'); ?>
<h2><?php echo i18n('General_Settings')?></h2>
<br>
<?php if (!extension_loaded('intl')) { ?>
<div class="callout callout-info">
<h5><i class="fa fa-info"></i> Note:</h5>
Please install and enable the INTL extension to format the date format to your local language.
</div>
<?php } ?>
<nav>
<div class="nav nav-tabs" id="nav-tab">
<a class="nav-item nav-link active" id="nav-general-tab" href="<?php echo site_url();?>admin/config"><?php echo i18n('General');?></a>
@ -66,45 +72,45 @@
<div class="col-sm-10">
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format1" value="dd MMMM yyyy" <?php if (config('date.format') === 'dd MMMM yyyy'):?>checked<?php endif;?>>
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format1" value="d F Y" <?php if (config('date.format') === 'd F Y'):?>checked<?php endif;?>>
<label class="form-check-label" for="date.format1">
<?php echo format_date(strtotime($date), 'dd MMMM yyyy'); ?>
<?php echo format_date(strtotime($date), 'd F Y'); ?>
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format2" value="MMMM dd, yyyy" <?php if (config('date.format') === 'MMMM dd, yyyy'):?>checked<?php endif;?>>
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format2" value="F d, Y" <?php if (config('date.format') === 'F d, Y'):?>checked<?php endif;?>>
<label class="form-check-label" for="date.format2">
<?php echo format_date(strtotime($date), 'MMMM dd, yyyy'); ?>
<?php echo format_date(strtotime($date), 'F d, Y'); ?>
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format3" value="dd MMM yyyy" <?php if (config('date.format') === 'dd MMM yyyy'):?>checked<?php endif;?>>
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format3" value="d M Y" <?php if (config('date.format') === 'd M Y'):?>checked<?php endif;?>>
<label class="form-check-label" for="date.format3">
<?php echo format_date(strtotime($date), 'dd MMM yyyy'); ?>
<?php echo format_date(strtotime($date), 'd M Y'); ?>
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format4" value="MMM dd, yyyy" <?php if (config('date.format') === 'MMM dd, yyyy'):?>checked<?php endif;?>>
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format4" value="M d, Y" <?php if (config('date.format') === 'M d, Y'):?>checked<?php endif;?>>
<label class="form-check-label" for="date.format4">
<?php echo format_date(strtotime($date), 'MMM dd, yyyy'); ?>
<?php echo format_date(strtotime($date), 'M d, Y'); ?>
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format5" value="dd/MM/yyyy" <?php if (config('date.format') === 'dd/MM/yyyy'):?>checked<?php endif;?>>
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format5" value="d/m/Y" <?php if (config('date.format') === 'd/m/Y'):?>checked<?php endif;?>>
<label class="form-check-label" for="date.format5">
<?php echo format_date(strtotime($date), 'dd/MM/yyyy'); ?>
<?php echo format_date(strtotime($date), 'd/m/Y'); ?>
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format6" value="MM/dd/yyyy" <?php if (config('date.format') === 'MM/dd/yyyy'):?>checked<?php endif;?>>
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format6" value="m/d/Y" <?php if (config('date.format') === 'm/d/Y'):?>checked<?php endif;?>>
<label class="form-check-label" for="date.format6">
<?php echo format_date(strtotime($date), 'MM/dd/yyyy'); ?>
<?php echo format_date(strtotime($date), 'm/d/Y'); ?>
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format6" value="yyyy-MM-dd" <?php if (config('date.format') === 'yyyy-MM-dd'):?>checked<?php endif;?>>
<input class="form-check-input" type="radio" name="-config-date.format" id="date.format6" value="Y-m-d" <?php if (config('date.format') === 'Y-m-d'):?>checked<?php endif;?>>
<label class="form-check-label" for="date.format6">
<?php echo format_date(strtotime($date), 'yyyy-MM-dd'); ?>
<?php echo format_date(strtotime($date), 'Y-m-d'); ?>
</label>
</div>


+ 2
- 2
system/htmly.php View File

@ -2072,9 +2072,9 @@ get('/archive/:req', function ($req) {
$date = strtotime($req);
if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
$timestamp = format_date($date, 'dd MMMM yyyy');
$timestamp = format_date($date, 'd F Y');
} elseif (isset($time[0]) && isset($time[1])) {
$timestamp = format_date($date, 'MMMM yyyy');
$timestamp = format_date($date, 'F Y');
} else {
$timestamp = $req;
}


+ 12
- 8
system/includes/functions.php View File

@ -1432,7 +1432,7 @@ EOF;
echo '<ul class="month">';
foreach ($by_month as $month => $count) {
$name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'MMMM');
$name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F');
echo '<li class="item"><a href="' . site_url() . 'archive/' . $year . '-' . $month . '">' . $name . '</a>';
echo ' <span class="count">(' . $count . ')</span></li>';
}
@ -3251,15 +3251,19 @@ function get_language()
}
function format_date($date, $date_format = null)
function format_date($date, $dateFormat = null)
{
if (empty($date_format)) {
$date_format = config('date.format');
if (empty($dateFormat)) {
$dateFormat = config('date.format');
}
if (extension_loaded('intl')) {
$format_map = array('d' => 'dd', 'm' => 'MM', 'M' => 'MMM', 'F' => 'MMMM', 'Y' => 'yyyy');
$intlFormat = strtr($dateFormat, $format_map);
$formatter = new IntlDateFormatter(config('language'), IntlDateFormatter::NONE, IntlDateFormatter::NONE, config('timezone'), IntlDateFormatter::GREGORIAN, $intlFormat);
return $formatter->format($date);
} else {
return date($dateFormat, $date);
}
$formatter = new IntlDateFormatter(config('language'), IntlDateFormatter::LONG, IntlDateFormatter::NONE, config('timezone'), IntlDateFormatter::GREGORIAN, $date_format);
return $formatter->format($date);
}
function valueMaker($value)


Loading…
Cancel
Save