mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-24 02:11:27 +01:00
FIX dol_print_date for %a and %b with some Timezone
This commit is contained in:
@@ -2197,8 +2197,8 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs =
|
||||
if ($tzoutput == 'tzserver') {
|
||||
$to_gmt = false;
|
||||
$offsettzstring = @date_default_timezone_get(); // Example 'Europe/Berlin' or 'Indian/Reunion'
|
||||
$offsettz = 0;
|
||||
$offsetdst = 0;
|
||||
$offsettz = 0; // Timezone offset with server timezone, so 0
|
||||
$offsetdst = 0; // Dst offset with server timezone, so 0
|
||||
} elseif ($tzoutput == 'tzuser' || $tzoutput == 'tzuserrel') {
|
||||
$to_gmt = true;
|
||||
$offsettzstring = (empty($_SESSION['dol_tz_string']) ? 'UTC' : $_SESSION['dol_tz_string']); // Example 'Europe/Berlin' or 'Indian/Reunion'
|
||||
@@ -2308,7 +2308,7 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs =
|
||||
if ($time < 100000000000) { // Protection against bad date values
|
||||
$timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
|
||||
|
||||
$ret = adodb_strftime($format, $timetouse, $to_gmt);
|
||||
$ret = adodb_strftime($format, $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server
|
||||
} else {
|
||||
$ret = 'Bad value '.$time.' for date';
|
||||
}
|
||||
@@ -2318,7 +2318,7 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs =
|
||||
$timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
|
||||
|
||||
// Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs.
|
||||
$month = adodb_strftime('%m', $timetouse, true);
|
||||
$month = adodb_strftime('%m', $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server
|
||||
$month = sprintf("%02d", $month); // $month may be return with format '06' on some installation and '6' on other, so we force it to '06'.
|
||||
if ($encodetooutput) {
|
||||
$monthtext = $outputlangs->transnoentities('Month'.$month);
|
||||
@@ -2334,9 +2334,10 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs =
|
||||
//return $ret;
|
||||
}
|
||||
if (preg_match('/__a__/i', $format)) {
|
||||
//print "time=$time offsettz=$offsettz offsetdst=$offsetdst offsettzstring=$offsettzstring";
|
||||
$timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
|
||||
|
||||
$w = adodb_strftime('%w', $timetouse, true); // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
|
||||
$w = adodb_strftime('%w', $timetouse, $to_gmt); // If to_gmt = false then adodb_strftime use TZ of server
|
||||
$dayweek = $outputlangs->transnoentitiesnoconv('Day'.$w);
|
||||
$ret = str_replace('__A__', $dayweek, $ret);
|
||||
$ret = str_replace('__a__', dol_substr($dayweek, 0, 3), $ret);
|
||||
|
||||
@@ -81,13 +81,16 @@ $monthofday = GETPOST('addtimemonth');
|
||||
$dayofday = GETPOST('addtimeday');
|
||||
$yearofday = GETPOST('addtimeyear');
|
||||
|
||||
$daytoparse = $now;
|
||||
if ($yearofday && $monthofday && $dayofday) {
|
||||
$daytoparse = dol_mktime(0, 0, 0, $monthofday, $dayofday, $yearofday); // xxxofday is value of day after submit action 'addtime'
|
||||
} elseif ($year && $month && $day) {
|
||||
$daytoparse = dol_mktime(0, 0, 0, $month, $day, $year); // this are value submited after submit of action 'submitdateselect'
|
||||
}
|
||||
/*var_dump(GETPOST('remonth'));
|
||||
var_dump(GETPOST('button_search_x'));
|
||||
var_dump(GETPOST('button_addtime'));*/
|
||||
|
||||
$daytoparse = $now;
|
||||
if ($year && $month && $day) {
|
||||
$daytoparse = dol_mktime(0, 0, 0, $month, $day, $year); // this are value submited after submit of action 'submitdateselect'
|
||||
} elseif ($yearofday && $monthofday && $dayofday) {
|
||||
$daytoparse = dol_mktime(0, 0, 0, $monthofday, $dayofday, $yearofday); // xxxofday is value of day after submit action 'addtime'
|
||||
}
|
||||
|
||||
if (empty($search_usertoprocessid) || $search_usertoprocessid == $user->id) {
|
||||
$usertoprocess = $user;
|
||||
@@ -416,10 +419,10 @@ $search_options_pattern = 'search_task_options_';
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
|
||||
|
||||
// Show navigation bar
|
||||
$nav = '<a class="inline-block valignmiddle" href="?year='.$prev_year."&month=".$prev_month."&day=".$prev_day.$param.'">'.img_previous($langs->trans("Previous"))."</a>\n";
|
||||
$nav = '<a class="inline-block valignmiddle" href="?year='.$prev_year."&month=".$prev_month."&day=".$prev_day.$param.'">'.img_previous($langs->trans("Previous"))."</a>\n";
|
||||
$nav .= dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "%A").' ';
|
||||
$nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "day")." </span>\n";
|
||||
$nav .= '<a class="inline-block valignmiddle" href="?year='.$next_year."&month=".$next_month."&day=".$next_day.$param.'">'.img_next($langs->trans("Next"))."</a>\n";
|
||||
$nav .= '<a class="inline-block valignmiddle" href="?year='.$next_year."&month=".$next_month."&day=".$next_day.$param.'">'.img_next($langs->trans("Next"))."</a>\n";
|
||||
$nav .= ' '.$form->selectDate(-1, '', 0, 0, 2, "addtime", 1, 1).' ';
|
||||
$nav .= ' <button type="submit" name="button_search_x" value="x" class="bordertransp"><span class="fa fa-search"></span></button>';
|
||||
|
||||
@@ -773,7 +776,7 @@ print '</div>';
|
||||
print '<input type="hidden" id="numberOfLines" name="numberOfLines" value="'.count($tasksarray).'"/>'."\n";
|
||||
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button button-save"'.($disabledtask ? ' disabled' : '').' value="'.$langs->trans("Save").'">';
|
||||
print '<input type="submit" name="button_addtime" class="button button-save"'.($disabledtask ? ' disabled' : '').' value="'.$langs->trans("Save").'">';
|
||||
print '</div>';
|
||||
|
||||
print '</form>';
|
||||
|
||||
@@ -665,7 +665,12 @@ if (!empty($arrayfields['timeconsumed']['checked'])) {
|
||||
for ($idw = 0; $idw < 7; $idw++) {
|
||||
$dayinloopfromfirstdaytoshow = dol_time_plus_duree($firstdaytoshow, $idw, 'd'); // $firstdaytoshow is a date with hours = 0
|
||||
$dayinloop = dol_time_plus_duree($startday, $idw, 'd');
|
||||
|
||||
/*print $dayinloopfromfirstdaytoshow;
|
||||
print dol_print_date($dayinloopfromfirstdaytoshow, 'dayhour', 'gmt');
|
||||
print dol_print_date($dayinloopfromfirstdaytoshow, 'dayhour');
|
||||
print dol_print_date($dayinloopfromfirstdaytoshow, '%a', 'gmt');
|
||||
print dol_print_date($dayinloopfromfirstdaytoshow, '%a');
|
||||
print '<br>';*/
|
||||
$cssweekend = '';
|
||||
if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) { // This is a day is not inside the setup of working days, so we use a week-end css.
|
||||
$cssweekend = 'weekend';
|
||||
@@ -682,7 +687,9 @@ for ($idw = 0; $idw < 7; $idw++) {
|
||||
$cssonholiday .= 'onholidayafternoon ';
|
||||
}
|
||||
|
||||
print '<th width="6%" align="center" class="bold hide'.$idw.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">'.dol_print_date($dayinloopfromfirstdaytoshow, '%a').'<br>'.dol_print_date($dayinloopfromfirstdaytoshow, 'dayreduceformat').'</th>';
|
||||
print '<th width="6%" align="center" class="bold hide'.$idw.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
|
||||
print dol_print_date($dayinloopfromfirstdaytoshow, '%a');
|
||||
print '<br>'.dol_print_date($dayinloopfromfirstdaytoshow, 'dayreduceformat').'</th>';
|
||||
}
|
||||
//print '<td></td>';
|
||||
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
|
||||
|
||||
@@ -1029,7 +1029,7 @@ if ($conf->global->TAKEPOS_DIRECT_PAYMENT) {
|
||||
// BAR RESTAURANT specific menu
|
||||
if ($conf->global->TAKEPOS_BAR_RESTAURANT) {
|
||||
if ($conf->global->TAKEPOS_ORDER_PRINTERS) {
|
||||
$menus[$r++] = array('title'=>$langs->trans("Order"), 'action'=>'TakeposPrintingOrder();');
|
||||
$menus[$r++] = array('title'=>'<span class="fa fa-blender-phone paddingrightonly"></span><div class="trunc">'.$langs->trans("Order").'</span>', 'action'=>'TakeposPrintingOrder();');
|
||||
}
|
||||
//Button to print receipt before payment
|
||||
if ($conf->global->TAKEPOS_BAR_RESTAURANT) {
|
||||
|
||||
@@ -390,6 +390,17 @@ class DateLibTest extends PHPUnit\Framework\TestCase
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertEquals('Jeu Jan. Janvier', $result);
|
||||
|
||||
|
||||
$result=dol_print_date(1619388000, '%Y-%m-%d %a', 'gmt', $outputlangs);
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertEquals('2021-04-25 Dim', $result);
|
||||
|
||||
/* This test is disabled because result depends on TZ of server
|
||||
$result=dol_print_date(1619388000, '%Y-%m-%d %a', 'tzserver', $outputlangs); // If TZ is +2, then result will be Lun for 1619388000
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertEquals('2021-04-26 Lun', $result);
|
||||
*/
|
||||
|
||||
// Check day format for en_US
|
||||
$outputlangs=new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang('en_US');
|
||||
|
||||
Reference in New Issue
Block a user