18 $this->dateTimeFormat = strtr($this->dateTimeFormat,[
'[date]' => $this->dateFormat,
'[time]' => $this->timeFormat]);
22 return array_merge(parent::clientConfig(),[
23 'dateFormat' => $this->dateFormat,
24 'timeFormat' => $this->timeFormat,
25 'dateTimeFormat' => $this->dateTimeFormat,
26 'decimalPoint' => $this->decimalPoint,
27 'thousandsSeparator' => $this->thousandsSeparator,
28 'delimiter' => $this->delimiter
33 if(!$value)
return null;
35 return $value ? $value->format($this->dateFormat) :
null;
43 if(\Rsi::nothing($value))
return $value;
45 return $value ? $value->format($this->timeFormat) :
null;
53 if(\Rsi::nothing($value))
return $value;
55 return $value ? $value->format($this->dateTimeFormat) :
null;
63 return \Rsi\Number::formatDuration($value,$this->durationFormat);
67 if(\Rsi::nothing($value))
return $value;
68 return number_format($value,0,$this->decimalPoint,$this->thousandsSeparator);
72 return (
int)str_replace($this->thousandsSeparator,
'',$value);
75 public function formatNumber($value,$decimals =
null,$trim =
null,$zero =
null){
76 if(\Rsi::nothing($value))
return $value;
77 if($decimals ===
null) $decimals = ($index = strpos($value,
'.')) ? strlen($value) - $index - 1 : 0;
78 $value = number_format($value,$decimals,$this->decimalPoint,$this->thousandsSeparator);
79 if($decimals && ($trim !==
null))
80 while(($trim++ < $decimals) && !substr($value,-1)) $value = substr($value,0,-1);
81 if($zero !==
null) $value = preg_replace(
'/' . preg_quote($this->decimalPoint,
'/') .
'0*$/',$zero,$value);
82 return rtrim($value,$this->decimalPoint);
86 $value = str_replace($this->decimalPoint,
'.',str_replace($this->thousandsSeparator,
'',$value));
87 return is_numeric($value) ? ($decimals ===
null ? $value : round($value,$decimals)) :
null;
91 return \Rsi\Str::transform((
new \NumberFormatter($locale,\NumberFormatter::SPELLOUT))->format($value),$format);
95 return \Rsi\Number::toRoman($value) ?: $value;
99 return \Rsi\Number::formatBytes($value,$decimals,$this->decimalPoint,$this->thousandsSeparator);
103 return \Rsi\Number::shorthandBytes($value);