22
33namespace Yudhatp \Helpers ;
44
5+ use Carbon \Carbon ;
6+ use DateTime ;
7+
58class Helpers
69{
10+
11+ //source from https://https://gist.github.com/matriphe/3103ec578ec556bad5047b378520f070
12+ public static function indonesianPoliceNumberformat ($ string )
13+ {
14+ $ string = strtoupper (trim ($ string ));
15+
16+ $ pattern = '/^([A-Z]{1,3})(\s|-)*([1-9][0-9]{0,3})(\s|-)*([A-Z]{0,3}|[1-9][0-9]{1,2})$/i ' ;
17+ if (preg_match ($ pattern , $ string )) {
18+ return trim (strtoupper (preg_replace ($ pattern , '$1 $3 $5 ' , $ string )));
19+ }
20+
21+ // militer dan kepolisian
22+ $ pattern = '/^([0-9]{1,5})(\s|-)*([0-9]{2}|[IVX]{1,5})*/ ' ;
23+ if (preg_match ($ pattern , $ string )) {
24+ return trim (strtoupper (preg_replace ($ pattern , '$1-$3 ' , $ string )));
25+ }
26+
27+ return null ;
28+ }
29+
30+ public static function addDays ($ date , $ day ){
31+ return Carbon::createFromFormat ('Y-m-d ' ,$ date )->addDays ($ day )->toDateString ();
32+ }
33+
34+ public static function indonesianFormatDecimal ($ number ){
35+ $ temp = str_replace ('. ' ,'' ,$ number );
36+ $ temp = str_replace (', ' ,'. ' ,$ temp );
37+ return $ temp ;
38+ }
39+
40+ public static function generatePassword ($ char ) {
41+ $ tmp = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz ' ;
42+ return substr (str_shuffle ($ tmp ), 0 , $ char );
43+ }
44+
45+ public static function isWeekend ($ date ){
46+ $ day = date ('D ' , strtotime ($ date ));
47+ if ($ day == "Sat " || $ day == "Sun " ){
48+ return true ;
49+ }else {
50+ return false ;
51+ }
52+ }
53+
54+ public static function getAgeIndonesian ($ birthdate ){
55+ $ tmp = new DateTime ($ birthdate );
56+ $ curdate = new DateTime ();
57+ $ diff = $ tmp ->diff ($ curdate );
58+ $ year = $ diff ->y ;
59+ $ month = $ diff ->m ;
60+ $ day = $ diff ->d ;
61+ return $ year ." Tahun, " .$ month ." Bulan, " .$ day ." Hari " ;
62+ }
63+
764 public static function indonesianMonthName ($ date ) {
865 $ date = date_create ($ date );
966 $ month = date_format ($ date ,"n " );
@@ -29,23 +86,23 @@ public static function terbilang($nilai) {
2986 if ($ nilai < 12 ) {
3087 $ temp = " " . $ huruf [$ nilai ];
3188 } else if ($ nilai <20 ) {
32- $ temp = $ this -> terbilang ($ nilai - 10 ). " Belas " ;
89+ $ temp = static :: terbilang ($ nilai - 10 ). " Belas " ;
3390 } else if ($ nilai < 100 ) {
34- $ temp = $ this -> terbilang ($ nilai /10 )." Puluh " . $ this -> terbilang ($ nilai % 10 );
91+ $ temp = static :: terbilang ($ nilai /10 )." Puluh " . static :: terbilang ($ nilai % 10 );
3592 } else if ($ nilai < 200 ) {
36- $ temp = " Seratus " . $ this -> terbilang ($ nilai - 100 );
93+ $ temp = " Seratus " . static :: terbilang ($ nilai - 100 );
3794 } else if ($ nilai < 1000 ) {
38- $ temp = $ this -> terbilang ($ nilai /100 ) . " Ratus " . $ this -> terbilang ($ nilai % 100 );
95+ $ temp = static :: terbilang ($ nilai /100 ) . " Ratus " . static :: terbilang ($ nilai % 100 );
3996 } else if ($ nilai < 2000 ) {
40- $ temp = " Seribu " . $ this -> terbilang ($ nilai - 1000 );
97+ $ temp = " Seribu " . static :: terbilang ($ nilai - 1000 );
4198 } else if ($ nilai < 1000000 ) {
42- $ temp = $ this -> terbilang ($ nilai /1000 ) . " Ribu " . $ this -> terbilang ($ nilai % 1000 );
99+ $ temp = static :: terbilang ($ nilai /1000 ) . " Ribu " . static :: terbilang ($ nilai % 1000 );
43100 } else if ($ nilai < 1000000000 ) {
44- $ temp = $ this -> terbilang ($ nilai /1000000 ) . " Juta " . $ this -> terbilang ($ nilai % 1000000 );
101+ $ temp = static :: terbilang ($ nilai /1000000 ) . " Juta " . static :: terbilang ($ nilai % 1000000 );
45102 } else if ($ nilai < 1000000000000 ) {
46- $ temp = $ this -> terbilang ($ nilai /1000000000 ) . " Milyar " . $ this -> terbilang (fmod ($ nilai ,1000000000 ));
103+ $ temp = static :: terbilang ($ nilai /1000000000 ) . " Milyar " . static :: terbilang (fmod ($ nilai ,1000000000 ));
47104 } else if ($ nilai < 1000000000000000 ) {
48- $ temp = $ this -> terbilang ($ nilai /1000000000000 ) . " Trilyun " . $ this -> terbilang (fmod ($ nilai ,1000000000000 ));
105+ $ temp = static :: terbilang ($ nilai /1000000000000 ) . " Trilyun " . static :: terbilang (fmod ($ nilai ,1000000000000 ));
49106 }
50107 return $ temp ;
51108 }
0 commit comments