mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
+ configurable date format
This commit is contained in:
parent
adb082a75b
commit
b20bc1406d
6 changed files with 51 additions and 25 deletions
49
src/ajax.php
49
src/ajax.php
|
|
@ -486,12 +486,18 @@ function tag_size($qmin, $q, $step)
|
|||
|
||||
function parse_duedate($s)
|
||||
{
|
||||
global $config;
|
||||
$y = $m = $d = 0;
|
||||
if(preg_match("|^(\d+)-(\d+)-(\d+)\b|", $s, $ma)) {
|
||||
$y = (int)$ma[1]; $m = (int)$ma[2]; $d = (int)$ma[3];
|
||||
}
|
||||
elseif(preg_match("|^(\d+)\/(\d+)\/(\d+)\b|", $s, $ma)) {
|
||||
$m = (int)$ma[1]; $d = (int)$ma[2]; $y = (int)$ma[3];
|
||||
elseif(preg_match("|^(\d+)\/(\d+)\/(\d+)\b|", $s, $ma))
|
||||
{
|
||||
if($config['duedateformat'] == 4) {
|
||||
$d = (int)$ma[1]; $m = (int)$ma[2]; $y = (int)$ma[3];
|
||||
} else {
|
||||
$m = (int)$ma[1]; $d = (int)$ma[2]; $y = (int)$ma[3];
|
||||
}
|
||||
}
|
||||
elseif(preg_match("|^(\d+)\.(\d+)\.(\d+)\b|", $s, $ma)) {
|
||||
$d = (int)$ma[1]; $m = (int)$ma[2]; $y = (int)$ma[3];
|
||||
|
|
@ -502,8 +508,13 @@ function parse_duedate($s)
|
|||
if( $m<(int)$a[1] || ($m==(int)$a[1] && $d<(int)$a[2]) ) $y = (int)$a[0]+1;
|
||||
else $y = (int)$a[0];
|
||||
}
|
||||
elseif(preg_match("|^(\d+)\/(\d+)\b|", $s, $ma)) {
|
||||
$m = (int)$ma[1]; $d = (int)$ma[2];
|
||||
elseif(preg_match("|^(\d+)\/(\d+)\b|", $s, $ma))
|
||||
{
|
||||
if($config['duedateformat'] == 4) {
|
||||
$d = (int)$ma[1]; $m = (int)$ma[2];
|
||||
} else {
|
||||
$m = (int)$ma[1]; $d = (int)$ma[2];
|
||||
}
|
||||
$a = explode(',', date('Y,m,d'));
|
||||
if( $m<(int)$a[1] || ($m==(int)$a[1] && $d<(int)$a[2]) ) $y = (int)$a[0]+1;
|
||||
else $y = (int)$a[0];
|
||||
|
|
@ -537,18 +548,19 @@ function prepare_duedate($duedate, $tz=null)
|
|||
}
|
||||
$diff = mktime(0,0,0,$ad[1],$ad[2],$ad[0]) - mktime(0,0,0,$at[1],$at[2],$at[0]);
|
||||
|
||||
if($diff < -604800 && $ad[0] == $at[0]) { $a['class'] = 'past'; $a['str'] = $lang->formatMD((int)$ad[1], (int)$ad[2]); }
|
||||
elseif($diff < -604800) { $a['class'] = 'past'; $a['str'] = $lang->formatYMD((int)$ad[0], (int)$ad[1], (int)$ad[2]); }
|
||||
if($diff < -604800 && $ad[0] == $at[0]) { $a['class'] = 'past'; $a['str'] = formatDate3($config['dateformatshort'], (int)$ad[0], (int)$ad[1], (int)$ad[2]); }
|
||||
elseif($diff < -604800) { $a['class'] = 'past'; $a['str'] = formatDate3($config['dateformat'], (int)$ad[0], (int)$ad[1], (int)$ad[2]); }
|
||||
elseif($diff < -86400) { $a['class'] = 'past'; $a['str'] = sprintf($lang->get('daysago'),ceil(abs($diff)/86400)); }
|
||||
elseif($diff < 0) { $a['class'] = 'past'; $a['str'] = $lang->get('yesterday'); }
|
||||
elseif($diff < 86400) { $a['class'] = 'today'; $a['str'] = $lang->get('today'); }
|
||||
elseif($diff < 172800) { $a['class'] = 'today'; $a['str'] = $lang->get('tomorrow'); }
|
||||
elseif($diff < 691200) { $a['class'] = 'soon'; $a['str'] = sprintf($lang->get('indays'),ceil($diff/86400)); }
|
||||
elseif($ad[0] == $at[0]) { $a['class'] = 'future'; $a['str'] = $lang->formatMD((int)$ad[1], (int)$ad[2]); }
|
||||
else { $a['class'] = 'future'; $a['str'] = $lang->formatYMD((int)$ad[0], (int)$ad[1], (int)$ad[2]); }
|
||||
elseif($ad[0] == $at[0]) { $a['class'] = 'future'; $a['str'] = formatDate3($config['dateformatshort'], (int)$ad[0], (int)$ad[1], (int)$ad[2]); }
|
||||
else { $a['class'] = 'future'; $a['str'] = formatDate3($config['dateformat'], (int)$ad[0], (int)$ad[1], (int)$ad[2]); }
|
||||
|
||||
if($config['duedateformat'] == 2) $a['formatted'] = (int)$ad[1].'/'.(int)$ad[2].'/'.$ad[0];
|
||||
elseif($config['duedateformat'] == 3) $a['formatted'] = $ad[2].'.'.$ad[1].'.'.$ad[0];
|
||||
elseif($config['duedateformat'] == 4) $a['formatted'] = $ad[2].'/'.$ad[1].'/'.$ad[0];
|
||||
else $a['formatted'] = $duedate;
|
||||
|
||||
return $a;
|
||||
|
|
@ -596,4 +608,25 @@ function myExceptionHandler($e)
|
|||
exit;
|
||||
}
|
||||
|
||||
function formatDate3($format, $ay, $am, $ad)
|
||||
{
|
||||
# F - month long, M - month short
|
||||
# m - month 2-digit, n - month 1-digit
|
||||
# d - day 2-digit, j - day 1-digit
|
||||
global $lang;
|
||||
$ml = $lang->get('months_long');
|
||||
$ms = $lang->get('months_short');
|
||||
$Y = $ay;
|
||||
$n = $am;
|
||||
$m = $n < 10 ? '0'.$n : $n;
|
||||
$F = $ml[$am-1];
|
||||
$M = $ms[$am-1];
|
||||
$j = $ad;
|
||||
$d = $j < 10 ? '0'.$j : $j;
|
||||
return str_replace(
|
||||
array('Y','F','M','n','m','d','j'),
|
||||
array($Y, $F, $M, $n, $m, $d, $j),
|
||||
$format);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -75,6 +75,9 @@ class Config
|
|||
'duedateformat' => array('default'=>1, 'type'=>'i'),
|
||||
'firstdayofweek' => array('default'=>1, 'type'=>'i'),
|
||||
'session' => array('default'=>'files', 'type'=>'s', 'options'=>array('files','default')),
|
||||
'clock' => array('default'=>24, 'type'=>'i', 'options'=>array(12,24)),
|
||||
'dateformat' => array('default'=>'j M Y', 'type'=>'s'),
|
||||
'dateformatshort' => array('default'=>'j M', 'type'=>'s'),
|
||||
);
|
||||
|
||||
public static function save($config)
|
||||
|
|
|
|||
|
|
@ -41,4 +41,9 @@ $config['firstdayofweek'] = 1;
|
|||
# select session handling mechanism: files or default (php default)
|
||||
$config['session'] = 'files';
|
||||
|
||||
# Date/time formats
|
||||
$config['clock'] = 24;
|
||||
$config['dateformat'] = 'j M Y';
|
||||
$config['dateformatshort'] = 'j M';
|
||||
|
||||
?>
|
||||
|
|
@ -17,6 +17,7 @@ if(isset($_COOKIE['sort']) && $_COOKIE['sort'] != '') $sort = (int)$_COOKIE['sor
|
|||
|
||||
if($config['duedateformat'] == 2) $duedateformat = 'm/d/yy';
|
||||
elseif($config['duedateformat'] == 3) $duedateformat = 'dd.mm.yy';
|
||||
elseif($config['duedateformat'] == 4) $duedateformat = 'dd/mm/yy';
|
||||
else $duedateformat = 'yy-mm-dd';
|
||||
|
||||
if(!isset($config['firstdayofweek']) || !is_int($config['firstdayofweek']) ||
|
||||
|
|
@ -65,7 +66,7 @@ $().ready(function(){
|
|||
if(is_logged()) echo "\tflag.isLogged = true;\n";
|
||||
echo "\tupdateAccessStatus();\n";
|
||||
}
|
||||
echo "\tloadLists(1)\n";
|
||||
echo "\tloadLists(1);\n";
|
||||
?>
|
||||
preloadImg();
|
||||
$("#duedate").datepicker({dateFormat: '<?php echo $duedateformat; ?>', firstDay: <?php echo $config['firstdayofweek']; ?>,
|
||||
|
|
|
|||
|
|
@ -57,8 +57,6 @@ class DefaultLang
|
|||
'months_short' => array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"),
|
||||
'months_long' => array("January","February","March","April","May","June","July","August","September","October","November","December"),
|
||||
'days_min' => array("Su","Mo","Tu","We","Th","Fr","Sa"),
|
||||
'date_md' => "%1\$s %2\$d",
|
||||
'date_ymd' => "%2\$s %3\$d, %1\$d",
|
||||
'today' => "today",
|
||||
'yesterday' => "yesterday",
|
||||
'tomorrow' => "tomorrow",
|
||||
|
|
@ -110,18 +108,6 @@ class DefaultLang
|
|||
if(isset($this->default_inc[$key])) return $this->default_inc[$key];
|
||||
return $key;
|
||||
}
|
||||
|
||||
function formatMD($m, $d)
|
||||
{
|
||||
$months = $this->get('months_short');
|
||||
return sprintf($this->get('date_md'), $months[$m-1], $d);
|
||||
}
|
||||
|
||||
function formatYMD($y, $m, $d)
|
||||
{
|
||||
$months = $this->get('months_short');
|
||||
return sprintf($this->get('date_ymd'), $y, $months[$m-1], $d);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -52,8 +52,6 @@ class Lang extends DefaultLang
|
|||
'months_short' => array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"),
|
||||
'months_long' => array("January","February","March","April","May","June","July","August","September","October","November","December"),
|
||||
'days_min' => array("Su","Mo","Tu","We","Th","Fr","Sa"),
|
||||
'date_md' => "%1\$s %2\$d",
|
||||
'date_ymd' => "%2\$s %3\$d, %1\$d",
|
||||
'today' => "today",
|
||||
'yesterday' => "yesterday",
|
||||
'tomorrow' => "tomorrow",
|
||||
|
|
|
|||
Loading…
Reference in a new issue