Skip to content

Commit 3848cbe

Browse files
Fix coding style
1 parent fd5b7fb commit 3848cbe

File tree

10 files changed

+141
-88
lines changed

10 files changed

+141
-88
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ As datium output
3838

3939
```js
4040
Datium::now()->get(); // ex: 2016-01-01 00:00:00
41+
42+
Datium::now()->timestamp(); ex: 1420057800
4143
```
4244
Or working with date as simple as you need:
4345

@@ -212,6 +214,10 @@ Generalization in translation is another Datium generalization support.
212214
Datium::create( 2016, 6, 25, 12, 0, 0 )->to( 'jalali' )->lang( 'fa' )->get('l jS F Y h:i:s A');
213215
// ex: شنبه ۵ تیر ۱۳۹۵ ۱۲:۰۰:۰۰ ب.ظ
214216

217+
Datium::create( 2016, 6, 25, 12, 0, 0 )->to( 'jalali' )->get('l jS F Y h:i:s A');
218+
// ex: Shanbe 5th Tir 1395 12:00:00 PM
219+
220+
215221
Datium::create(2016, 6, 25, 12, 0, 0)->to('hijri')->get('l jS F Y h:i:s A');
216222
// ex: as-Sabt 19th Ramadan 1437 12:00:00 PM
217223

