All Projects → manuelmhtr → Countries And Timezones

manuelmhtr / Countries And Timezones

Licence: mit
Minimalistic library to work with countries and timezones data

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Countries And Timezones

civicstack
A repository for open source civic tools from many countries and organizations
Stars: ✭ 36 (-37.93%)
Mutual labels:  countries
Date Holidays
worldwide holidays
Stars: ✭ 509 (+777.59%)
Mutual labels:  countries
Factbook.json
World Factbook Country Profiles in JSON - Free Open Public Domain Data - No API Key Required ;-)
Stars: ✭ 750 (+1193.1%)
Mutual labels:  countries
oracle-geo-data
demo.insum.ca/ords/f?p=131
Stars: ✭ 20 (-65.52%)
Mutual labels:  countries
Getcountries
MySQL, Firebird, XML, JSON, CSV or YAML generator for custom Countries data.
Stars: ✭ 343 (+491.38%)
Mutual labels:  countries
Countries
World countries in JSON, CSV, XML and Yaml. Any help is welcome!
Stars: ✭ 5,379 (+9174.14%)
Mutual labels:  countries
countriesNowAPI
CountriesNow is an Open source API for retrieving geo-information for countries, including their states, cities, population, etc. 🌎
Stars: ✭ 78 (+34.48%)
Mutual labels:  countries
Country Fns
🌏 Useful country data for forms and stuff.
Stars: ✭ 35 (-39.66%)
Mutual labels:  countries
Easyvpn
Easily connect to a VPN in a country of your choice.
Stars: ✭ 492 (+748.28%)
Mutual labels:  countries
Geographer
PHP library that knows how countries and cities are called in any language
Stars: ✭ 714 (+1131.03%)
Mutual labels:  countries
react-vector-maps
🗺 A React component for interactive vector maps of the world and 100+ countries
Stars: ✭ 112 (+93.1%)
Mutual labels:  countries
React Native Phone Verification
The best React Native example for phone verification (an alternative to Twitter Digits).
Stars: ✭ 332 (+472.41%)
Mutual labels:  countries
Countries
Countries, Languages & Continents data (capital and currency, native name, calling codes).
Stars: ✭ 656 (+1031.03%)
Mutual labels:  countries
test-your-markup
Just a game, made for fun, to test developers HTML5 and JavaScript knowledge, and typing speed!
Stars: ✭ 12 (-79.31%)
Mutual labels:  countries
React Native Country Picker Modal
🇦🇶 Country picker provides a modal allowing a user to select a country from a list. It display a flag next to each country name.
Stars: ✭ 775 (+1236.21%)
Mutual labels:  countries
agegate
A simple function that verifies a date of birth against a country's legal drinking age.
Stars: ✭ 16 (-72.41%)
Mutual labels:  countries
World countries
Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CSV, JSON , PHP and SQL formats, in multiple languages and with national flags included
Stars: ✭ 598 (+931.03%)
Mutual labels:  countries
Svg World Map
🗺 A JavaScript library to easily integrate one or more SVG world maps with all nations (countries) and second-level political subdivisions (countries, provinces, states).
Stars: ✭ 38 (-34.48%)
Mutual labels:  countries
Yasumi
The easy PHP Library for calculating holidays
Stars: ✭ 788 (+1258.62%)
Mutual labels:  countries
Country Json
A simple data of the world by country each in JSON format.
Stars: ✭ 688 (+1086.21%)
Mutual labels:  countries

countries-and-timezones

A minimalistic library to work with countries and timezones data. Updated with the IANA timezones database.

Usage

NodeJS

Install with npm or yarn:

npm install --save countries-and-timezones

Browser

Add the following script to your project (only ~9kb):

<!-- Latest version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/[email protected]/dist/index.js" type="text/javascript"></script>

<!-- Or specify a version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/[email protected]/dist/index.js" type="text/javascript"></script>

<!-- This will export a variable named "ct": -->
<script type="text/javascript">
  var data = ct.getCountry('MX');
  console.log(data);
</script>

API

.getCountry(id)

Returns a country referenced by its id.

Example

const ct = require('countries-and-timezones');

const country = ct.getCountry('DE');
console.log(country);

/*
Prints:

{
  id: 'DE',
  name: 'Germany',
  timezones: [ 'Europe/Busingen', 'Europe/Berlin' ]
}

*/

.getTimezone(name)

Returns a timezone referenced by its name.

Example

const ct = require('countries-and-timezones');

const timezone = ct.getTimezone('America/Los_Angeles');
console.log(timezone);

/*
Prints:

{
  name: 'America/Los_Angeles',
  country: 'US',
  utcOffset: -480,
  utcOffsetStr: '-08:00',
  dstOffset: -420,
  dstOffsetStr: '-07:00',
  aliasOf: null
}

*/

.getAllCountries()

Returns an object with the data of all countries.

Example

const ct = require('countries-and-timezones');

const countries = ct.getAllCountries();
console.log(countries);

