LFT
  • Namespace
  • Class
  • Tree

Namespaces

  • Docoflow
    • Contracts
    • Entity
    • Facades
    • Models
    • Traits
  • Docolight
    • Agno
      • Traits
    • Container
    • Http
      • Contracts
    • Rest
      • Handler
      • Http
    • Support
      • Debug
      • Traits
  • Docotory
    • Traits
  • None

Classes

  • Docoflow\Docoflow
  • Docoflow\Entity\Group
  • Docoflow\Entity\Step
  • Docoflow\Entity\Verificator
  • Docoflow\Facades\Action
  • Docoflow\Facades\Activity
  • Docoflow\Facades\Flo
  • Docoflow\Facades\StateActivity
  • Docoflow\Flo
  • Docoflow\Models\Workflow
  • Docoflow\Models\WorkflowAction
  • Docoflow\Models\WorkflowActivity
  • Docoflow\Models\WorkflowGroups
  • Docoflow\Models\WorkflowNotification
  • Docoflow\Models\WorkflowState
  • Docoflow\Models\WorkflowStateActivity
  • Docoflow\Models\WorkflowStep
  • Docoflow\Models\WorkflowVerificator
  • Docolight
  • Docolight\Agno\AgnoModule
  • Docolight\Container\Container
  • Docolight\Http\Headers
  • Docolight\Http\JsonResponse
  • Docolight\Http\MimeResponse
  • Docolight\Http\Response
  • Docolight\Http\ResponseFactory
  • Docolight\Rest\Handler\RestfulErrorHandler
  • Docolight\Rest\Http\RestFulController
  • Docolight\Support\ActiveRecordWrapper
  • Docolight\Support\Arr
  • Docolight\Support\Carbonate
  • Docolight\Support\ClassLoader
  • Docolight\Support\Collection
  • Docolight\Support\CollectionDataProvider
  • Docolight\Support\Debug\Dumper
  • Docolight\Support\Debug\HtmlDumper
  • Docolight\Support\Facade
  • Docolight\Support\Factory
  • Docolight\Support\Fluent
  • Docolight\Support\Html
  • Docolight\Support\IterablePager
  • Docolight\Support\Repository
  • Docolight\Support\Set
  • Docolight\Support\Str
  • Docotory\Factory

Interfaces

  • Docoflow\Contracts\DocoflowContract
  • Docoflow\Contracts\ValidationStatus
  • Docolight\Http\Contracts\Arrayable

Traits

  • Docoflow\Traits\BulkValidator
  • Docoflow\Traits\Entity
  • Docoflow\Traits\HasMutator
  • Docoflow\Traits\Validable
  • Docolight\Agno\Traits\HasAssetsUrl
  • Docolight\Agno\Traits\HasAutoload
  • Docolight\Support\Traits\Macroable
  • Docotory\Traits\HasFactories

Exceptions

  • Docolight\Container\BindingResolutionException
  • Docotory\ResolvingTypeException

