Last active
March 20, 2021 16:16
-
-
Save herusdianto/80618e91999674acd456 to your computer and use it in GitHub Desktop.
Laravel Carbon Difference For Humans Bahasa Indonesia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/config/app.php | |
return array( | |
// ... konfigurasi lainnya ... | |
'timezone' => 'Asia/Jakarta', | |
'locale' => 'id', | |
'providers' => array( | |
// ... service provider lainnya ... | |
'Laravelrus\LocalizedCarbon\LocalizedCarbonServiceProvider', | |
), | |
'aliases' => array( | |
// ... alias lainnya ... | |
'LocalizedCarbon' => 'Laravelrus\LocalizedCarbon\LocalizedCarbon', | |
'DiffFormatter' => 'Laravelrus\LocalizedCarbon\DiffFactoryFacade', | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "laravel/laravel", | |
"description": "The Laravel Framework.", | |
"keywords": ["framework", "laravel"], | |
"license": "MIT", | |
"type": "project", | |
"require": { | |
"laravel/framework": "4.2.8", | |
"laravelrus/localized-carbon": "1.3.3" | |
}, | |
"autoload": { | |
"classmap": [ | |
"app/commands", | |
"app/controllers", | |
"app/models", | |
"app/database/migrations", | |
"app/database/seeds", | |
"app/tests/TestCase.php" | |
], | |
"psr-4": { | |
"Acme\\": "app/Acme" | |
} | |
}, | |
"scripts": { | |
"post-install-cmd": [ | |
"php artisan clear-compiled", | |
"php artisan optimize" | |
], | |
"post-update-cmd": [ | |
"php artisan clear-compiled", | |
"php artisan optimize" | |
], | |
"post-create-project-cmd": [ | |
"php artisan key:generate" | |
] | |
}, | |
"config": { | |
"preferred-install": "dist" | |
}, | |
"minimum-stability": "stable" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/start/global.php | |
// ... isi file global lainnya ... | |
DiffFormatter::extend('id', 'Acme\\DiffFormatters\\IdDiffFormatter'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Acme\DiffFormatters; | |
// app/Acme/DiffFormatters/IdDiffFormatter.php | |
use Laravelrus\LocalizedCarbon\DiffFormatters\DiffFormatterInterface; | |
use Lang; | |
class IdDiffFormatter implements DiffFormatterInterface { | |
/** | |
* format diffForHumans | |
* | |
* @param bool $isNow | |
* @param bool $isFuture | |
* @param int $delta | |
* @param int $unit | |
* @return string | |
*/ | |
public function format($isNow, $isFuture, $delta, $unit) | |
{ | |
$local = Lang::choice("units.".$unit, $delta, array(), 'id'); | |
$text = $delta.' '.$local; | |
if ($isNow) | |
{ | |
$text .= ($isFuture) ? ' dari sekarang' : ' yang lalu'; | |
return $text; | |
} | |
$text .= ($isFuture) ? ' setelah' : ' sebelum'; | |
return $text; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/lang/id/units.php | |
return [ | |
'second' => 'detik', | |
'minute' => 'menit', | |
'hour' => 'jam', | |
'day' => 'hari', | |
'week' => 'minggu', | |
'month' => 'bulan', | |
'year' => 'tahun', | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment