forked from kokonior/PHP-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindoDate.php
58 lines (50 loc) · 1.42 KB
/
indoDate.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/* Dibuat Pada Tanggal : 01-10-2021
* Nama project : Indonesian Date
* Require : PHP_8
* Dibuat Oleh ♡ Yoppy0x100 @hacktoberfest
*/
date_default_timezone_set('Asia/Jakarta');
function toMonth($date) {
$month = match($date) {
'01' => 'Januari',
'02' => 'Februari',
'03' => 'Maret',
'04' => 'April',
'05' => 'Juni',
'06' => 'Juli',
'07' => 'Agustus',
'08' => 'September',
'10' => 'Oktober',
'11' => 'November',
'12' => 'Desember',
default => throw new exception('Can`t Parse Month'),
};
return $month;
}
function toDay($date) {
$date = explode(':', $date);
$day = match($date[1]) {
'Mon' => 'Senin',
'Tue' => 'Selasa',
'Wed' => 'Rabu',
'Thu' => 'Kamis',
'Fri' => 'Jum`at',
'Sat' => 'Sabtu',
'Sun' => 'Minggu',
default => throw new exception('Can`t To Parse Day'),
};
return $day . ', ' . $date[0];
}
/*
var $opt to increase / decrease date format
ex: date now, +1 day = tommorow date
01-10-2021, +2 day = 03-10-2021
*/
function dateIndo($separator='/', $opt=null) {
$date = isset($opt) ? date('d:D-m-Y', strtotime($opt)) : date('D-m-Y');
$parse = explode('-', $date);
return toDay($parse[0]) . $separator . toMonth($parse[1]) . $separator . $parse[2];
}
echo dateIndo(opt: '+10 Day');
// echo dateIndo(' ');