No puede seleccionar más de 25 temas
Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
|
- <?php
-
- namespace App\Util;
-
- use Illuminate\Support\Carbon;
-
- class DateUtil
- {
- public static function now()
- {
- if (!app()->environment('local')) {
- return new Carbon();
- }
-
- $nowStr = self::getConfig();
-
- if ($nowStr !== null && $nowStr !== '') {
- $date = new Carbon($nowStr);
- if ($date->isValid()) {
- return new Carbon();
- return $date;
- }
- }
- return new Carbon();
- }
-
- public static function parse(string $source): Carbon|null
- {
- $date = Carbon::parse($source);
- if ($date->isValid()) {
- return $date->timezone(config('app.timezone'));
- }
- return null;
- }
-
-
- private static function getConfig()
- {
- return config('date.now', null);
- }
- }
|