Skip to content

Commit

Permalink
feat: get all supported timezones list (#10)
Browse files Browse the repository at this point in the history
* feat: get all supported timezones list

* v1.3.2
  • Loading branch information
shivarm authored Oct 15, 2024
1 parent cf23f82 commit 3be820a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<summary>How to Use</summary>

- [Get Current Time in Zone](./guide/getCurrentTimeInZone.md)
- [Get list of Time Zones](./guide/getListOfSupportedTimeZones.md)
- [Convert Time Zone](./guide/convertTimeZone.md)
- [Time Zone Offset Difference](./guide/getTimeZoneOffsetDifference.md)
- [Format Date in Time Zone](./guide/formatDateInTimeZone.md)
Expand Down
34 changes: 34 additions & 0 deletions docs/guide/getListOfSupportedTimeZones.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Supported Timezones

## Description

This function returns a list of all supported IANA timezones, making it easy to access and work with timezone data.

## Usage

```javascript
import { getSupportedTimezones } from 'world-clockify';

const timezones = getSupportedTimezones();
```

## Expected Output

```bash

Africa/Abidjan',
'Africa/Accra',
'Africa/Addis_Ababa',
'Africa/Algiers',
'Africa/Asmera',
'Africa/Bamako',
'Africa/Bangui',
'Africa/Banjul',
'Africa/Bissau',
... more items
```
## Returns
Returns: strings[], Array of string each representing a valid IANA timezone.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "world-clockify",
"version": "1.1.2",
"version": "1.3.2",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand All @@ -13,6 +13,7 @@
},
"files": [
"dist",
"docs",
"src",
"LICENSE",
"REDME.md"
Expand All @@ -24,7 +25,7 @@
"zone",
"converter"
],
"homepage": "https://github.com/shivam-sharma7/world-clockify",
"homepage": "https://shivam-sharma7.github.io/world-clockify/#/",
"repository": {
"type": "git",
"url": "git+https://github.com/shivam-sharma7/world-clockify.git"
Expand Down
11 changes: 11 additions & 0 deletions src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,14 @@ export const calculateDuration = (

return duration;
};

/**
* Returns a list of all supported IANA timezones using the Javascript Intl API.
* @returns {string[]} - An array of supported timezone strings.
*/
export const getSupportedTimezones = (): string[] => {
const getListOfSupportedTimeZones = Intl.supportedValuesOf('timeZone');
console.log('Get all all supported IANA timezones', getListOfSupportedTimeZones);

return getListOfSupportedTimeZones;
};
6 changes: 6 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getTimeDifference,
formatDateInTimeZone,
calculateDuration,
getSupportedTimezones,
} from '../src/function.js';

describe('Timezone-Aware Date Helper', () => {
Expand Down Expand Up @@ -63,4 +64,9 @@ describe('Timezone-Aware Date Helper', () => {
expect(durationInHours).toBe(72); // 3 days * 24 hours = 72 hours
expect(durationInMinutes).toBe(4320); // 72 hours * 60 minutes = 4320 minutes
});

it('should returns a list of all supported IANA timezones', () => {
const timezones = getSupportedTimezones();
expect(timezones);
});
});

0 comments on commit 3be820a

Please sign in to comment.