Skip to content

Commit

Permalink
Merge pull request #1 from gaming-engine/feat/initial-build
Browse files Browse the repository at this point in the history
feat(timezones): initial wrapper
  • Loading branch information
awjudd authored Oct 7, 2021
2 parents e3f5b87 + c39f853 commit cc95c4e
Show file tree
Hide file tree
Showing 15 changed files with 670 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Tests

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/vendor
composer.phar
composer.lock
.DS_Store
Thumbs.db
/.idea
/.vscode
.phpunit.result.cache
report.junit.xml
coverage/
build/
4 changes: 4 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
preset: laravel

disabled:
- single_class_element_per_statement
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to `dictionary` will be documented in this file

## 1.0.0 - 201X-XX-XX

- initial release
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

Please read and understand the contribution guide before creating an issue or pull request.

## Etiquette

This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.

Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.

It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.

## Viability

When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.

## Procedure

Before filing an issue:

- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.

Before submitting a pull request:

- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.

## Requirements

If the project maintainer has any additional requirements, you will find them listed here.

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

**Happy coding**!
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# PHP String Tools

[![Latest Version on Packagist](https://img.shields.io/packagist/v/gaming-engine/timezone.svg?style=flat-square)](https://packagist.org/packages/gaming-engine/timezone)
[![Total Downloads](https://img.shields.io/packagist/dt/gaming-engine/timezone.svg?style=flat-square)](https://packagist.org/packages/gaming-engine/timezone)
![GitHub Actions](https://github.com/gaming-engine/string-tools/actions/workflows/main.yml/badge.svg)

A quick and easy wrapper for the timezone functions in PHP.

## Installation

You can install the package via composer:

```bash
composer require gaming-engine/timezone
```

## Usage

```php
use GamingEngine\Timezone\TimezoneList;

$timezones = TimezoneList::all();

// Provides all timezones
```

### Testing

```bash
composer test
```

### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [Andrew Judd](https://github.com/gaming-engine)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
42 changes: 42 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "gaming-engine/timezone",
"description": "Timezone tools",
"keywords": [
"gaming-engine",
"date",
"timezone"
],
"homepage": "https://github.com/gaming-engine/timezone",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Andrew Judd",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^8.0|^8.1"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"GamingEngine\\Timezone\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"GamingEngine\\Timezone\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
}
}
39 changes: 39 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="GamingEngine Dictionary Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="./build/coverage"/>
<text outputFile="./build/coverage.txt"/>
<clover outputFile="./build/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
13 changes: 13 additions & 0 deletions src/Exceptions/InvalidPropertyException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace GamingEngine\Timezone\Exceptions;

use Exception;

class InvalidPropertyException extends Exception
{
public function __construct(string $property)
{
parent::__construct("The property you requested, $property, does not exist.");
}
}
13 changes: 13 additions & 0 deletions src/Exceptions/InvalidTimezoneException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace GamingEngine\Timezone\Exceptions;

use Exception;

class InvalidTimezoneException extends Exception
{
public function __construct(string $timezone)
{
parent::__construct("The specified timezone is invalid: $timezone");
}
}
13 changes: 13 additions & 0 deletions src/Exceptions/TimezoneListReadonlyException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace GamingEngine\Timezone\Exceptions;

use Exception;

class TimezoneListReadonlyException extends Exception
{
public function __construct(string $parameter)
{
parent::__construct("Tried to set the value for, $parameter, however it is readonly.");
}
}
42 changes: 42 additions & 0 deletions src/Timezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace GamingEngine\Timezone;

use DateTime;
use DateTimeZone;
use Exception;
use GamingEngine\Timezone\Exceptions\InvalidPropertyException;
use GamingEngine\Timezone\Exceptions\InvalidTimezoneException;

/**
* @property-read int $offset
*/
class Timezone
{
private DateTimeZone $timezone;

public function __construct(string $timezone)
{
try {
$this->timezone = new DateTimeZone($timezone);
} catch (Exception $e) {
throw new InvalidTimezoneException($timezone);
}
}

public function offset()
{
return $this->timezone->getOffset(
new DateTime('now', new DateTimeZone('UTC'))
);
}

public function __get($name)
{
if (method_exists($this, $name)) {
return $this->$name();
}

throw new InvalidPropertyException($name);
}
}
Loading

0 comments on commit cc95c4e

Please sign in to comment.