Skip to content

Commit 72fc0c6

Browse files
committed
fix and add function
1 parent a178f17 commit 72fc0c6

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Laravel Helpers
22

3-
Collection of (9) helper functions for laravel.
3+
Collection of (12) helper functions for laravel.
44

55
## Installation
66

@@ -14,15 +14,25 @@ composer require yudhatp/laravel-helpers
1414

1515
```php
1616
use Yudhatp\Helpers\Helpers;
17-
Helpers::terbilang("2000"); //Dua Ribu
18-
Helpers::indonesianMonthName("2022-11-28"); //28 November 2022
19-
Helpers::indonesianShortMonthName("2022-11-28"); //28 Nov 22
17+
18+
//date helpers
19+
Helpers::indonesianDate("2022-11-28"); //28 November 2022
20+
Helpers::indonesianShortDate("2022-11-28"); //28 Nov 22
21+
Helpers::indonesianDayName("2022-11-29"); //Selasa
22+
Helpers::indonesianMonthName("2022-11-29"); //November
2023
Helpers::getAgeIndonesian("1945-08-17"); //77 Tahun, 3 Bulan, 12 Hari
2124
Helpers::isWeekend("2022-11-29"); //false
22-
Helpers::generatePassword(8); //EPp218kR
23-
Helpers::indonesianFormatDecimal("2.100,00"); //2100.00
2425
Helpers::addDays("2022-11-28",2); //2022-11-30
26+
27+
//number helpers
28+
Helpers::terbilang("2000"); //Dua Ribu
29+
Helpers::indonesianFormatDecimal("2,000.50"); //2.000,50
30+
31+
//other helpers
2532
Helpers::indonesianPoliceNumberformat("B123XYZ"); //B 123 XYZ
33+
Helpers::generatePassword(8); //EPp218kR
34+
Helpers::filenameWithTimestamp("test","jpg"); //1669704266_test.jpg
35+
Helpers::randomHexColor(); //#D15AF0
2636

2737
//blade
2838
{{ (new \Yudhatp\Helpers\Helpers)->indonesianMonthName("2022-11-28") }}
@@ -34,7 +44,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re
3444

3545
## Credits
3646

37-
- [@matriphe](https://https://gist.github.com/matriphe/3103ec578ec556bad5047b378520f070)
47+
- indonesianPoliceNumberformat - [@matriphe](https://https://gist.github.com/matriphe/3103ec578ec556bad5047b378520f070)
3848

3949

4050
## License

src/Helpers.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,27 @@
88
class Helpers
99
{
1010

11-
//source from https://https://gist.github.com/matriphe/3103ec578ec556bad5047b378520f070
11+
public static function randomHexColor(){
12+
return '#' . substr(str_shuffle('ABCDEF0123456789'), 0, 6);
13+
}
14+
15+
public static function filenameWithTimestamp($name, $extention){
16+
$timestamp = time();
17+
return $timestamp. "_" . $name . ".".$extention;
18+
}
19+
20+
public static function indonesianMonthName($date) {
21+
$tmp = date_format(new DateTime($date),"n");
22+
$month = array (1 => 'Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
23+
return $month[$tmp];
24+
}
25+
26+
public static function indonesianDayName($date) {
27+
$tmp = date_format(new DateTime($date),"w");
28+
$day = array (1 => 'Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu');
29+
return $day[$tmp];
30+
}
31+
1232
public static function indonesianPoliceNumberformat($string)
1333
{
1434
$string = strtoupper(trim($string));
@@ -26,18 +46,20 @@ public static function indonesianPoliceNumberformat($string)
2646

2747
return null;
2848
}
29-
49+
3050
public static function addDays($date, $day){
3151
return Carbon::createFromFormat('Y-m-d',$date)->addDays($day)->toDateString();
3252
}
33-
53+
3454
public static function indonesianFormatDecimal($number){
35-
$temp = str_replace('.','',$number);
55+
$temp = str_replace('.','-',$number);
3656
$temp = str_replace(',','.',$temp);
57+
$temp = str_replace('-',',',$temp);
3758
return $temp;
3859
}
3960

40-
public static function generatePassword($char) {
61+
public static function generatePassword($char)
62+
{
4163
$tmp = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz';
4264
return substr(str_shuffle($tmp), 0, $char);
4365
}
@@ -60,8 +82,7 @@ public static function getAgeIndonesian($birthdate){
6082
$day = $diff->d;
6183
return $year." Tahun, ".$month." Bulan, ".$day." Hari";
6284
}
63-
64-
public static function indonesianMonthName($date) {
85+
public static function indonesianDate($date) {
6586
$date = date_create($date);
6687
$month = date_format($date,"n");
6788
$day = date_format($date,"d");
@@ -70,7 +91,7 @@ public static function indonesianMonthName($date) {
7091
return $day.' '.$name[$month].' '.$year;
7192
}
7293

73-
public static function indonesianShortMonthName($date) {
94+
public static function indonesianShortDate($date) {
7495
$date = date_create($date);
7596
$month = date_format($date,"n");
7697
$day = date_format($date,"d");

0 commit comments

Comments
 (0)