Functions

  • array_add
  • array_build
  • array_collapse
  • array_divide
  • array_dot
  • array_except
  • array_first
  • array_flatten
  • array_forget
  • array_get
  • array_has
  • array_last
  • array_only
  • array_pluck
  • array_pull
  • array_replace_value
  • array_set
  • array_sort
  • array_sort_recursive
  • array_where
  • cache
  • camel_case
  • class_basename
  • class_uses_recursive
  • collect
  • container
  • data_get
  • dd
  • def
  • dump
  • e
  • ends_with
  • fluent
  • get
  • head
  • input
  • last
  • object_get
  • preg_replace_sub
  • request
  • response
  • session
  • snake_case
  • starts_with
  • str_contains
  • str_finish
  • str_is
  • str_limit
  • str_random
  • str_replace_array
  • str_slug
  • studly_case
  • title_case
  • trait_uses_recursive
  • transaction
  • trimtolower
  • value
  • with
  1 <?php
  2 
  3 namespace Docolight\Support;
  4 
  5 use Carbon\Carbon;
  6 
  7 /**
  8  * Date helper.
  9  *
 10  * @author Krisan Alfa Timur <krisanalfa@docotel.co.id>
 11  */
 12 class Carbonate
 13 {
 14     protected static $month = array(
 15         'Jan' => 1,
 16         'Feb' => 2,
 17         'Mar' => 3,
 18         'Apr' => 4,
 19         'May' => 5,
 20         'Jun' => 6,
 21         'Jul' => 7,
 22         'Aug' => 8,
 23         'Sep' => 9,
 24         'Oct' => 10,
 25         'Nov' => 11,
 26         'Dev' => 12,
 27     );
 28 
 29     protected static $day = array(
 30         'Mon' => 1,
 31         'Tue' => 2,
 32         'Wed' => 3,
 33         'Thu' => 4,
 34         'Fri' => 5,
 35         'Sat' => 6,
 36         'Sun' => 7,
 37     );
 38 
 39     protected static $localeMonth = array(
 40         'id' => array(
 41             1 => 'Januari',
 42             2 => 'Februari',
 43             3 => 'Maret',
 44             4 => 'April',
 45             5 => 'Mei',
 46             6 => 'Juni',
 47             7 => 'Juli',
 48             8 => 'Agustus',
 49             9 => 'September',
 50             10 => 'Oktober',
 51             11 => 'November',
 52             12 => 'Desember',
 53         ),
 54     );
 55 
 56     protected static $localeDays = array(
 57         'id' => array(
 58             1 => 'Senin',
 59             2 => 'Selasa',
 60             3 => 'Rabu',
 61             4 => 'Kamis',
 62             5 => 'Jum\'at',
 63             6 => 'Sabtu',
 64             7 => 'Minggu',
 65         ),
 66     );
 67 
 68     /**
 69      * Format date to Indonesia Locale.
 70      *
 71      * @param string $date
 72      * @param string $format
 73      * @param string $returnFormat
 74      *
 75      * @return string|null
 76      */
 77     public static function formatId($date, $format = 'Y-m-d H:i:s', $returnFormat = 'D, d M Y')
 78     {
 79         $date = Carbon::createFromFormat($format, $date);
 80 
 81         return ($date) ? static::formatLocale($date, 'id', $returnFormat)
 82                        : null;
 83     }
 84 
 85     /**
 86      * Format our locale date
 87      *
 88      * @param Carbon\Carbon $date
 89      * @param string        $locale
 90      * @param string        $returnFormat
 91      *
 92      * @return string
 93      */
 94     public static function formatLocale(Carbon $date, $locale, $returnFormat)
 95     {
 96         $date->setLocale('en');
 97 
 98         $replacedMonth = str_replace($date->format('M'), static::localeMonth($date, $locale), $date->format($returnFormat));
 99         $replacedDay = str_replace($date->format('D'), static::localeDay($date, $locale), $replacedMonth);
100 
101         return $replacedDay;
102     }
103 
104     /**
105      * Get month index. Useful for translation.
106      *
107      * @param \Carbon\Carbon $date
108      *
109      * @return int|null
110      */
111     public static function monthIndex(Carbon $date)
112     {
113         $date->setLocale('en');
114 
115         return def(static::$month, $date->format('M'));
116     }
117 
118     public static function dayIndex(Carbon $date)
119     {
120         $date->setLocale('en');
121 
122         return def(static::$day, $date->format('D'));
123     }
124 
125     /**
126      * Get translated locale month
127      *
128      * @param \Carbon\Carbon $date
129      * @param string         $locale
130      *
131      * @return string|null
132      */
133     public static function localeMonth(Carbon $date, $locale)
134     {
135         return def(static::localeMonths($locale), static::monthIndex($date));
136     }
137 
138     /**
139      * Get translated locale day
140      *
141      * @param \Carbon\Carbon $date
142      * @param string         $locale
143      *
144      * @return string|null
145      */
146     public static function localeDay(Carbon $date, $locale)
147     {
148         return def(static::localeDays($locale), static::dayIndex($date));
149     }
150 
151     /**
152      * Get days name lists
153      *
154      * @return array
155      */
156     public static function localeDays($locale)
157     {
158         return def(static::$localeDays, $locale, array());
159     }
160 
161     /**
162      * Get month name lists
163      *
164      * @return array
165      */
166     public static function localeMonths($locale)
167     {
168         return def(static::$localeMonth, $locale, array());
169     }
170 
171     /**
172      * Return differ time in hours.
173      *
174      * @param string $start  Date you want to start from.
175      * @param string $end    Date you want to calculate the difference from the start.
176      * @param string $format The `$start` and `$end` format. They must be in the in same format.
177      *
178      * @return int|null
179      */
180     public static function diff($start, $end, $format = 'Y-m-d')
181     {
182         $start = Carbon::createFromFormat($format, $start);
183         $end = Carbon::createFromFormat($format, $end);
184 
185         return ($start and $end) ? $start->diffInDays($end)
186                                  : null;
187     }
188 }
189 
LFT API documentation generated by ApiGen