diff --git a/resources/Js/Handlebars/round.js b/resources/Js/Handlebars/round.js new file mode 100644 index 0000000..5935d4b --- /dev/null +++ b/resources/Js/Handlebars/round.js @@ -0,0 +1,32 @@ +/** + * Handlebars Array Helpers + * + * @source https://github.com/helpers/handlebars-helpers + * + * @package kzarshenas/crazyphp + * @author kekefreedog + * @copyright 2022-2023 Kévin Zarshenas + */ + +/** + * Length + * + * Returns the length of the given string or array. + * + * @param any value + * @param Object options + * + * @return number + */ +module.exports = (value, options) => { + + // Check if array or string + if(typeof value === 'number') + + // Return lenght + return Math.round(value); + + // Return 0 + return value; + +} \ No newline at end of file diff --git a/src/Front/Library/Utility/DateTime.ts b/src/Front/Library/Utility/DateTime.ts index e277ddd..1c5dd27 100644 --- a/src/Front/Library/Utility/DateTime.ts +++ b/src/Front/Library/Utility/DateTime.ts @@ -71,4 +71,37 @@ export default class DateTime { } + /** + * Get Next Day + * + * Return in format YYYY/MM/DD + * + * @param weekday + * @returns string + */ + public static getNextDay = (weekday:1|2|3|4|5|6|7) => { + + // Check week day + if (weekday < 1 || weekday > 7) + + // New error + throw new Error("Invalid weekday number. Please enter a number between 1 (Monday) and 7 (Sunday)."); + + // New date + const today = new Date(); + const todayDayOfWeek = today.getUTCDay(); // Sunday - 0, Monday - 1, etc. + const daysUntilNext = (weekday - todayDayOfWeek + 7) % 7; // Calculate days until the next desired weekday + + // Set the date to the next desired weekday + today.setUTCDate(today.getUTCDate() + daysUntilNext); + + // Format the date as YYYY/MM/DD + const year = today.getUTCFullYear(); + const month = (today.getUTCMonth() + 1).toString().padStart(2, '0'); // Months are zero-indexed + const day = today.getUTCDate().toString().padStart(2, '0'); + + // Return date + return `${year}/${month}/${day}`; + } + } \ No newline at end of file diff --git a/src/Library/File/File.php b/src/Library/File/File.php index 393a060..aace2dc 100644 --- a/src/Library/File/File.php +++ b/src/Library/File/File.php @@ -938,6 +938,8 @@ public static function downloadToTmp(string $url = "", string $tempFileName = "t "jpeg" => "image/jpeg", # Png "png" => "image/png", + # WebP + "webp" => "image/webp", # TBC ... ]; diff --git a/src/Library/Template/Handlebars/Helpers.php b/src/Library/Template/Handlebars/Helpers.php index 2ecc889..e552ed6 100644 --- a/src/Library/Template/Handlebars/Helpers.php +++ b/src/Library/Template/Handlebars/Helpers.php @@ -596,4 +596,27 @@ public static function length($value) { } + /** + * Round + * + * Returns the length of the given string or array. + * + * @param mixed $value + * @param mixed options + */ + public static function round($value) { + + # Check if array + if(is_int($value) || is_float($value) || ctype_digit($value)) + + # Return round value + return round(intval($value)); + + else + + # Return value + return $value; + + } + } \ No newline at end of file