Skip to content

sagrawal31/angular-server-timezone

Repository files navigation

Angular Server Timezone (current v0.0.1)

A simple Angular module which will pass the timezone of user's browser to the every $http request. By default, it sends the timezone in request header under the key User-Time-Zone (name can be changed) but you can change it to pass as request parameter.

This library combines bower-jstz for detecting the timezone. (You don't have to include it explicitly).

Usage

1. Install via Bower

bower install angular-server-timezone --save

2. Add the script to your main HTML file (like index.html)

<script src="bower_components/angular-server-timezone/dist/angular-server-timezone.min.js"></script>

3. Add dependency to your application

var myApp = angular.module("foo", ["server.timezone", "other-foo-depenency"]);

Now, in each HTTP request to the server, you can see the user's current timezone is being sent.

angular-server-timezone

4. Customizations

By default, this module send the timezone in header with name User-Time-Zone which can be customized in your app's config. Also, you can send the timezone as the request parameter instead of header or both where paramter name can also be customized.

amyApp.config(['serverTimeZoneConfigProvider', function (serverTimeZoneConfig) {

    serverTimeZoneConfig.sendAsHeader = true;              // Default
    serverTimeZoneConfig.headerName = 'fooTimeZone';        // Default to User-Time-Zone

    serverTimeZoneConfig.sendAsParameter = false;              // Default
    serverTimeZoneConfig.headerName = 'barTimeZone';        // Default to userTimeZone
}]);

About

A simple AngularJS extension to pass user's browser timezone with each $http request

Resources

License

Stars

Watchers

Forks

Packages

No packages published