Download the PHP package kevinorriss/clienttimezone without Composer
On this page you can find all versions of the php package kevinorriss/clienttimezone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kevinorriss/clienttimezone
More information about kevinorriss/clienttimezone
Files in kevinorriss/clienttimezone
Package clienttimezone
Short Description Use javascript to get the client timezone offset from UTC in minutes
License MIT
Homepage https://github.com/kevinorriss/clienttimezone
Informations about the package clienttimezone
clienttimezone
Gets the clients timezone difference from UTC in minutes using Javascript.
How it works
If the client timezone is not stored in the session, the javascript will fire a POST ajax request, sending the clients current time offset in minutes from the UTC time. This offset is then stored in session and the users browser reloads the current page. Javascript will then only have to do this once, or until a new session is started.
Installation
-
Add ClientTimezone to your composer.json file under
require
:"kevinorriss\clienttimezone": "1.2.*"
-
Add the ClientTimezoneServiceProvider to your app.php file:
KevinOrriss\ClientTimezone\ClientTimezoneServiceProvider::class,
-
Add the ClientTimezone alias to your app.php file:
'ClientTimezone' => KevinOrriss\ClientTimezone\ClientTimezone::class,
- Run
composer update
Usage
In order to use this package, you need to setup your application so that Ajax calls send the CSRF token.
-
Add the following meta tag to your main blade layout file
<meta name="csrf-token" content="{{ csrf_token() }}" />
-
Add the javascript ajax setup code using jquery, you could create
public/js/main.js
and add this script to you main layout -
In your main layout add the following line AFTER your jQuery script tag
@include('clienttimezone::javascript')
Example
Carbon
ClientTimezone is best used with Carbon to display the users current time.
Skipping
There may be times when you do not want javascript to check the client timezone. An example of this is when the client creates a new session on your application by following a URL to verify their email address, this page displays a flash message, but will be shown briefly until Javascript reloads the page. Upon the page reload, the flash message will have expired.
To prevent Javascript from checking the client timezone and reloading the page if it needs to, just add this line to your controller before returning a view.
ClientTimezone::skip();
Overrides
You can override any of the ClientTimezone constant values by simply adding a value of the same name inside the .env file, for example:
Authors
- Kevin Orriss - Website
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details