Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: run-tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.2, 8.1]
laravel: [9.*, 10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
- laravel: 10.*
testbench: 8.*
carbon: ^2.63

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

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
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 require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: List Installed Dependencies
run: composer show -D

- name: Execute tests
run: vendor/bin/pest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.idea
vendor
composer.lock
.phpunit.result.cache
build
47 changes: 33 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,49 @@
}
],
"require": {
"php": ">=7.4",
"laravel/framework": "5.6.*|5.7.*|5.8.*|^6|^7|^8|^9|^10.0",
"torann/geoip": "^3.0",
"nesbot/carbon": "^1.0|^2.0"
"php": "^8.1",
"illuminate/support": "^10.0",
"illuminate/contracts": "^10.0",
"stevebauman/location": "^6.6"
},
"require-dev": {
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.6",
"pestphp/pest": "^1.22",
"pestphp/pest-plugin-laravel": "^1.4",
"spatie/laravel-ray": "^1.32"
},
"autoload": {
"psr-4": {
"JamesMills\\LaravelTimezone\\": "src/",
"JamesMills\\LaravelTimezone\\Database\\Seeds\\": "database/seeds/"
"JamesMills\\LaravelTimezone\\": "src/"
},
"files": ["src/helpers.php"]
},
"autoload-dev": {
"psr-4": {
"JamesMills\\LaravelTimezone\\Tests\\": "tests"
}
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
},
"extra": {
"laravel": {
"providers": [
"JamesMills\\LaravelTimezone\\LaravelTimezoneServiceProvider"
]
],
"aliases": {
"Timezone": "JamesMills\\LaravelTimezone\\Facades\\Timezone"
}
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.12|^3.14"
},
"scripts": {
"pre-package-install": [
"@php artisan config:clear"
]
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
33 changes: 33 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
>
<testsuites>
<testsuite name="Timezone 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/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
15 changes: 15 additions & 0 deletions src/Events/TimezoneSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace JamesMills\LaravelTimezone\Events;

use Illuminate\Foundation\Events\Dispatchable;

class TimezoneSet
{
use Dispatchable;

public function __construct(public string $timezone)
{
//
}
}
16 changes: 15 additions & 1 deletion src/Facades/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@

namespace JamesMills\LaravelTimezone\Facades;

use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Carbon\FactoryImmutable;
use Illuminate\Support\Facades\Facade;

/**
* @method static string getCurrentTimezone()
* @method static FactoryImmutable getCarbonFactory($user)
* @method static string|CarbonImmutable convertToLocal(null|Carbon|CarbonImmutable $date, string $format = null)
* @method static string formatLocal(null|Carbon|CarbonImmutable $date, string $format = null)
* @method static CarbonImmutable convertFromLocal(mixed $date)
* @method static CarbonImmutable today()
* @method static CarbonImmutable now()
*
* @see \JamesMills\LaravelTimezone\Timezone
*/
class Timezone extends Facade
{
public static function getFacadeAccessor()
{
return 'timezone';
return \JamesMills\LaravelTimezone\Timezone::class;
}
}
22 changes: 7 additions & 15 deletions src/LaravelTimezoneServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace JamesMills\LaravelTimezone;

use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
Expand All @@ -17,7 +16,6 @@ class LaravelTimezoneServiceProvider extends ServiceProvider
*/
protected $defer = false;


/**
* Perform post-registration booting of services.
*
Expand All @@ -26,14 +24,9 @@ class LaravelTimezoneServiceProvider extends ServiceProvider
public function boot()
{
// Allow migrations publish
if (! class_exists('AddTimezoneColumnToUsersTable')) {
$this->publishes([
__DIR__ . '/database/migrations/add_timezone_column_to_users_table.php.stub' => database_path('/migrations/' . date('Y_m_d_His') . '_add_timezone_column_to_users_table.php'),
], 'migrations');
}

// Register the Timezone alias
AliasLoader::getInstance()->alias('Timezone', \JamesMills\LaravelTimezone\Facades\Timezone::class);
$this->publishes([
__DIR__ . '/database/migrations/add_timezone_column_to_users_table.php.stub' => database_path('/migrations/' . date('Y_m_d_His') . '_add_timezone_column_to_users_table.php'),
], 'migrations');

// Register an event listener
$this->registerEventListener();
Expand Down Expand Up @@ -84,11 +77,10 @@ public function register()
*/
private function registerEventListener(): void
{
$events = [
\Illuminate\Auth\Events\Login::class,
\Laravel\Passport\Events\AccessTokenCreated::class,
];
$events = config('timezone.events');

Event::listen($events, UpdateUsersTimezone::class);
if (!empty($events)) {
Event::listen($events, UpdateUsersTimezone::class);
}
}
}
Loading