summaryrefslogtreecommitdiff
path: root/protected/components/Format.php
blob: a4802e2244038f462aad64e6e7107c014f3941b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?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, $pattern = null) {
		if ($pattern !== null) {
			return Yii::app()->locale->numberFormatter->formatDecimal($value);
		} else {
			return Yii::app()->locale->numberFormatter->format($pattern, $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;
	}
}