-
Notifications
You must be signed in to change notification settings - Fork 3
558 twig filters voor datums #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4d3259e
8bd6b3c
075f32f
7e55d51
585b012
61df026
fcc1540
d94a3ca
4d7a140
b626f8e
aa32e0e
255e510
287de72
fb45bab
8f6c411
af4575f
1bec8cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,10 +70,8 @@ public static function getDate(int $timestamp): string | |
| return ''; | ||
| } | ||
|
|
||
| // get user setting for long dates | ||
| $format = Authentication::getUser()->getSetting('date_format'); | ||
| $format = 'j F Y'; | ||
|
|
||
| // format the date according the user his settings | ||
| return SpoonDate::getDate($format, $timestamp, BackendLanguage::getInterfaceLanguage()); | ||
| } | ||
|
|
||
|
|
@@ -91,10 +89,8 @@ public static function getLongDate(int $timestamp): string | |
| return ''; | ||
| } | ||
|
|
||
| // get user setting for long dates | ||
| $format = Authentication::getUser()->getSetting('datetime_format'); | ||
| $format = 'j F Y H:i'; | ||
|
|
||
| // format the date according the user his settings | ||
| return SpoonDate::getDate($format, $timestamp, BackendLanguage::getInterfaceLanguage()); | ||
| } | ||
|
|
||
|
|
@@ -112,10 +108,8 @@ public static function getTime(int $timestamp): string | |
| return ''; | ||
| } | ||
|
|
||
| // get user setting for long dates | ||
| $format = Authentication::getUser()->getSetting('time_format'); | ||
| $format = 'H:i'; | ||
|
|
||
| // format the date according the user his settings | ||
| return SpoonDate::getDate($format, $timestamp, BackendLanguage::getInterfaceLanguage()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventueel ook al SpoonDate weghalen. Als je dat in apart ticket gaat doen, mag je dit negeren.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ja ik heb een aparte taak aangemaakt daarvoor |
||
| } | ||
|
|
||
|
|
@@ -129,7 +123,7 @@ public static function getTime(int $timestamp): string | |
| public static function getTimeAgo(int $timestamp): string | ||
| { | ||
| // get user setting for long dates | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment weghalen
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| $format = Authentication::getUser()->getSetting('datetime_format'); | ||
| $format = 'j F Y H:i'; | ||
|
|
||
| // get the time ago as a string | ||
| $timeAgo = SpoonDate::getTimeAgo($timestamp, BackendLanguage::getInterfaceLanguage(), $format); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| use Backend\Core\Engine\Model as BackendModel; | ||
| use Common\Core\Twig\Extensions\BaseTwigModifiers; | ||
| use Backend\Core\Language\Language as BackendLanguage; | ||
| use SpoonDate; | ||
| use IntlDateFormatter; | ||
| use function Symfony\Component\String\s; | ||
|
|
||
| /** | ||
|
|
@@ -23,15 +23,20 @@ class TemplateModifiers extends BaseTwigModifiers | |
| */ | ||
| public static function formatDate($var): string | ||
| { | ||
| // get setting | ||
| $format = Authentication::getUser()->getSetting('date_format'); | ||
|
jonasdekeukelaere marked this conversation as resolved.
|
||
|
|
||
| if ($var instanceof \DateTime) { | ||
| $var = $var->getTimestamp(); | ||
| } | ||
|
|
||
| // format the date | ||
| return SpoonDate::getDate($format, (int) $var, BackendLanguage::getInterfaceLanguage()); | ||
| $date = new IntlDateFormatter( | ||
| BackendLanguage::getInterfaceLanguage(), | ||
| IntlDateFormatter::SHORT, | ||
| IntlDateFormatter::NONE, | ||
| null, | ||
| null, | ||
| 'dd MMMM yyyy' | ||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||
| )->format((int) $var); | ||
|
|
||
| return $date; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -44,15 +49,21 @@ public static function formatDate($var): string | |
| */ | ||
| public static function formatDateTime($var): string | ||
| { | ||
| // get setting | ||
| $format = Authentication::getUser()->getSetting('datetime_format'); | ||
|
jonasdekeukelaere marked this conversation as resolved.
|
||
|
|
||
| if ($var instanceof \DateTime) { | ||
| $var = $var->getTimestamp(); | ||
| } | ||
|
|
||
| // format the date | ||
| return SpoonDate::getDate($format, (int) $var, BackendLanguage::getInterfaceLanguage()); | ||
| $date = new IntlDateFormatter( | ||
| BackendLanguage::getInterfaceLanguage(), | ||
| IntlDateFormatter::SHORT, | ||
| IntlDateFormatter::SHORT, | ||
| null, | ||
| null, | ||
| 'dd MMMM yyyy HH:mm' | ||
| )->format((int) $var); | ||
|
|
||
| return $date; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -114,23 +125,28 @@ public static function formatNumber(float $number, ?int $decimals = null): strin | |
|
|
||
| /** | ||
| * Format a UNIX-timestamp as a date | ||
| * syntax: {{ $var|formatdate }} | ||
| * syntax: {{ $var|formattime }} | ||
| * | ||
| * @param int|\DateTime $var The UNIX-timestamp to format. | ||
| * | ||
| * @return string | ||
| */ | ||
| public static function formatTime($var): string | ||
| { | ||
| // get setting | ||
| $format = Authentication::getUser()->getSetting('time_format'); | ||
|
jonasdekeukelaere marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem hier.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is er dus uit |
||
|
|
||
| if ($var instanceof \DateTime) { | ||
| $var = $var->getTimestamp(); | ||
| } | ||
|
|
||
| // format the date | ||
| return SpoonDate::getDate($format, (int) $var, BackendLanguage::getInterfaceLanguage()); | ||
| $date = new IntlDateFormatter( | ||
| BackendLanguage::getInterfaceLanguage(), | ||
| IntlDateFormatter::NONE, | ||
| IntlDateFormatter::SHORT, | ||
| null, | ||
| null, | ||
| 'HH:mm' | ||
| )->format((int) $var); | ||
|
|
||
| return $date; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventueel ook al SpoonDate weghalen. Als je dat in apart ticket gaat doen, mag je dit negeren.