Skip to content

Commit 9a749de

Browse files
committed
Create README.md
1 parent 0c9eb08 commit 9a749de

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# clienttimezone
2+
Gets the clients timezone difference from UTC in minutes using Javascript.
3+
4+
## How it works
5+
If the client timezone is not stored in the session, the javascript will fire a POST ajax
6+
request, sending the clients current time offset in minutes from the UTC time. This offset
7+
is then stored in session and the users browser reloads the current page. Javascript will
8+
then only have to do this once, or until a new session is started.
9+
10+
## Installation
11+
12+
1. Add ClientTimezone to your composer.json file under `require`:
13+
14+
`"kevinorriss\clienttimezone": "1.0.*"`
15+
16+
2. Add a PSR-4 entry to your composer.json file under `autoload/psr-4`:
17+
18+
`"KevinOrriss\\ClientTimezone\\": "vendor/kevinorriss/clienttimezone/src/"`
19+
20+
3. Add the ClientTimezoneServiceProvider to your app.php file:
21+
22+
`KevinOrriss\ClientTimezone\ClientTimezoneServiceProvider::class,`
23+
24+
4. Add the ClientTimezone alias to your app.php file:
25+
26+
`'ClientTimezone' => KevinOrriss\ClientTimezone\ClientTimezone::class,`
27+
28+
5. Run `composer update`
29+
30+
## Usage
31+
32+
In order to use this package, you need to setup your application so that Ajax calls send the
33+
CSRF token.
34+
35+
1. Add the following meta tag to your main blade layout file
36+
37+
`<meta name="csrf-token" content="{{ csrf_token() }}" />`
38+
39+
2. Add the javascript ajax setup code using jquery, you could create `public/js/main.js` and add this script to you main layout
40+
41+
```
42+
$(document).ready(function()
43+
{
44+
$.ajaxSetup(
45+
{
46+
headers:
47+
{
48+
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
49+
}
50+
});
51+
});
52+
```
53+
3. In your main layout add the following line AFTER your jQuery script tag
54+
55+
`@include('clienttimezone::javascript')`
56+
57+
## Example
58+
59+
ClientTimezone is best used with Carbon to display the users current time.
60+
61+
```
62+
$carbon = Carbon::now();
63+
$carbon->addMinutes(ClientTimezone::getOffset());
64+
```
65+
66+
## Authors
67+
68+
* **Kevin Orriss** - [Website](http://kevinorriss.com)
69+
70+
See also the list of [contributors](https://github.com/kevinorriss/clienttimezone/graphs/contributors) who participated in this project.
71+
72+
## License
73+
74+
This project is licensed under the MIT License - see the [LICENSE](src/LICENSE) file for details

0 commit comments

Comments
 (0)