/*
Prints:

{
  AD: {
    id: 'AD',
    name: 'Andorra',
    timezones: [ 'Europe/Andorra' ]
  },
  AE: {
    id: 'AE',
    name: 'United Arab Emirates',
    timezones: [ 'Asia/Dubai' ]
  },
  AF: {
    id: 'AF',
    name: 'Afghanistan',
    timezones: [ 'Asia/Kabul' ]
  },
  AG: {
    id: 'AG',
    name: 'Antigua and Barbuda',
    timezones: [ 'America/Antigua' ]
  },
  ...
}

*/

.getAllTimezones()

Returns an object with the data of all timezones.

Example

const ct = require('countries-and-timezones');

const timezones = ct.getAllTimezones();
console.log(timezones);

/*
Prints:

{
  'Africa/Bamako': {
    name: 'Africa/Bamako',
    country: 'ML',
    utcOffset: 0,
    utcOffsetStr: '+00:00',
    dstOffset: 0,
    dstOffsetStr: '+00:00',
    aliasOf: 'Africa/Abidjan'
  },
  'Africa/Banjul': {
    name: 'Africa/Banjul',
    country: 'GM',
    utcOffset: 0,
    utcOffsetStr: '+00:00',
    dstOffset: 0,
    dstOffsetStr: '+00:00',
    aliasOf: 'Africa/Abidjan'
  },
  'Africa/Conakry': {
    name: 'Africa/Conakry',
    country: 'GN',
    utcOffset: 0,
    utcOffsetStr: '+00:00',
    dstOffset: 0,
    dstOffsetStr: '+00:00',
    aliasOf: 'Africa/Abidjan'
  },
  ...
}

*/

.getTimezonesForCountry(id)

Returns an array with all the timezones of a country given its id.

Example

const ct = require('countries-and-timezones');

const timezones = ct.getTimezonesForCountry('MX');
console.log(timezones);

/*
Prints:

[
  {
    name: 'Mexico/BajaSur',
    country: 'MX',
    utcOffset: -420,
    utcOffsetStr: '-07:00',
    dstOffset: -360,
    dstOffsetStr: '-06:00',
    aliasOf: 'America/Mazatlan'
  },
  {
    name: 'Mexico/General',
    country: 'MX',
    utcOffset: -360,
    utcOffsetStr: '-06:00',
    dstOffset: -300,
    dstOffsetStr: '-05:00',
    aliasOf: 'America/Mexico_City'
  },
  {
    name: 'America/Ensenada',
    country: 'MX',
    utcOffset: -480,
    utcOffsetStr: '-08:00',
    dstOffset: -420,
    dstOffsetStr: '-07:00',
    aliasOf: 'America/Tijuana'
  },
  ...
}

*/

.getCountryForTimezone(name)

Returns the country that uses a timezone given its name.

Example

const ct = require('countries-and-timezones');

const timezone = ct.getCountryForTimezone('Asia/Tokyo');
console.log(timezone);

/*
Prints:

{
  id: 'JP',
  name: 'Japan',
  timezones: [ 'Asia/Tokyo' ]
}

*/

Data models

Country

A country is defined by the following parameters:

Parameter Type Description
id String The country ISO 3166-1 code.
name String Preferred name of the country.
timezones Array[String] The list of timezones used in the country.
{
  id: 'MX',
  name: 'Mexico',
  timezones: [
    'Mexico/BajaSur',
    'Mexico/General',
    'America/Ensenada',
    'America/Santa_Isabel',
    'Mexico/BajaNorte',
    'America/Bahia_Banderas',
    'America/Cancun',
    'America/Chihuahua',
    'America/Tijuana',
    'America/Hermosillo',
    'America/Matamoros',
    'America/Mazatlan',
    'America/Merida',
    'America/Mexico_City',
    'America/Monterrey',
    'America/Ojinaga'
  ]
}

Timezone

A timezone is defined by the following parameters:

Parameter Type Description
name String The name of the timezone, from tz database.
country String The ISO 3166-1 code of the country where it's used. Etc/*, GMT and UTC timezones don't have and associated country.
utcOffset Number The difference in minutes between the timezone and UTC.
utcOffsetStr String The difference in hours and minutes between the timezone and UTC, expressed as string with format: ±[hh]:[mm].
dstOffset Number The difference in minutes between the timezone and UTC during daylight saving time (DST). When utcOffset and dstOffset are the same, means that the timezone does not observe a daylight saving time.
dstOffsetStr String The difference in hours and minutes between the timezone and UTC during daylight saving time (DST, expressed as string with format: ±[hh]:[mm].
aliasOf String The name of a primary timezone in case this is an alias. null means this is a primary timezone.
{
  name: 'Asia/Tel_Aviv',
  country: 'IL',
  utcOffset: 120,
  utcOffsetStr: '+02:00',
  dstOffset: 180,
  dstOffsetStr: '+03:00',
  aliasOf: 'Asia/Jerusalem'
}

Related projects

Working on something more complex?

Meet Spott:

  • Search any city, country or administrative division in the world. By full strings or autocompletion.
  • Find a place by an IP address.
  • Access to more than 240,000 geographical places. In more than 20 languages.

Spott API for cities, countries and administrative divisions

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].