diff --git a/src/installer/index.php b/src/installer/index.php index 54599de..e46c725 100644 --- a/src/installer/index.php +++ b/src/installer/index.php @@ -9,8 +9,8 @@ if (!file_exists(__PRIVATE_DIR . "/vendor/autoload.php")) { die( '
composer update
in the ' .
'' . realpath(__BASE_DIR) . '
directory'
);
diff --git a/src/private/php/Utils/DateUtils.php b/src/private/php/Utils/DateUtils.php
index 0b54011..d7f13fa 100644
--- a/src/private/php/Utils/DateUtils.php
+++ b/src/private/php/Utils/DateUtils.php
@@ -5,12 +5,13 @@ namespace Wruczek\TSWebsite\Utils;
use Wruczek\TSWebsite\Utils\Language\LanguageUtils;
class DateUtils {
+
/**
* Returns current date format based on current user language. If it cannot
* be retrieved, default value is returned
* @return string date format
*/
- public function getDateFormat() {
+ public static function getDateFormat() {
try {
return LanguageUtils::i()->translate("DATE_FORMAT");
} catch (\Exception $e) {
@@ -23,7 +24,7 @@ class DateUtils {
* be retrieved, default value is returned
* @return string time format
*/
- public function getTimeFormat() {
+ public static function getTimeFormat() {
try {
return LanguageUtils::i()->translate("TIME_FORMAT");
} catch (\Exception $e) {
@@ -36,8 +37,8 @@ class DateUtils {
* @param $timestamp
* @return false|string
*/
- public function formatToDate($timestamp) {
- return date($this->getDateFormat(), $timestamp);
+ public static function formatDate($timestamp) {
+ return date(self::getDateFormat(), $timestamp);
}
/**
@@ -45,8 +46,8 @@ class DateUtils {
* @param $timestamp
* @return false|string
*/
- public function formatToTime($timestamp) {
- return date($this->getTimeFormat(), $timestamp);
+ public static function foramtTime($timestamp) {
+ return date(self::getTimeFormat(), $timestamp);
}
/**
@@ -55,63 +56,8 @@ class DateUtils {
* @param string $additional additional date format
* @return false|string
*/
- public function formatToDateTime($timestamp, $additional = "") {
- return date("{$this->getDateFormat()} {$this->getTimeFormat()} $additional", $timestamp);
+ public static function formatDatetime($timestamp, $additional = "") {
+ return date(trim(self::getDateFormat() . ", " . self::getTimeFormat() . " " . $additional), $timestamp);
}
- /**
- * Formats timestamp into "time ago" string
- * For example, timestamp set to 60 seconds ago will return "1 minute ago"
- *
- * Taken from StackOverflow: https://stackoverflow.com/a/18602474
- * @param $timestamp int timestamp with past date
- * @param bool $full if true, full date will be returned. For example "5 hours, 2 minutes, 8 seconds"
- * @return string timestamp formatted to fuzzy date. Marf.
- */
- public function fuzzyDate($timestamp, $full = false) {
- $now = new \DateTime;
- $ago = (new \DateTime)->setTimestamp($timestamp);
-
- $diff = $now->diff($ago);
-
- $diff->w = floor($diff->d / 7);
- $diff->d -= $diff->w * 7;
-
- $string = [
- 'y' => 'year',
- 'm' => 'month',
- 'w' => 'week',
- 'd' => 'day',
- 'h' => 'hour',
- 'i' => 'minute',
- 's' => 'second'
- ];
-
- foreach ($string as $k => &$v) {
- if ($diff->$k) {
- $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
- } else {
- unset($string[$k]);
- }
- }
-
- if (!$full) $string = array_slice($string, 0, 1);
- return $string ? implode(', ', $string) . ' ago' : 'just now';
- }
-
-
- /**
- * Returns fuzzy date with abbreviation showing precise date
- * @see fuzzyDate
- * @param $timestamp
- * @param bool $full
- * @return string
- */
- public function fuzzyDateHTML($timestamp, $full = false) {
- $fuzzyDate = $this->fuzzyDate($timestamp, $full);
- $fullDate = $this->formatToDateTime($timestamp, "T");
-
- return '';
-// return '' . htmlentities($fuzzyDate) . '';
- }
}
diff --git a/src/private/php/Utils/TemplateUtils.php b/src/private/php/Utils/TemplateUtils.php
index 9218df8..95ecf4f 100644
--- a/src/private/php/Utils/TemplateUtils.php
+++ b/src/private/php/Utils/TemplateUtils.php
@@ -27,11 +27,13 @@ class TemplateUtils {
// Add custom filters...
$this->getLatte()->addFilter("fuzzyDateAbbr", function ($s) {
- return new Html('{cannot convert ' . $s . '}');
+ $default = DateUtils::formatDatetime($s);
+ return new Html('' . $default . '');
});
$this->getLatte()->addFilter("fullDate", function ($s) {
- return new Html('{cannot convert ' . $s . '}');
+ $default = DateUtils::formatDatetime($s);
+ return new Html('' . $default . '');
});
$this->getLatte()->addFilter("translate", function ($s, ...$args) {