Snapshot of main at 9f39a6e1e (2026-11-02)
This commit is contained in:
commit
6ccf1792d7
2580 files changed
+1040202
No files matched your search
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Format the given number of minutes into a time format string.
|
||||
* Minutes are used in the database to record currency.
|
||||
*
|
||||
* @param int $minutes The number of minutes to format.
|
||||
* @return string The formatted time string.
|
||||
*/
|
||||
|
||||
function tbFormat($minutes)
|
||||
{
|
||||
$isNegative = $minutes < 0;
|
||||
$minutes = abs($minutes);
|
||||
|
||||
$wholeHours = intdiv($minutes, 60);
|
||||
$restMinutes = sprintf("%02d", $minutes % 60);
|
||||
|
||||
// Group the hours (e.g. 12223 -> 12.223). Default '' keeps the previous
|
||||
// unseparated output for platforms that don't configure one — note
|
||||
// platform_trans() returns the key itself when no default is passed.
|
||||
$thousandSeparator = platform_trans('platform_currency_thousand_separator', null, '');
|
||||
if ($thousandSeparator !== '') {
|
||||
$wholeHours = number_format($wholeHours, 0, '', $thousandSeparator);
|
||||
}
|
||||
|
||||
$currencySymbol = platform_currency_symbol();
|
||||
$timeValue = ($isNegative ? '-' : '') . $wholeHours . ':' . $restMinutes;
|
||||
|
||||
// Check if currency symbol should be at the end (default is start)
|
||||
$positionEnd = platform_trans('platform_currency_position_end', null, false);
|
||||
|
||||
if ($positionEnd) {
|
||||
$formattedTime = $timeValue . ' ' . $currencySymbol;
|
||||
} else {
|
||||
$formattedTime = $currencySymbol . ' ' . $timeValue;
|
||||
}
|
||||
|
||||
return $formattedTime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts a time string in the format "HHH:MM" to minutes.
|
||||
*
|
||||
* @param string $hhh_mm The time string to convert.
|
||||
* @return int The time in minutes.
|
||||
*/
|
||||
|
||||
function dbFormat($hhh_mm)
|
||||
{
|
||||
list($wholeHours, $restMinutes) = explode(':', $hhh_mm);
|
||||
|
||||
// Check if the wholeHours part is negative
|
||||
$isNegative = $wholeHours < 0;
|
||||
// Convert the values to absolute for calculation
|
||||
$wholeHours = abs($wholeHours);
|
||||
$restMinutes = abs($restMinutes);
|
||||
// Calculate the total minutes
|
||||
$minutes = ($wholeHours * 60) + $restMinutes;
|
||||
// Adjust the sign if the original value was negative
|
||||
return $isNegative ? -$minutes : $minutes;
|
||||
}
|
||||
|
||||
|
||||
function hoursAndMinutes($time, $format = '%02d:%02d')
|
||||
// Usage: echo hoursAndMinutes('188', '%02d Hours, %02d Minutes');
|
||||
// this will output 3 Hours, 8 Minutes
|
||||
// hoursAndMinutes('188', '%02dH,%02dM');
|
||||
// will output 3H,8M
|
||||
{
|
||||
if ($time < 1) {
|
||||
return;
|
||||
}
|
||||
$hours = floor($time / 60);
|
||||
$minutes = ($time % 60);
|
||||
return sprintf($format, $hours, $minutes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert days to human-readable format
|
||||
* Returns format like "2 weeks", "3 months", "1 year"
|
||||
* Uses 30 days = 1 month, 7 days = 1 week
|
||||
*
|
||||
* @param int $days The number of days to convert
|
||||
* @return string The human-readable format
|
||||
*/
|
||||
/**
|
||||
* Return the translated display name for an account.
|
||||
* Looks up the translation key "messages.{name}_account".
|
||||
* Falls back to ucfirst of the raw DB name when no translation exists.
|
||||
*
|
||||
* @param string $rawName The raw account name from the database (e.g. "personal 2")
|
||||
* @return string
|
||||
*/
|
||||
function account_name(string $rawName): string
|
||||
{
|
||||
$key = 'messages.' . $rawName . '_account';
|
||||
$translated = __($key);
|
||||
// __() returns the key itself when no translation is found
|
||||
return $translated === $key ? ucfirst($rawName) : $translated;
|
||||
}
|
||||
|
||||
|
||||
function daysToHumanReadable($days)
|
||||
{
|
||||
if ($days < 7) {
|
||||
return $days . ' ' . trans_choice('day|days', $days);
|
||||
} elseif ($days < 30) {
|
||||
$weeks = round($days / 7);
|
||||
return $weeks . ' ' . trans_choice('week|weeks', $weeks);
|
||||
} elseif ($days < 365) {
|
||||
$months = round($days / 30);
|
||||
return $months . ' ' . trans_choice('month|months', $months);
|
||||
} else {
|
||||
$years = round($days / 365);
|
||||
return $years . ' ' . trans_choice('year|years', $years);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user