Skip to content

Commit

Permalink
Merge pull request #14 from opencafe/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrokhniakan authored Oct 18, 2016
2 parents f6fd8eb + 876c9af commit 15d0eac
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 17 deletions.
79 changes: 65 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
[![Build Status](https://travis-ci.org/opencafe/datium.svg?branch=master)](https://travis-ci.org/opencafe/datium)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/opencafe/datium/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/opencafe/datium/?branch=master)
[![npm](https://img.shields.io/npm/l/express.svg?maxAge=2592000)]()
[![packagist](https://img.shields.io/badge/status-beta-orange.svg)]()



Awesome DateTime package ever written in PHP, with clean design pattern and generalization support in calendar and translation, which makes Datium powerful and simple.

Expand All @@ -20,7 +17,7 @@ Awesome DateTime package ever written in PHP, with clean design pattern and gene

## Via Composer

```
```js
composer require opencafe/datium
```

Expand All @@ -44,6 +41,8 @@ As datium output
Datium::now()->get(); // ex: 2016-01-01 00:00:00

Datium::now()->timestamp(); // ex: 1420057800

Datium::now()->get('timestamp'); // ex: 1420057800
```
Or working with date as simple as you need:

Expand Down Expand Up @@ -71,6 +70,44 @@ And even with custom PHP YMD [format](http://php.net/manual/en/function.date.php
Datium::now()->get( 'l jS F Y h:i:s A' );
```

Timestamp format:

```js
Datium::create(2016,10,16)->get('timestamp');
// Result : 1476563400
```

Easy usage:

```js
Datium::now()->all();

// Result
object(stdClass)#5 (6) {
["second"]=>
string(2) "03"
["minute"]=>
string(2) "10"
["hour"]=>
string(2) "15"
["day"]=>
string(2) "12"
["month"]=>
string(2) "10"
["year"]=>
string(4) "2016"
}

Datium::now()->all()->year; // 2016
Datium::now()->all()->month; // 10
Datium::now()->all()->day; // 12
Datium::now()->all()->hour; // 15
Datium::now()->all()->minute; // 10
Datium::now()->all()->second; // 03
```




## Create
You can also simply create new time:
Expand Down Expand Up @@ -138,7 +175,7 @@ Datium::now()->sub('1 year')
## Date Difference
This method will return the difference between two specific date with php date interval type.

```
```js
// current generated date difference with next 5000 days
$diff = Datium::diff(
Datium::now()->object(),
Expand All @@ -155,14 +192,14 @@ echo $diff->year . ' year, ' . $diff->month . ' month, ' . $diff->day . ' day '
### Human readable time difference
Datium also supports human readable date and time difference.

```
```js
// current generated date difference with next 5000 days
$diff = Datium::diff(
Datium::now()->object(),
Datium::now()->add('5000 day')->object()
)->simple->get();

// result => 13 years ago
// result => 13 years ago

// current generated date difference with next 5000 days
$diff = Datium::diff(
Expand Down Expand Up @@ -243,6 +280,21 @@ Datium::now()->to( 'hijri' )->dayOf()->week();

```

## Last Day of Month
How many days is current month
```js

// Last Day of Current Month to Gregorian
Datium::now()->dayOf()->lastDayMonth();

// Last Day of Current Month to Jalali
Datium::now()->to( 'jalali' )->dayOf()->lastDayMonth();

// Last Day of Current Month to Hijri
Datium::now()->to( 'hijri' )->dayOf()->lastDayMonth();

```

## Generalization

### Calendar generalization
Expand All @@ -260,9 +312,11 @@ Datium::create( 2015, 11, 9 )->to( 'hijri' )->get()
Convert all calendars which supported on Datium or event your customized calendars as simple as possible:

```js
Datium::create( 2015, 11, 9 )->from( 'jalali' )->to( 'gregorian' )->get();
Datium::create( 1395, 7, 25 )->from( 'jalali' )->get(); // Gregorian is default value for destination calendar.
// result: 2016-10-16 00:00:00

Datium::create( 2015, 11, 9 )->from( 'jalali' )->to( 'hijri' )->get();
Datium::create( 1395, 7, 25 )->from( 'jalali' )->to( 'hijri' )->get();
// result: 1438-01-14 00:00:00
```

### Translation Generalization
Expand All @@ -281,16 +335,13 @@ Datium::create(2016, 6, 25, 12, 0, 0)->to('hijri')->get('l jS F Y h:i:s A');

Datium::create(2016, 6, 25, 12, 0, 0)->get('l jS F Y h:i:s A');
// ex: Saturday 25th June 2016 12:00:00 PM



```

### Change Configuration

You can change any configuration after initialize Datium object.

```php
```js
$datium = Datium::create(
$date->format('Y'),
$date->format('m'),
Expand All @@ -304,7 +355,7 @@ $datium->setConfig(['timezone'=>'Europe/Istanbul']);

#### Default configuration

```php
```
[
'timezone' => 'Asia/Tehran',
'language' => 'en',
Expand Down
8 changes: 5 additions & 3 deletions src/Datium.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,11 @@ public function timestamp()
public function get($format = 'Y-m-d H:i:s')
{

// $this->translate_from_file = include( 'Lang/en/general.php' );
//
// $this->translate_to_file = include( 'Lang/' . $this->language . '/general.php' );
if( $format === 'timestamp' ) {

return $this->timestamp();

}

if (is_null($this->fromConfig)) {
$this->fromConfig = include __DIR__.'/CalendarSettings/'.
Expand Down
14 changes: 14 additions & 0 deletions src/DayOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,18 @@ public function week()
return $this->config[ 'day_of_week' ]( $this->date_time );

}

/**
* Return last day of current month
*
* @since Oct, 18 2016
* @return integer
*/
public function lastDayMonth() {

$this->config = include __DIR__.'/CalendarSettings/' . ucfirst($this->calendar_type) . '.php';

return $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ];

}
}
5 changes: 5 additions & 0 deletions tests/DatiumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public function testCreateDateTime()
Datium::create(2015, 1, 1)->timestamp()
);

$this->assertEquals(
'1420057800',
Datium::create(2015, 1, 1)->get('timestamp')
);

$this->assertEquals(
'2015-01-01 00:00:00',
Datium::createTimestamp( 1420057800 )->get()
Expand Down
11 changes: 11 additions & 0 deletions tests/DayOfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ public function testDayOfWeek()
$this->assertEquals(6, Datium::create(2015, 1, 1)->to('jalali')->dayOf()->week());

}

public function testLastDayOfMonth()
{

$this->assertEquals(31, Datium::create(2015, 1, 1)->dayOf()->lastDayMonth());

$this->assertEquals(30, Datium::create(2015, 1, 1)->to('hijri')->dayOf()->lastDayMonth());

$this->assertEquals(30, Datium::create(2015, 1, 1)->to('jalali')->dayOf()->lastDayMonth());

}
}

0 comments on commit 15d0eac

Please sign in to comment.