src/CalendarSettings/Gregorian.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@
169169
*
170170
*\_________________________________________________________/
171171
*/
172-
'leap_year' => function($year) {
172+
'leap_year' => function ($year) {
173173

174-
return ( ( ( $year % 4 ) == 0 ) && ( ( ( $year % 100 ) != 0 ) || ( ( $year % 400 ) == 0 ) ) );
174+
return ( ( ( $year % 4 ) == 0 ) && ( ( ( $year % 100 ) != 0 ) || ( ( $year % 400 ) == 0 ) ) );
175175

176176
},
177177

src/CalendarSettings/Hijri.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
$jd = (int)((11 * $year + 3) / 30) + 354 * $year +
109109
30 * $month -(int)(($month - 1) / 2) + $day + 1948440 - 385;
110110

111-
$result = explode( '/', jdtogregorian($jd));
111+
$result = explode('/', jdtogregorian($jd));
112112

113113
$month = $result[0];
114114

@@ -276,22 +276,23 @@
276276
*
277277
*\_________________________________________________________/
278278
*/
279-
'leap_year' => function($year){
280-
$result = $this->year % 30;
281-
282-
if (( 2 == $result ) ||
283-
( 5 == $result ) ||
284-
( 7 == $result ) ||
285-
( 10 == $result ) ||
286-
( 13 == $result ) ||
287-
( 16 == $result ) ||
288-
( 18 == $result ) ||
289-
( 21 == $result ) ||
290-
( 24 == $year ) ||
291-
( 26 == $result ) ||
292-
( 29 == $result )) {
293-
return $result;
294-
}
279+
'leap_year' => function ($year) {
280+
$result = $this->year % 30;
281+
282+
if (( 2 == $result )
283+
|| ( 5 == $result )
284+
|| ( 7 == $result )
285+
|| ( 10 == $result )
286+
|| ( 13 == $result )
287+
|| ( 16 == $result )
288+
|| ( 18 == $result )
289+
|| ( 21 == $result )
290+
|| ( 24 == $year )
291+
|| ( 26 == $result )
292+
|| ( 29 == $result )
293+
) {
294+
return $result;
295+
}
295296
},
296297

297298
/************************************************************

src/CalendarSettings/Jalali.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -322,29 +322,31 @@
322322
*
323323
*\_________________________________________________________/
324324
*/
325-
'leap_year' => function( $year ) {
325+
'leap_year' => function ( $year ) {
326326

327327
$a = 0.025;
328328

329329
$b = 266;
330330

331-
if ($year > 0){
332-
$leapDays0 = (($year + 38) % 2820)*0.24219 + $a; # 0.24219 ~ extra days of one year
333-
$leapDays1 = (($year + 39) % 2820)*0.24219 + $a; # 38 days is the difference of epoch to 2820-year cycle
334-
} elseif( $year < 0 ) {
335-
$leapDays0 = (($year + 39) % 2820)*0.24219 + $a;
336-
$leapDays1 = (($year + 40) % 2820)*0.24219 + $a;
337-
} else {
338-
return false;
339-
}
331+
if ($year > 0) {
332+
$leapDays0 = (($year + 38) % 2820)*0.24219 + $a; // 0.24219 ~ extra days of one year
333+
$leapDays1 = (($year + 39) % 2820)*0.24219 + $a; // 38 days is the difference of epoch to 2820-year cycle
334+
} elseif($year < 0 ) {
335+
$leapDays0 = (($year + 39) % 2820)*0.24219 + $a;
336+
$leapDays1 = (($year + 40) % 2820)*0.24219 + $a;
337+
} else {
338+
return false;
339+
}
340340

341341
$frac0 = intval(($leapDays0 - intval($leapDays0))*1000);
342342
$frac1 = intval(($leapDays1 - intval($leapDays1))*1000);
343343

344-
if ($frac0 <= $b && $frac1 > $b)
345-
return true;
346-
else
347-
return false;
344+
if ($frac0 <= $b && $frac1 > $b) {
345+
return true;
346+
}
347+
else {
348+
return false;
349+
}
348350

349351
},
350352

src/Datium.php

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,36 +112,36 @@ public function __construct()
112112
$this->calendar_type = 'gregorian';
113113

114114
switch (Datium::$call_type) {
115-
case 'now':
116-
$this->date_time = new DateTime('now');
115+
case 'now':
116+
$this->date_time = new DateTime('now');
117117

118-
$this->gregorian_DayofWeek = $this->date_time->format('w');
118+
$this->gregorian_DayofWeek = $this->date_time->format('w');
119119

120-
break;
120+
break;
121121

122-
case 'make':
123-
$this->date_time = new DateTime('now');
122+
case 'make':
123+
$this->date_time = new DateTime('now');
124124

125-
$this->date_time->setDate(
126-
self::$array_date[ 'year' ],
127-
self::$array_date[ 'month' ],
128-
self::$array_date[ 'day' ]
129-
);
125+
$this->date_time->setDate(
126+
self::$array_date[ 'year' ],
127+
self::$array_date[ 'month' ],
128+
self::$array_date[ 'day' ]
129+
);
130130

131-
$this->date_time->setTime(
132-
self::$array_date[ 'hour' ],
133-
self::$array_date[ 'minute' ],
134-
self::$array_date[ 'second' ]
135-
);
131+
$this->date_time->setTime(
132+
self::$array_date[ 'hour' ],
133+
self::$array_date[ 'minute' ],
134+
self::$array_date[ 'second' ]
135+
);
136136

137-
$this->gregorian_DayofWeek = $this->date_time->format('w');
137+
$this->gregorian_DayofWeek = $this->date_time->format('w');
138138

139-
break;
139+
break;
140140

141-
case 'set':
142-
$this->date_time = Datium::$static_date_time;
141+
case 'set':
142+
$this->date_time = Datium::$static_date_time;
143143

144-
$this->gregorian_DayofWeek = $this->date_time->format('w');
144+
$this->gregorian_DayofWeek = $this->date_time->format('w');
145145
}
146146

147147
$this->convert_calendar = new Convert();
@@ -202,13 +202,14 @@ public static function now()
202202
* @return object
203203
*/
204204
public static function create(
205-
$year = 2000,
206-
$month = 1,
207-
$day = 1,
208-
$hour = 0,
209-
$minute = 0,
210-
$second = 0)
211-
{
205+
$year = 2000,
206+
$month = 1,
207+
$day = 1,
208+
$hour = 0,
209+
$minute = 0,
210+
$second = 0
211+
) {
212+
212213

213214
/**
214215
* When we want to set a Datetime object to Datium
@@ -467,6 +468,18 @@ public function lang($language = 'fa')
467468

468469
}
469470

471+
/**
472+
* Return object as timestamp
473+
*
474+
* @return timestamp
475+
*/
476+
public function timestamp()
477+
{
478+
479+
return strtotime($this->date_time->format('Y-m-d H:i:s'));
480+
481+
}
482+
470483
/**
471484
* Return fainal result
472485
*

src/Events/Events.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ public function local($country_code = "ir")
124124
$this->date_time->setDate(Events::$date_start->format('Y'), $month, $day);
125125

126126
switch ($this->local[ 'default_calendar' ]) {
127-
case 'jalali':
128-
$this->date_time->setDate(1394, $month, $day);
127+
case 'jalali':
128+
$this->date_time->setDate(1394, $month, $day);
129129

130-
$this->date_time = Datium::create($this->date_time)->from('jalali')->to('gregorian')->object(); //$this->convert->jalaliToGregorian( $this->date_time );
130+
$this->date_time = Datium::create($this->date_time)->from('jalali')->to('gregorian')->object(); //$this->convert->jalaliToGregorian( $this->date_time );
131131

132-
break;
132+
break;
133133

134-
case 'hijri':
135-
$this->date_time = Datium::create($this->date_time)->from('hijri')->to('gregorian')->object(); // $this->convert->hijriToGregorian( $this->date_time );
134+
case 'hijri':
135+
$this->date_time = Datium::create($this->date_time)->from('hijri')->to('gregorian')->object(); // $this->convert->hijriToGregorian( $this->date_time );
136136

137-
break;
137+
break;
138138
}
139139

140140
$this->result[ $this->date_time->format('Y-m-d') ][] = $event;

src/Leap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function __construct($year, $type = 'gregorian')
4747
public function get()
4848
{
4949

50-
$this->result = include('CalendarSettings/' . ucfirst($this->type) . '.php');
50+
$this->result = include 'CalendarSettings/' . ucfirst($this->type) . '.php';
5151

52-
return $this->result['leap_year']($this->year);
52+
return $this->result['leap_year']($this->year);
5353

5454
}
5555
}

tests/ConvertTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testGregorianToHijri()
1919

2020
$date = Datium::create(2016, 6, 13)->to('hijri')->get();
2121

22-
$this->assertEquals( '1437-09-07 00:00:00', $date );
22+
$this->assertEquals('1437-09-07 00:00:00', $date);
2323

2424
}
2525

@@ -28,7 +28,7 @@ public function testJalaliToGregorian()
2828

2929
$date = Datium::create(1395, 3, 24)->from('jalali')->get();
3030

31-
$this->assertEquals( '2016-06-13 00:00:00', $date );
31+
$this->assertEquals('2016-06-13 00:00:00', $date);
3232

3333
}
3434

@@ -37,7 +37,7 @@ public function testHijriToGregorian()
3737

3838
$date = Datium::create(1437, 9, 7)->from('hijri')->get();
3939

40-
$this->assertEquals( '2016-06-13 00:00:00', $date );
40+
$this->assertEquals('2016-06-13 00:00:00', $date);
4141

4242
}
4343

@@ -46,7 +46,7 @@ public function testJalaliToHijri()
4646

4747
$date = Datium::create(1395, 3, 24)->from('jalali')->to('hijri')->get();
4848

49-
$this->assertEquals( '1437-09-07 00:00:00', $date );
49+
$this->assertEquals('1437-09-07 00:00:00', $date);
5050

5151
}
5252

@@ -55,7 +55,7 @@ public function testHijriToJalali()
5555

5656
$date = Datium::create(1437, 9, 7)->from('hijri')->to('jalali')->get();
5757

58-
$this->assertEquals( '1395-03-24 00:00:00', $date );
58+
$this->assertEquals('1395-03-24 00:00:00', $date);
5959

6060
}
6161
}

tests/DatiumTest.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,39 @@ public function testCreateDateTime()
1616

1717
$current_date_time->setTime(0, 0, 0);
1818

19-
$this->assertEquals($current_date_time->format('Y-m-d H:i:s'), Datium::create(2015, 1, 1)->get());
19+
$this->assertEquals(
20+
$current_date_time->format('Y-m-d H:i:s'),
21+
Datium::create(2015, 1, 1)->get()
22+
);
23+
24+
$this->assertEquals(
25+
'1420057800',
26+
Datium::create(2015, 1, 1)->timestamp()
27+
);
2028

2129
}
2230

2331
public function testDateDifference()
2432
{
2533

26-
$diff = Datium::diff(Datium::now()->object(), Datium::now()->add('5 day')->object());
34+
$diff = Datium::diff(
35+
Datium::now()->object(),
36+
Datium::now()->add('5 day')->object()
37+
);
2738

2839
$this->assertEquals(5, $diff->days);
2940

30-
$diff = Datium::diff(Datium::now()->object(), Datium::now()->add('100 day')->object());
41+
$diff = Datium::diff(
42+
Datium::now()->object(),
43+
Datium::now()->add('100 day')->object()
44+
);
3145

3246
$this->assertEquals(100, $diff->days);
3347

34-
$diff = Datium::diff(Datium::now()->object(), Datium::now()->add('5000 day')->object());
48+
$diff = Datium::diff(
49+
Datium::now()->object(),
50+
Datium::now()->add('5000 day')->object()
51+
);
3552

3653
$this->assertEquals(5000, $diff->days);
3754

@@ -40,11 +57,16 @@ public function testDateDifference()
4057
public function testJalaliCalendar()
4158
{
4259

43-
$jalali = Datium::create(2016, 6, 25, 12, 0, 0)->to('jalali')->get('l jS F Y h:i:s A');
60+
$jalali = Datium::create(2016, 6, 25, 12, 0, 0)
61+
->to('jalali')
62+
->get('l jS F Y h:i:s A');
4463

4564
$this->assertEquals('Shanbe 5th Tir 1395 12:00:00 PM', $jalali);
4665

47-
$jalali = Datium::create(2016, 6, 25, 12, 0, 0)->to('jalali')->lang('fa')->get('l jS F Y h:i:s A');
66+
$jalali = Datium::create(2016, 6, 25, 12, 0, 0)
67+
->to('jalali')
68+
->lang('fa')
69+
->get('l jS F Y h:i:s A');
4870

4971
$this->assertEquals('شنبه ۵ تیر ۱۳۹۵ ۱۲:۰۰:۰۰ ب.ظ', $jalali);
5072

@@ -53,7 +75,15 @@ public function testJalaliCalendar()
5375
public function testHijriCalendar()
5476
{
5577

56-
$hijri = Datium::create(2016, 6, 25, 12, 0, 0)->to('hijri')->get('l jS F Y h:i:s A');
78+
$hijri = Datium::create(2016, 6, 25, 12, 0, 0)
79+
->to('hijri')
80+
->get('l jS F Y h:i:s A');
81+
82+
$this->assertEquals('as-Sabt 19th Ramadan 1437 12:00:00 PM', $hijri);
83+
84+
$hijri = Datium::create(2016, 6, 25, 12, 0, 0)
85+
->to('hijri')
86+
->get('l jS F Y h:i:s A');
5787

5888
$this->assertEquals('as-Sabt 19th Ramadan 1437 12:00:00 PM', $hijri);
5989

@@ -62,7 +92,8 @@ public function testHijriCalendar()
6292
public function testGregorianCalendar()
6393
{
6494

65-
$gregorian = Datium::create(2016, 6, 25, 12, 0, 0)->get('l jS F Y h:i:s A');
95+
$gregorian = Datium::create(2016, 6, 25, 12, 0, 0)
96+
->get('l jS F Y h:i:s A');
6697

6798
$this->assertEquals('Saturday 25th June 2016 12:00:00 PM', $gregorian);
6899

0 commit comments

Comments
 (0)