Skip to content

Commit

Permalink
feat: get all supported timezones list
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-sharma7 committed Oct 15, 2024
1 parent cf23f82 commit a302a86
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 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.
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 a302a86

Please sign in to comment.