What is countries-and-timezones?
The 'countries-and-timezones' npm package provides utilities for working with country and timezone data. It allows you to retrieve information about countries, their timezones, and perform various operations related to timezones.
What are countries-and-timezones's main functionalities?
Get Country Information
This feature allows you to retrieve information about a specific country using its ISO 3166-1 alpha-2 code. The returned object includes details such as the country's name, timezones, and other relevant data.
const ctz = require('countries-and-timezones');
const country = ctz.getCountry('US');
console.log(country);
Get Timezone Information
This feature allows you to retrieve information about a specific timezone using its IANA timezone identifier. The returned object includes details such as the timezone's name, offset, and other relevant data.
const ctz = require('countries-and-timezones');
const timezone = ctz.getTimezone('America/New_York');
console.log(timezone);
Get All Countries
This feature allows you to retrieve a list of all countries supported by the package. The returned object includes details for each country.
const ctz = require('countries-and-timezones');
const countries = ctz.getAllCountries();
console.log(countries);
Get All Timezones
This feature allows you to retrieve a list of all timezones supported by the package. The returned object includes details for each timezone.
const ctz = require('countries-and-timezones');
const timezones = ctz.getAllTimezones();
console.log(timezones);
Get Timezones for a Country
This feature allows you to retrieve a list of all timezones for a specific country using its ISO 3166-1 alpha-2 code. The returned array includes details for each timezone.
const ctz = require('countries-and-timezones');
const timezones = ctz.getTimezonesForCountry('US');
console.log(timezones);
Other packages similar to countries-and-timezones
moment-timezone
The 'moment-timezone' package is an extension for the 'moment' library to handle timezones. It provides utilities for parsing, manipulating, and displaying dates and times in various timezones. Compared to 'countries-and-timezones', 'moment-timezone' focuses more on date and time manipulation rather than country-specific data.
timezone-support
The 'timezone-support' package provides utilities for working with timezones and converting dates between different timezones. It includes features for parsing and formatting dates, as well as handling daylight saving time. Compared to 'countries-and-timezones', 'timezone-support' is more focused on date and time operations rather than providing country-specific information.
world-countries
The 'world-countries' package provides a comprehensive list of countries with various details such as names, codes, and regions. It is similar to 'countries-and-timezones' in terms of providing country data, but it does not include timezone information.
countries-and-timezones
This is a minimalistic library to work with countries and timezones data.
Install
npm install --save countries-and-timezones
Data models
Country
A country is defined by the following parameters:
- id: The country ISO code.
- name: Name in english.
- timezones: An array of ids of the timezones available in the country.
{
id: 'MX',
name: 'Mexico',
timezones: [
'America/Mexico_City',
'America/Cancun',
'America/Merida',
'America/Monterrey',
'America/Matamoros',
'America/Mazatlan',
'America/Chihuahua',
'America/Ojinaga',
'America/Hermosillo',
'America/Tijuana',
'America/Santa_Isabel',
'America/Bahia_Banderas'
]
}
Timezone
A timezone is defined by the following parameters:
- name: The name of the timezone.
- utcOffset: UTC offset in minutes.
- offsetStr: UTC offset in hours (human readable string).
- countries: An array of ids of the countries that use this timezone.
{
name: 'Asia/Dubai',
utcOffset: 240,
offsetStr: '+04:00',
countries: [ 'AE', 'OM' ]
}
API
.raw
Contains and object with the raw data used in this library.
Example
const ct = require('countries-and-timezones');
const rawData = ct.raw;
console.log(rawData);
.getAllCountries()
Returns an object with the data of all countries.
Example
const ct = require('countries-and-timezones');
const countries = ct.getAllCountries();
console.log(countries);
.getAllTimezones()
Returns an object with the data of all timezones.
Example
const ct = require('countries-and-timezones');
const timezones = ct.getAllTimezones();
console.log(timezones);
.getTimezonesForCountry()
Returns an array with the timezones of a country given its id.
Example
const ct = require('countries-and-timezones');
const mxTimezones = ct.getTimezonesForCountry('MX');
console.log(mxTimezones);
.getCountriesForTimezone()
Returns an array with the country that use a timezone given its id.
Example
const ct = require('countries-and-timezones');
const nyTimezone = ct.getCountriesForTimezone('America/New_York');
console.log(nyTimezone);
License
MIT