Skip to content

Commit

Permalink
fix: use IntlDateFormatter instead of strftime
Browse files Browse the repository at this point in the history
This CL introduces breaking changes, since it uses non-constant static
variable initializers, which are only available since PHP 8.3. Thus, the
codebase now only supports PHP 8.3 (and the docs have been modified to
reflect this and the fact that the Intl extension is necessary).

Fixed: hores:2
GitOrigin-RevId: 9a91312c96b90fa4c9ae5fc5f6e972fd95c9cd57
  • Loading branch information
avm99963 authored and Copybara bot committed Dec 3, 2023
1 parent 4f968f0 commit eaee4a9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
El servidor donde se va a instalar el aplicativo debe cumplir los siguientes requisitos:

* **Sistema operativo:** distro Linux, Mac o Windows (se recomienda Linux, ya que solo está probado con Linux)
* **Servidor:** Apache 2, PHP 8.2 (incluyendo las extensiones `mysql` y `curl`), MySQL.
* **Servidor:** Apache 2, PHP 8.3 (incluyendo las extensiones `mysql`, `curl` y `intl`), MySQL.

## Instalación
Para instalar el aplicativo, descarga el código fuente desde [https://github.com/avm99963/hores-external](https://github.com/avm99963/hores-external) y extraelo en el directorio raíz de Apache (`/var/www/html/` es el directorio raíz de Apache por defecto en Ubuntu).
Expand Down
2 changes: 1 addition & 1 deletion src/doexport.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Footer() {

$this->SetFont('Arial','I',10);
$this->SetY(-20);
$this->Cell(0, 10, export::convert("Generado: ".strftime("%d %b %Y %T", $actualTime)), 0, 0, 'L');
$this->Cell(0, 10, export::convert("Generado: ".date::getShortDateWithTime($actualTime)), 0, 0, 'L');
$this->SetY(-20);
$this->Cell(0, 10, $this->PageNo().'/{nb}', 0, 0, 'R');
}
Expand Down
2 changes: 1 addition & 1 deletion src/inc/calendarsView.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function renderCalendar($current, $ends, $selectedFunc, $disabled

if ($dow == 1) echo "</tr>";
if ($dom == 1) echo "</table>";
if ($dom == 1 || $start) echo "<div class='month'>".security::htmlsafe(ucfirst(strftime("%B %G", $current->getTimestamp())))."</div><table class='calendar'>";
if ($dom == 1 || $start) echo "<div class='month'>".security::htmlsafe(ucfirst(date::getMonthYear($current->getTimestamp())))."</div><table class='calendar'>";
if ($dow == 1 || $start) echo "<tr>";
if ($dom == 1 || $start) {
for ($i = 1; $i < $dow; $i++) {
Expand Down
35 changes: 35 additions & 0 deletions src/inc/date.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
class date {
const LOCALE = 'es';

private static function createFormatter(string $pattern) {
return new IntlDateFormatter(
locale: self::LOCALE,
dateType: IntlDateFormatter::FULL,
timeType: IntlDateFormatter::FULL,
timezone: null,
calendar: IntlDateFormatter::GREGORIAN,
pattern: $pattern
);
}

public static function getMonthYear(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
static $formatter = self::createFormatter("MMMM yyyy");
return $formatter->format($timestamp);
}

public static function getShortDate(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
static $formatter = self::createFormatter("dd MMM yyyy");
return $formatter->format($timestamp);
}

public static function getShortDateWithTime(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
static $formatter = self::createFormatter("dd MMM yyyy HH:mm:ss");
return $formatter->format($timestamp);
}

public static function getLongDate(IntlCalendar|DateTimeInterface|array|string|int|float $timestamp) {
static $formatter = self::createFormatter("dd 'de' MMMM 'de' yyyy");
return $formatter->format($timestamp);
}
}
8 changes: 4 additions & 4 deletions src/inc/incidents.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ public static function add($worker, $type, $details, $iday, $begins, $ends, $cre

if (!count($to)) return 0;

$subject = "Incidencia del tipo \"".security::htmlsafe($incidenttype["name"])."\" creada para ".security::htmlsafe($workerName)." el ".strftime("%d %b %Y", $sday);
$subject = "Incidencia del tipo \"".security::htmlsafe($incidenttype["name"])."\" creada para ".security::htmlsafe($workerName)." el ".date::getShortDate($sday);
$body = mail::bodyTemplate("<p>Hola,</p>
<p>Este es un mensaje automático para avisarte de que ".security::htmlsafe(people::userData("name"))." ha introducido la siguiente incidencia en el sistema de registro horario:</p>
<ul>
<li><b>Trabajador:</b> ".security::htmlsafe($workerName)."</li>
<li><b>Motivo:</b> ".security::htmlsafe($incidenttype["name"])."</li>
<li><b>Fecha:</b> ".strftime("%d %b %Y", $sday)." ".(($sbegins == 0 && $sends == self::ENDOFDAY) ? "(todo el día)": schedules::sec2time($sbegins)."-".schedules::sec2time($sends))."</li>".
<li><b>Fecha:</b> ".date::getShortDate($sday)." ".(($sbegins == 0 && $sends == self::ENDOFDAY) ? "(todo el día)": schedules::sec2time($sbegins)."-".schedules::sec2time($sends))."</li>".
(!empty($details) ? "<li><b>Observaciones:</b> <span style='white-space: pre-wrap;'>".security::htmlsafe($details)."</span></li>" : "").
"</ul>
<p style='font-size: 11px;'>Has recibido este mensaje porque estás configurado como persona responsable de la categoría a la que pertenece este trabajador o eres el administrador del sistema.</p>");
Expand Down Expand Up @@ -568,9 +568,9 @@ public static function verify($id, $value, $confirmedby = "ME") {
"email" => $workerEmail,
"name" => $workerName
)];
$subject = "Incidencia del ".strftime("%d %b %Y", $incident["day"])." ".($value == 1 ? "verificada" : "rechazada");
$subject = "Incidencia del ".date::getShortDate($incident["day"])." ".($value == 1 ? "verificada" : "rechazada");
$body = mail::bodyTemplate("<p>Bienvenido ".security::htmlsafe($workerName).",</p>
<p>Este es un mensaje automático para avisarte de que la incidencia que introduciste para el día ".strftime("%d de %B de %Y", $incident["day"])." ha sido ".($value == 1 ? "aceptada" : "rechazada").".</p><p>Puedes ver el estado de todas tus incidencias en el <a href='".security::htmlsafe($conf["fullPath"])."'>aplicativo web</a>.</p>");
<p>Este es un mensaje automático para avisarte de que la incidencia que introduciste para el día ".date::getLongDate($incident["day"])." ha sido ".($value == 1 ? "aceptada" : "rechazada").".</p><p>Puedes ver el estado de todas tus incidencias en el <a href='".security::htmlsafe($conf["fullPath"])."'>aplicativo web</a>.</p>");

mail::send($to, [], $subject, $body);
}
Expand Down
2 changes: 1 addition & 1 deletion src/inc/incidentsView.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static function renderIncidents(&$incidents, &$companies, $scrollable = f
<?php
}
?>
<td class="can-strike"><?=strftime("%d %b %Y", $incident["day"])." ".security::htmlsafe($incident["allday"] ? "(todo el día)" : schedules::sec2time($incident["begins"])."-".schedules::sec2time($incident["ends"]))?></td>
<td class="can-strike"><?=date::getShortDate($incident["day"])." ".security::htmlsafe($incident["allday"] ? "(todo el día)" : schedules::sec2time($incident["begins"])."-".schedules::sec2time($incident["ends"]))?></td>
<td>
<a href="dynamic/editincidentcomment.php?id=<?=(int)$incident["id"]?>&continue=<?=$safeContinueUrl?>" data-dyndialog-href="dynamic/editincidentcomment.php?id=<?=(int)$incident["id"]?>&continue=<?=$safeContinueUrl?>" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect" title="Ver/editar las observaciones"><i class="material-icons icon"><?=(empty($incident["details"]) && empty($incident["workerdetails"]) ? "mode_" : "")?>comment</i></a>
<span<?=($attachments > 0 ? ' class="mdl-badge mdl-badge--overlap" data-badge="'.$attachments.'"' : '')?>><a href="dynamic/incidentattachments.php?id=<?=(int)$incident["id"]?>&continue=<?=$safeContinueUrl?>" data-dyndialog-href="dynamic/incidentattachments.php?id=<?=(int)$incident["id"]?>&continue=<?=$safeContinueUrl?>" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect" title="Ver/gestionar los archivos adjuntos"><i class="material-icons icon">attach_file</i></a></span>
Expand Down
2 changes: 1 addition & 1 deletion src/inc/registryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function renderRegistry(&$registry, &$companies, $scrollable = fal
<?php
}
?>
<td class="can-strike"><?=strftime("%d %b %Y", $record["day"])?></td>
<td class="can-strike"><?=date::getShortDate($record["day"])?></td>
<td class="centered can-strike"><?=schedules::sec2time($record["beginswork"])." - ".schedules::sec2time($record["endswork"])?></td>
<td class="centered can-strike"><?=(intervals::measure($breakfastInt) == 0 ? "-" : ($isForWorker ? export::sec2hours(intervals::measure($breakfastInt)) : schedules::sec2time($record["beginsbreakfast"])." - ".schedules::sec2time($record["endsbreakfast"])))?></td>
<td class="centered can-strike"><?=(intervals::measure($lunchInt) == 0 ? "-" : ($isForWorker ? export::sec2hours(intervals::measure($lunchInt)) : schedules::sec2time($record["beginslunch"])." - ".schedules::sec2time($record["endslunch"])))?></td>
Expand Down

0 comments on commit eaee4a9

Please sign in to comment.