Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryJones committed May 16, 2018
0 parents commit 8175af6
Show file tree
Hide file tree
Showing 9 changed files with 689 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
/vendor/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.0] - 2018-05-16
### Added
- Initial release to GitHub.

[0.1.0]: https://github.com/GaryJones/DateRange/compare/v0.0.0...v0.1.0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Gary Jones, Gamajo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Gamajo Date Range

[![Latest Stable Version](https://img.shields.io/packagist/v/gamajo/daterange.svg)](https://packagist.org/packages/gamajo/daterange)
[![Total Downloads](https://img.shields.io/packagist/dt/gamajo/daterange.svg)](https://packagist.org/packages/gamajo/daterange)
[![Latest Unstable Version](https://img.shields.io/packagist/vpre/gamajo/daterange.svg)](https://packagist.org/packages/gamajo/daterange)
[![License](https://img.shields.io/packagist/l/gamajo/daterange.svg)](https://packagist.org/packages/gamajo/daterange)

Display a range of dates, with consolidated time parts.

## Table Of Contents

* [Installation](#installation)
* [Basic Usage](#basic-usage)
* [Advanced Usage](#advanced-usage)
* [Contributing](#contributing)
* [License](#license)

## Installation

The best way to use this package is through Composer:

```BASH
composer require gamajo/daterange
```

## Basic Usage

Create an instance of the `DateRange` class, with `DateTimeImmutable` or `DateTime` start and end date-time objects as arguments. Then choose the format to use as the end date output. The start date will only display the time parts that are not duplicated.

```php
$dateRange = new DateRange(
new DateTimeImmutable('23rd June 18 14:00'),
new DateTimeImmutable('2018-06-23T15:00')
);
echo $dateRange->format('H:i d M Y'); // 14:00 – 15:00 23 Jun 2018
```

If the formatted date would be the same start and end date, only a single date is displayed:

```php
$dateRange = new DateRange(
new DateTimeImmutable('23rd June 18 14:00'),
new DateTimeImmutable('2018-06-23T15:00')
);
echo $dateRange->format('jS M Y'); // 23rd Jun 2018
```

## Advanced Usage

### Change Separator

The default separator between the start and end date, is a space, en-dash, space: `' – '`

This can be changed via the `changeSeparator()` method:

```php
$dateRange = new DateRange(
new DateTimeImmutable('23rd June 18 14:00'),
new DateTimeImmutable('2018-06-23T15:00')
);
$dateRange->changeSeparator(' to ');
echo 'From ', $dateRange->format('H:i d M Y'); // From 14:00 to 15:00 23 Jun 2018
```

### Change Removable Delimiters

The consolidation and removal of some time parts may leave delimiters from the format:

```php
$dateRange = new DateRange(
new DateTimeImmutable('23rd June 18'),
new DateTimeImmutable('2018-06-24')
);
echo $dateRange->format('d·M·Y'); // 23·· – 24·Jun·2018
```

Be default, `/`, `-` and `.` are trimmed from the start date, but this can be amended with the `changeRemovableDelimiters()` method:

```php
$dateRange = new DateRange(
new DateTimeImmutable('23rd June 18'),
new DateTimeImmutable('2018-06-24')
);
$dateRange->changeRemovableDelimiters('·');
echo $dateRange->format('d·M·Y'); // 23 – 24·Jun·2018
```


## Contributing

All feedback / bug reports / pull requests are welcome.

## License

Copyright (c) 2018 Gary Jones, Gamajo

This code is licensed under the [MIT License](LICENSE).
54 changes: 54 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "gamajo/daterange",
"description": "Display a range of dates, with consolidated time parts.",
"minimum-stability": "dev",
"prefer-stable": true,
"license": "MIT",
"homepage": "https://github.com/GaryJones/date-range",
"authors": [
{
"name": "Gary Jones",
"homepage": "https://gamajo.com",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/GaryJones/daterange/issues",
"source": "https://github.com/GaryJones/daterange"
},
"config": {
"sort-packages": true
},
"require": {
"php": "^7.1"
},
"require-dev": {
"brain/monkey": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"infection/infection": "^0.8",
"mockery/mockery": "^1.1",
"object-calisthenics/phpcs-calisthenics-rules": "^3",
"phpunit/phpunit": "^7",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.2",
"sirbrillig/phpcs-variable-analysis": "^2.0",
"wimg/php-compatibility": "^8.1"
},
"autoload": {
"psr-4": {
"Gamajo\\DateRange\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Gamajo\\DateRange\\Tests\\": "tests/"
}
},
"scripts": {
"test": "./vendor/bin/phpunit",
"phpcs": "./vendor/bin/phpcs",
"install-codestandards": [
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
]
}
}
33 changes: 33 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<ruleset name="Gamajo DateRange">
<description>The code standard for Gamajo dateRange package.</description>

<!-- What to scan -->
<file>.</file>
<exclude-pattern>vendor/</exclude-pattern>

<!-- How to scan -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="basepath" value="."/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="report" value="full"/>
<arg name="report" value="summary"/>
<arg name="report" value="source"/>

<!-- Rules: ObjectCalisthenics for good coding practices -->
<rule ref="ObjectCalisthenics">
<exclude-pattern>/tests</exclude-pattern>
</rule>

<!-- Rules: Good use of variables -->
<rule ref="VariableAnalysis"/>

<!-- Rules: Check PHP version compatibility -->
<config name="testVersion" value="7.1-"/>
<rule ref="PHPCompatibility"/>

<!-- Rules: PSR-2 -->
<rule ref="PSR2"/>

</ruleset>
30 changes: 30 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
defaultTestSuite="unit"
verbose="true">
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
<!--<testsuite name="integration">-->
<!--<directory suffix="Test.php">tests/Integration</directory>-->
<!--</testsuite>-->
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout"/>
<!--<log type="coverage-html" target="coverage"/>-->
</logging>
</phpunit>
Loading

0 comments on commit 8175af6

Please sign in to comment.