summaryrefslogtreecommitdiff
path: root/protected/components/Format.php
diff options
context:
space:
mode:
Diffstat (limited to 'protected/components/Format.php')
-rw-r--r--protected/components/Format.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/protected/components/Format.php b/protected/components/Format.php
new file mode 100644
index 0000000..1be259f
--- /dev/null
+++ b/protected/components/Format.php
@@ -0,0 +1,35 @@
+<?php
+class Format {
+ public static function currency($value, $currency = 'EUR') {
+ return Yii::app()->locale->numberFormatter->formatCurrency($value, $currency);
+ }
+
+ public static function number($value, $einheit = '') {
+ return Yii::app()->locale->numberFormatter->formatDecimal($value).' '.$einheit;
+ }
+
+ public static function decimal($value) {
+ return Yii::app()->locale->numberFormatter->formatDecimal($value);
+ }
+
+ public static function percentage($value) {
+ return Yii::app()->locale->numberFormatter->formatPercentage($value);
+ }
+
+ public static function dbDateTime($value) {
+ return Yii::app()->dateFormatter->format('yyyy-MM-dd HH:mm', CDateTimeParser::parse($value, 'dd.MM.yyyy HH:mm'));
+ }
+
+ public static function displayDateTime($value) {
+ $checkvalue = CDateTimeParser::parse($value, 'dd.MM.yyyy HH:mm');
+ if (!empty($checkvalue)) {
+ return $value;
+ }
+ $timestamp = CDateTimeParser::parse($value, 'yyyy-MM-dd HH:mm:ss');
+ Yii::trace('Input value: '.$value. ' -> output timestamp: '.$timestamp, 'ccwn.astaf.format');
+ if ($timestamp) {
+ return Yii::app()->dateFormatter->format('dd.MM.yyyy HH:mm', $timestamp);
+ }
+ return null;
+ }
+} \ No newline at end of file