Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
countries-and-timezones
Advanced tools
Minimalistic library to work with countries and timezones data.
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.
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);
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.
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.
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.
This is a minimalistic library to work with countries and timezones data.
npm install --save countries-and-timezones
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: [
'America/Bahia_Banderas',
'America/Cancun',
'America/Chihuahua',
'America/Ensenada',
'America/Hermosillo',
'America/Matamoros',
'America/Mazatlan',
'America/Merida',
'America/Mexico_City',
'America/Monterrey',
'America/Ojinaga',
'America/Santa_Isabel',
'America/Tijuana'
]
}
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'
}
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/Berlin',
'Europe/Busingen'
]
}
*/
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
}
*/
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' ]
},
...
}
*/
Returns an object with the data of all timezones.
Example
const ct = require('countries-and-timezones');
const timezones = ct.getAllTimezones();
console.log(timezones);
/*
Prints:
{
'America/Los_Angeles': {
name: 'America/Los_Angeles',
country: 'US',
utcOffset: -480,
utcOffsetStr: '-08:00',
dstOffset: -420,
dstOffsetStr: '-07:00',
aliasOf: null
},
'Africa/Abidjan': {
name: 'Africa/Abidjan',
country: 'CI',
utcOffset: 0,
utcOffsetStr: '+00:00',
dstOffset: 0,
dstOffsetStr: '+00:00',
aliasOf: null
},
'Africa/Accra': {
name: 'Africa/Accra',
country: 'GH',
utcOffset: 0,
utcOffsetStr: '+00:00',
dstOffset: 0,
dstOffsetStr: '+00:00',
aliasOf: null
},
...
}
*/
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: 'America/Bahia_Banderas',
country: 'MX',
utcOffset: -360,
utcOffsetStr: '-06:00',
dstOffset: -300,
dstOffsetStr: '-05:00',
aliasOf: null
},
{
name: 'America/Cancun',
country: 'MX',
utcOffset: -300,
utcOffsetStr: '-05:00',
dstOffset: -300,
dstOffsetStr: '-05:00',
aliasOf: null
},
{
name: 'America/Chihuahua',
country: 'MX',
utcOffset: -420,
utcOffsetStr: '-07:00',
dstOffset: -360,
dstOffsetStr: '-06:00',
aliasOf: null
},
...
}
*/
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' ]
}
*/
Meet Spott:
MIT
FAQs
Minimalistic library to work with countries and timezones data.
The npm package countries-and-timezones receives a total of 56,181 weekly downloads. As such, countries-and-timezones popularity was classified as popular.
We found that countries-and-timezones demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.