opencafe /
datium
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | use Datium\Datium as Datium; |
||
| 4 | |||
| 5 | return array ( |
||
| 6 | |||
| 7 | /************************************************************ |
||
| 8 | * Convert to |
||
| 9 | ************************************************************ |
||
| 10 | * |
||
| 11 | * Convert algorith to convert Gregorian to Jalali calerndar |
||
| 12 | * |
||
| 13 | *\_________________________________________________________/ |
||
| 14 | */ |
||
| 15 | 'convert_to' => function( $date_time ) { |
||
| 16 | |||
| 17 | return Datium::create( $date_time )->sub( '226898 day' )->object(); |
||
| 18 | |||
| 19 | }, |
||
| 20 | |||
| 21 | /************************************************************ |
||
| 22 | * Convert From |
||
| 23 | ************************************************************ |
||
| 24 | * |
||
| 25 | * Convert algorith to convert Jalali to Gregorian calerndar |
||
| 26 | * |
||
| 27 | *\_________________________________________________________/ |
||
| 28 | */ |
||
| 29 | 'convert_from' => function( $date_time ) { |
||
| 30 | |||
| 31 | return Datium::create( $date_time )->add( '226898 day' )->object(); |
||
| 32 | |||
| 33 | }, |
||
| 34 | |||
| 35 | /************************************************************ |
||
| 36 | * Shorthand for jalali calendar |
||
| 37 | ************************************************************ |
||
| 38 | * |
||
| 39 | * Jalali calendar shorthand |
||
| 40 | * |
||
| 41 | *\_________________________________________________________/ |
||
| 42 | */ |
||
| 43 | 'shorthand' => 'sh', |
||
| 44 | |||
| 45 | /************************************************************ |
||
| 46 | * Month's name |
||
| 47 | ************************************************************ |
||
| 48 | * |
||
| 49 | * Jalali month name |
||
| 50 | * |
||
| 51 | *\_________________________________________________________/ |
||
| 52 | */ |
||
| 53 | 'month' => array ( |
||
| 54 | |||
| 55 | 'Farvardin', |
||
| 56 | |||
| 57 | 'Ordibehesht', |
||
| 58 | |||
| 59 | 'Khordad', |
||
| 60 | |||
| 61 | 'Tir', |
||
| 62 | |||
| 63 | 'Mordad', |
||
| 64 | |||
| 65 | 'Shahrivar', |
||
| 66 | |||
| 67 | 'Mehr', |
||
| 68 | |||
| 69 | 'Aban', |
||
| 70 | |||
| 71 | 'Azar', |
||
| 72 | |||
| 73 | 'Dey', |
||
| 74 | |||
| 75 | 'Bahman', |
||
| 76 | |||
| 77 | 'Esfand' |
||
| 78 | |||
| 79 | ), |
||
| 80 | |||
| 81 | /************************************************************ |
||
| 82 | * Days of Week |
||
| 83 | ************************************************************ |
||
| 84 | * |
||
| 85 | * Here is week days on jalali calendar, offset 0 is first |
||
| 86 | * day of week and offset 6 is the last one. |
||
| 87 | * |
||
| 88 | *\_________________________________________________________/ |
||
| 89 | */ |
||
| 90 | 'days_of_week' => array ( |
||
| 91 | 'Yekshanbe', |
||
| 92 | 'Doshanbe', |
||
| 93 | 'Seshanbe', |
||
| 94 | 'Chaharshanbe', |
||
| 95 | 'Panjshanbe', |
||
| 96 | 'Jome', |
||
| 97 | 'Shanbe' |
||
| 98 | ), |
||
| 99 | |||
| 100 | 'start_day_of_week' => 'Shanbe', |
||
| 101 | |||
| 102 | 'month_days_number' => array( 1 => 31, |
||
| 103 | 2 => 31, |
||
| 104 | 3 => 31, |
||
| 105 | 4 => 31, |
||
| 106 | 5 => 31, |
||
| 107 | 6 => 31, |
||
| 108 | 7 => 30, |
||
| 109 | 8 => 30, |
||
| 110 | 9 => 30, |
||
| 111 | 10 => 30, |
||
| 112 | 11 => 30, |
||
| 113 | 12 => 29 ), |
||
| 114 | |||
| 115 | |||
| 116 | View Code Duplication | 'day_of_year' => function( $date_time ) { |
|
| 117 | |||
| 118 | $result = null; |
||
| 119 | |||
| 120 | $config = include( 'Shamsi.php' ); |
||
| 121 | |||
| 122 | $month = $date_time->format('n'); |
||
| 123 | |||
| 124 | $day = $date_time->format('d'); |
||
| 125 | |||
| 126 | foreach( $config['month_days_number'] as $_month => $value ) { |
||
| 127 | |||
| 128 | if ( $_month < $month ) $result += $value; |
||
| 129 | |||
| 130 | } |
||
| 131 | |||
| 132 | $result += $day; |
||
| 133 | |||
| 134 | return $result + 1; |
||
| 135 | |||
| 136 | }, |
||
| 137 | |||
| 138 | View Code Duplication | 'day_of_week' => function( $date_time ) { |
|
|
0 ignored issues
–
show
|
|||
| 139 | |||
| 140 | $configShamsi = include( 'Shamsi.php' ); |
||
| 141 | |||
| 142 | $configGregorian = include( 'Gregorian.php' ); |
||
| 143 | |||
| 144 | $day = $date_time->format('l'); |
||
| 145 | |||
| 146 | $day = str_replace( $configGregorian['days_of_week'], $configShamsi['days_of_week'], $day ); |
||
| 147 | |||
| 148 | foreach ( $configShamsi['days_of_week'] as $key => $value ) { |
||
| 149 | |||
| 150 | if( $value == $day ) { |
||
| 151 | |||
| 152 | if( $key <= 5 ) { |
||
| 153 | |||
| 154 | return $key += 1; |
||
| 155 | |||
| 156 | } |
||
| 157 | |||
| 158 | } |
||
| 159 | |||
| 160 | } |
||
| 161 | |||
| 162 | }, |
||
| 163 | |||
| 164 | /************************************************************ |
||
| 165 | * Leap year |
||
| 166 | ************************************************************ |
||
| 167 | * |
||
| 168 | * Leap Year formula on jalali calendar |
||
| 169 | * |
||
| 170 | *\_________________________________________________________/ |
||
| 171 | */ |
||
| 172 | 'leap_year' => '', |
||
| 173 | |||
| 174 | /************************************************************ |
||
| 175 | * Weekend |
||
| 176 | ************************************************************ |
||
| 177 | * |
||
| 178 | * Jalali weekend |
||
| 179 | * |
||
| 180 | *\_________________________________________________________/ |
||
| 181 | */ |
||
| 182 | 'weekend' => array( 'friday' ) |
||
| 183 | |||
| 184 | ); |
||
| 185 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.