A high-level time zone package for Meteor. Aims to have the same simple API on client and server. Currently uses the Google Time Zone API (part of the Google Maps API) for time zone geolocation and moment-timezone for Date
handling, but could be adapted to support configurable data sources. Pull requests and issues are welcome.
$ meteor add aldeed:timezoned
Here are some ways to use this package.
On the client or server:
TimeZoned.getDateObjectForAddress("2014-05-12T12:00", "5700 S Lake Shore Dr, Chicago, IL 60637", function (error, date) {
});
The first argument is a local date and time and the second is any address that will be geocoded to determine the time zone and the proper UTC offset that was (or will be) in effect on the given date and time. The result is a Date object set to the given time at the calculated UTC offset.
On the server, the callback is optional:
var date = TimeZoned.getDateObjectForAddress("2014-05-12T12:00", "5700 S Lake Shore Dr, Chicago, IL 60637");
On the client or server:
TimeZoned.getDateObjectForCoords("2014-05-12T12:00", "41.8337329", "-87.7321555", function (error, date) {
});
The first argument is a local date and time, the second is the latitude, and the third is the longitude. The coordinates are used to determine the time zone and the proper UTC offset that was (or will be) in effect on the given date and time. The result is a Date object set to the given time at the calculated UTC offset.
On the server, the callback is optional:
var date = TimeZoned.getDateObjectForCoords("2014-05-12T12:00", "41.8337329", "-87.7321555");
On the client or server:
var date = TimeZoned.getDateObjectForTimeZone("2014-05-12T12:00", "America/Chicago");
The first argument is a local date and time and the second is a time zone ID from the IANA time zone database. This is a synchronous function.
On the client or server:
TimeZoned.getTimeZoneForAddress("5700 S Lake Shore Dr, Chicago, IL 60637", function (error, tz) {
});
The first argument is any address that will be geocoded to determine the time zone ID from the IANA time zone database for that location on earth.
On the server, the callback is optional:
var tz = TimeZoned.getTimeZoneForAddress("5700 S Lake Shore Dr, Chicago, IL 60637");
On the client or server:
TimeZoned.getTimeZoneForCoords("41.8337329", "-87.7321555", function (error, tz) {
});
The first argument is the latitude and the second is the longitude. The result is the time zone ID from the IANA time zone database for that location on earth.
On the server, the callback is optional:
var tz = TimeZoned.getTimeZoneForCoords("41.8337329", "-87.7321555");
On the client or server:
var offset = TimeZoned.getOffsetStringForTimeZone("2014-05-12T12:00", "America/Chicago");
The first argument is a local date and time and the second is the time zone ID from the IANA time zone database. The return value is the UTC offset that was (or will be) in effect at that time, on that day, in that time zone. This is a synchronous function.
If you have an Google Maps API key or Google Maps API for Business credentials, you can provide them.
TimeZoned.config({
gtzParams: {
key: '',
client: '',
signature: ''
}
});