npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

world-time-converter

v1.0.2

Published

Advanced time conversion and timezone management library with support for business hours, holidays, and locale-specific formatting

Downloads

15

Readme

World Time Converter

npm Version TypeScript License Downloads Node Version

A powerful TypeScript library for handling worldwide time conversions, business hours calculations, and timezone management. Perfect for applications dealing with international time coordination, business hours overlap, and holiday scheduling.

🌟 Key Features

  • 🌍 Global Timezone Support: Convert times between any cities worldwide
  • 💼 Business Hours Management: Calculate working hours overlap across timezones
  • 📅 Holiday Handling: Manage holidays and business days
  • DST Aware: Automatic handling of Daylight Saving Time transitions
  • 🔍 Type Safety: Full TypeScript support with comprehensive type definitions
  • 🌐 Locale Support: Format dates and times according to different locales

📦 Installation

npm install world-time-converter

🚀 Quick Start

Basic Time Operations

import { WorldTimeConverter } from 'world-time-converter';

// Get current time for a city
const londonTime = WorldTimeConverter.getCurrentTime('London');
console.log(londonTime);
/* Output:
{
  cityName: 'London',
  timezone: 'Europe/London',
  localTime: '14:30:45',
  utcOffset: '+01:00',
  date: '2024-03-15',
  dayOfWeek: 'Friday',
  isDST: true,
  epoch: 1710510645,
  iso8601: '2024-03-15T14:30:45.000Z',
  formattedDateTime: 'Friday, March 15, 2024 2:30 PM'
}
*/

// Convert between cities
const tokyoTime = WorldTimeConverter.convertTime(
  '2024-03-15T14:30:00Z',
  'London',
  'Tokyo'
);

💡 Advanced Usage

🕒 Time Comparison

// Compare times between cities
const comparison = WorldTimeConverter.compareTimeBetweenCities('London', 'Tokyo');
console.log(comparison);
/* Output:
{
  city1: { cityName: 'London', ... },
  city2: { cityName: 'Tokyo', ... },
  timeDifference: { hours: 8, minutes: 0 },
  isSameDay: false,
  hoursDifference: 8,
  minutesDifference: 0
}
*/

💼 Business Hours Management

const businessHours1 = {
  start: '09:00',
  end: '17:00',
  timezone: 'Europe/London'
};

const businessHours2 = {
  start: '09:00',
  end: '17:00',
  timezone: 'Asia/Tokyo'
};

const overlap = WorldTimeConverter.findWorkingHoursOverlap(
  'London',
  'Tokyo',
  businessHours1,
  businessHours2
);

// Calculate business days
const businessDays = WorldTimeConverter.getBusinessDaysBetween(
  'London',
  '2024-03-01',
  '2024-03-15',
  true  // Skip holidays
);

📅 Holiday Management

// Add a holiday
const holiday = {
  name: 'Christmas Day',
  date: '2024-12-25',
  recurring: true,
  type: 'public'
};

WorldTimeConverter.addHoliday('London', holiday);

// Check if date is holiday
const isHoliday = WorldTimeConverter.isHoliday('London', '2024-12-25');

🌐 Locale Support

// Format time with specific locale
const formattedTime = WorldTimeConverter.formatTimeWithLocale(
  'Paris',
  'fr',
  'LLLL'
);
console.log(formattedTime);
// Output: 'vendredi 15 mars 2024 14:30'

📋 Type Definitions

interface TimeResult {
  cityName: string;
  timezone: string;
  localTime: string;
  utcOffset: string;
  date: string;
  dayOfWeek: string;
  isDST: boolean;
  epoch: number;
  iso8601: string;
  formattedDateTime: string;
}

interface BusinessHours {
  start: string;     // Format: HH:mm
  end: string;       // Format: HH:mm
  timezone: string;
}

interface HolidayDefinition {
  name: string;
  date: string;      // Format: YYYY-MM-DD
  recurring: boolean;
  type: string;
}

interface TimezoneInfo {
  cityName: string;
  timezone: string;
  currentOffset: string;
  isDST: boolean;
  dstStart: string;
  region: string;
  subregion: string;
}

🔍 Error Handling

try {
  const time = WorldTimeConverter.getCurrentTime('InvalidCity');
} catch (error) {
  if (error instanceof InvalidCityError) {
    console.error('Invalid city:', error.message);
  } else if (error instanceof InvalidTimeFormatError) {
    console.error('Invalid time format:', error.message);
  } else {
    console.error('Unexpected error:', error);
  }
}

🚀 Best Practices

  1. Always use valid city names from the moment-timezone database
  2. Use proper time formats:
    • HH:mm for time (24-hour format)
    • YYYY-MM-DD for dates
  3. Consider DST when working with dates across different seasons
  4. Handle timezone edge cases (e.g., DST transitions)
  5. Cache timezone information for frequently used cities
  6. Use Unix timestamps for precise calculations

🛠️ Development

# Install dependencies
npm install

# Run tests
npm test

# Run tests with coverage
npm test -- --coverage

# Build the project
npm run build

# Lint the code
npm run lint

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -am 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

💬 Support

For support, please open an issue on GitHub.

🙏 Credits

This package uses Moment.js and Moment Timezone for timezone calculations.