Add remaining project files (exclude ignored folders)
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
function formatIndo($tanggal, $format = 'd F Y') {
|
||||
// Array nama bulan dalam bahasa Indonesia
|
||||
$bulan = array(
|
||||
1 => 'Januari',
|
||||
2 => 'Februari',
|
||||
3 => 'Maret',
|
||||
4 => 'April',
|
||||
5 => 'Mei',
|
||||
6 => 'Juni',
|
||||
7 => 'Juli',
|
||||
8 => 'Agustus',
|
||||
9 => 'September',
|
||||
10 => 'Oktober',
|
||||
11 => 'November',
|
||||
12 => 'Desember'
|
||||
);
|
||||
|
||||
// Mengubah string tanggal ke objek DateTime
|
||||
$date = new DateTime($tanggal);
|
||||
|
||||
// Format bulan dalam bahasa Indonesia
|
||||
$bulanIndo = $bulan[$date->format('n')];
|
||||
|
||||
// Format tanggal sesuai parameter format
|
||||
switch ($format) {
|
||||
case 'd F Y':
|
||||
return $date->format('d') . ' ' . $bulanIndo . ' ' . $date->format('Y');
|
||||
case 'F Y':
|
||||
return $bulanIndo . ' ' . $date->format('Y');
|
||||
default:
|
||||
return $date->format($format);
|
||||
}
|
||||
}
|
||||
|
||||
function penyebut($nilai) {
|
||||
$nilai = abs($nilai);
|
||||
$huruf = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
|
||||
$temp = "";
|
||||
if ($nilai < 12) {
|
||||
$temp = " ". $huruf[$nilai];
|
||||
} else if ($nilai <20) {
|
||||
$temp = penyebut($nilai - 10). " belas";
|
||||
} else if ($nilai < 100) {
|
||||
$temp = penyebut($nilai/10)." puluh". penyebut($nilai % 10);
|
||||
} else if ($nilai < 200) {
|
||||
$temp = " seratus" . penyebut($nilai - 100);
|
||||
} else if ($nilai < 1000) {
|
||||
$temp = penyebut($nilai/100) . " ratus" . penyebut($nilai % 100);
|
||||
} else if ($nilai < 2000) {
|
||||
$temp = " seribu" . penyebut($nilai - 1000);
|
||||
} else if ($nilai < 1000000) {
|
||||
$temp = penyebut($nilai/1000) . " ribu" . penyebut($nilai % 1000);
|
||||
} else if ($nilai < 1000000000) {
|
||||
$temp = penyebut($nilai/1000000) . " juta" . penyebut($nilai % 1000000);
|
||||
} else if ($nilai < 1000000000000) {
|
||||
$temp = penyebut($nilai/1000000000) . " milyar" . penyebut(fmod($nilai,1000000000));
|
||||
} else if ($nilai < 1000000000000000) {
|
||||
$temp = penyebut($nilai/1000000000000) . " trilyun" . penyebut(fmod($nilai,1000000000000));
|
||||
}
|
||||
return $temp;
|
||||
}
|
||||
|
||||
function terbilang($nilai) {
|
||||
if($nilai<0) {
|
||||
$hasil = "minus ". trim(penyebut($nilai));
|
||||
} else {
|
||||
$hasil = trim(penyebut($nilai));
|
||||
}
|
||||
return $hasil;
|
||||
}
|
||||
|
||||
function baseurl($path = '') {
|
||||
// Ambil URL dasar aplikasi
|
||||
$baseurl = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
|
||||
|
||||
// Gabungkan dengan path tambahan jika ada
|
||||
if ($path) {
|
||||
// Menghapus leading slashes dari path untuk menghindari double slashes
|
||||
$path = ltrim($path, '/');
|
||||
// Gabungkan base URL dengan path
|
||||
$baseurl = rtrim($baseurl, '/') . '/' . $path;
|
||||
}
|
||||
|
||||
return $baseurl;
|
||||
}
|
||||
|
||||
function intervalFormat($input) {
|
||||
// Menangkap jumlah dan satuan
|
||||
preg_match('/(\d+)([DHM])/', $input, $matches);
|
||||
|
||||
if (count($matches) !== 3) {
|
||||
return "Format tidak valid";
|
||||
}
|
||||
|
||||
$amount = intval($matches[1]);
|
||||
$unit = strtolower($matches[2]); // Mengubah satuan menjadi huruf kecil
|
||||
|
||||
// Inisialisasi waktu
|
||||
$days = 0;
|
||||
$hours = 0;
|
||||
$minutes = 0;
|
||||
$seconds = 0;
|
||||
|
||||
switch ($unit) {
|
||||
case 'd':
|
||||
$days = $amount;
|
||||
break;
|
||||
case 'h':
|
||||
$hours = $amount;
|
||||
break;
|
||||
case 'm':
|
||||
$minutes = $amount;
|
||||
break;
|
||||
}
|
||||
|
||||
// Format output
|
||||
if ($days > 0) {
|
||||
return sprintf("%d%s%02d:%02d:%02d", $days, $unit, $hours, $minutes, $seconds);
|
||||
} else {
|
||||
return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user