|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Yudhatp\Helpers; |
| 4 | + |
| 5 | +class Helpers |
| 6 | +{ |
| 7 | + public static function indonesianMonthName($date) { |
| 8 | + $date = date_create($date); |
| 9 | + $month = date_format($date,"n"); |
| 10 | + $day = date_format($date,"d"); |
| 11 | + $year = date_format($date,"Y"); |
| 12 | + $name = array (1 => 'Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember'); |
| 13 | + return $day.' '.$name[$month].' '.$year; |
| 14 | + } |
| 15 | + |
| 16 | + public static function indonesianShortMonthName($date) { |
| 17 | + $date = date_create($date); |
| 18 | + $month = date_format($date,"n"); |
| 19 | + $day = date_format($date,"d"); |
| 20 | + $year = date_format($date,"y"); |
| 21 | + $name = array (1 => 'Jan','Feb','Mar','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Des'); |
| 22 | + return $day.' '.$name[$month].' '.$year; |
| 23 | + } |
| 24 | + |
| 25 | + public function terbilang($nilai) { |
| 26 | + $nilai = abs($nilai); |
| 27 | + $huruf = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas"); |
| 28 | + $temp = ""; |
| 29 | + if ($nilai < 12) { |
| 30 | + $temp = " ". $huruf[$nilai]; |
| 31 | + } else if ($nilai <20) { |
| 32 | + $temp = $this->terbilang($nilai - 10). " Belas"; |
| 33 | + } else if ($nilai < 100) { |
| 34 | + $temp = $this->terbilang($nilai/10)." Puluh". $this->terbilang($nilai % 10); |
| 35 | + } else if ($nilai < 200) { |
| 36 | + $temp = " Seratus" . $this->terbilang($nilai - 100); |
| 37 | + } else if ($nilai < 1000) { |
| 38 | + $temp = $this->terbilang($nilai/100) . " Ratus" . $this->terbilang($nilai % 100); |
| 39 | + } else if ($nilai < 2000) { |
| 40 | + $temp = " Seribu" . $this->terbilang($nilai - 1000); |
| 41 | + } else if ($nilai < 1000000) { |
| 42 | + $temp = $this->terbilang($nilai/1000) . " Ribu" . $this->terbilang($nilai % 1000); |
| 43 | + } else if ($nilai < 1000000000) { |
| 44 | + $temp = $this->terbilang($nilai/1000000) . " Juta" . $this->terbilang($nilai % 1000000); |
| 45 | + } else if ($nilai < 1000000000000) { |
| 46 | + $temp = $this->terbilang($nilai/1000000000) . " Milyar" . $this->terbilang(fmod($nilai,1000000000)); |
| 47 | + } else if ($nilai < 1000000000000000) { |
| 48 | + $temp = $this->terbilang($nilai/1000000000000) . " Trilyun" . $this->terbilang(fmod($nilai,1000000000000)); |
| 49 | + } |
| 50 | + return $temp; |
| 51 | + } |
| 52 | +} |
0 commit comments