Download the PHP package imranali/smart-timezone without Composer

On this page you can find all versions of the php package imranali/smart-timezone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package smart-timezone

SmartTimezone for Laravel

Latest Version on Packagist Total Downloads

Stop timezone bugs forever. SmartTimezone auto-detects your users' timezone and makes every datetime "just work" in their local time.

No more ->setTimezone('UTC') spaghetti. No more "why does this show 5 hours off?"

What It Does

  1. Auto-detects timezone — from browser JS → cookie → user profile → IP → fallback
  2. Auto-casts dates — $post->created_at shows in user timezone, saves as UTC
  3. Blade ready — @usertime($datetime) prints "25 Jun 2026, 6:45 PM PKT"
  4. API friendly — Reads X-Timezone header for mobile/SPA apps
  5. Zero config — works for 80% of apps. Supports Laravel 10, 11, 12, 13.

Installation

Make sure your layout <head> has a CSRF token, then add the script before </body>:

The script sets a user_timezone cookie and (when the CSRF token is present) pushes the detected zone to the current session immediately. Without the meta tag it still works — the server just picks the zone up on the next request from the cookie.

That's it. All dates now respect user timezone.


Usage

1. Cast any datetime automatically

2. Blade directive

3. Manual conversion

4. Add to User model

5. API / Mobile App Usage

Send the timezone header from your frontend. SmartTimezone picks it up automatically.

Axios / React
Flutter / Dart

Laravel API response:

Response for a Lahore user:


How Detection Works

When rendering a date, SmartTimezone resolves the timezone in this order:

Priority Source When it's used
1 X-Timezone header API / mobile / SPA requests — overrides everything for that request
2 users.timezone DB Authenticated users — the source of truth once logged in
3 Session Guests — populated by the middleware from the cookie or IP lookup
4 Model's own timezone User-owned rows (e.g. a Post belonging to a user)
5 config('smart-timezone.default') (APP_TIMEZONE) Nothing else matched

The DetectTimezone middleware fills the session once per session for guests, trying detect_from sources in order (header, cookie, user, ip). The user_timezone cookie is set client-side by timezone-detect.js.

Key behaviors

Queues, jobs, commands, and notifications

There is no request, session, or authenticated user in a queued job, an Artisan command, or a queued notification/mail. In those contexts the cast falls back to config('smart-timezone.default'). When you need a specific user's zone outside a request, convert explicitly:


Configuration

Published to config/smart-timezone.php:

Opting out of automatic middleware

By default the package pushes DetectTimezone onto the web group and SetTimezoneFromHeader onto the api group. Set register_middleware to false and add them where you want:

Custom route prefix + JS

If you change route_prefix, tell the detector script where to POST:


Events

ImranAli\SmartTimezone\Events\TimezoneDetected fires whenever a timezone is resolved and written to the session (web middleware, API header middleware, or the JS route). It carries $timezone, $source (header / cookie / user / ip / route / default), and $request.

A common use — copy a guest's detected zone onto their account at registration:


Commands


Requirements


Package Comparison

Package Auto JS Detect API Header Eloquent Cast DB Saves UTC SPA Ready
SmartTimezone ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
jamesmills/laravel-timezone ❌ No ❌ No ✅ Yes ✅ Yes ❌ No
spatie/laravel-timezone ⚠️ Manual ❌ No ❌ No ❌ No ❌ No

Testing


Contributing

PRs welcome! Please ensure tests pass before submitting:


Security

If you discover a security vulnerability, please email [email protected].


License

MIT. Use it in any project, commercial or personal.


Built by Imran Ali in Lahore, PK 🇵🇰

If this saved you from timezone hell, ⭐ star the repo!


All versions of smart-timezone with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/contracts Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
illuminate/routing Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
nesbot/carbon Version ^2.67|^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package imranali/smart-timezone contains the following files

Loading the files please wait ...