@callstack/timezone-hermes-fix

中文文档
0.5.1发布于 2026/11/04MITTypeScriptCommonJS零依赖近 30 天下载 2969

Fix for resetting the timezone cache, while the timezone is changed

原始使用文档
文档目录16 节
  1. 🚀 React Native Support
  2. 🔧 The Problem
  3. 📦 Installation
  4. Using Yarn (recommended)
  5. Using npm
  6. 🎯 Usage
  7. Quick Start with Hook
  8. Direct Native Module Usage
  9. 📱 API Reference
  10. Types
  11. Methods
  12. Hook
  13. 🧪 Example App
  14. 🤝 Contributing
  15. 📄 License
  16. Made with ❤️ at Callstack

🕐 Timezone Hermes Fix

Timezone Hermes Fix is a cross-platform React Native library that provides a robust workaround for timezone-related issues when using the Hermes JavaScript engine. It includes native modules for both Android and iOS, designed as a drop-in solution for React Native projects requiring accurate timezone handling.

🚀 React Native Support

Library VersionReact Native Version
0.1.x - 0.3.x0.80.2 - 0.81.x
0.4.x0.82.x - 0.86.x
0.5.x0.87.x and above

🔧 The Problem

React Native apps using the Hermes JavaScript engine may experience timezone calculation issues, particularly when:

  • The device timezone changes while the app is running
  • Date/time calculations don't reflect the current timezone
  • Inconsistent behavior across different devices or regions

This library fixes these known issues by providing native timezone cache reset.

📦 Installation

yarn add @callstack/timezone-hermes-fix

Using npm

npm install @callstack/timezone-hermes-fix

🎯 Usage

Quick Start with Hook

The easiest way to use the library is with the provided React hook:

import React from 'react';
import { View, Text } from 'react-native';
import { useTimezoneHermesFix } from '@callstack/timezone-hermes-fix';

export default function App() {
  const { currentTimezone } = useTimezoneHermesFix();

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Current Timezone: {currentTimezone}</Text>
      <Text>Current Time: {new Date().toLocaleString()}</Text>
    </View>
  );
}

Direct Native Module Usage

For more control, you can use the native module directly:

import { NativeTimezoneHermesFix } from '@callstack/timezone-hermes-fix';

// Get current timezone information
const timezone = NativeTimezoneHermesFix.getCurrentTimeZone();
console.log('Timezone:', timezone.name); // "America/New_York"
console.log('GMT Offset:', timezone.secondsFromGMT); // -18000 (for EST)
console.log('DST Active:', timezone.isDaylightSavingTime); // true/false

// Get all supported timezones
const supportedTimezones = NativeTimezoneHermesFix.getSupportedTimeZones();
console.log('Available timezones:', supportedTimezones.length);

// Listen for timezone changes
const subscription = NativeTimezoneHermesFix.onTimezoneChange.addListener(
  (newTimezone) => {
    console.log('Timezone changed to:', newTimezone.name);
    console.log('New GMT offset:', newTimezone.secondsFromGMT);
    console.log('DST status:', newTimezone.isDaylightSavingTime);
  }
);

// Clean up listener when component unmounts
// subscription.remove();

📱 API Reference

Types

type CurrentTimezone = {
  name: string; // e.g., "America/New_York"
  secondsFromGMT: number; // Offset in seconds from GMT
  isDaylightSavingTime: boolean; // Whether DST is currently active
};

Methods

getCurrentTimeZone(): CurrentTimezone

Returns the current timezone information.

getSupportedTimeZones(): string[]

Returns an array of all supported timezone identifiers.

onTimezoneChange: EventEmitter<CurrentTimezone>

Event emitter that fires when the device timezone changes.

Hook

useTimezoneHermesFix(): { currentTimezone: string }

React hook that automatically updates when the timezone changes.

🧪 Example App

A complete example app is included in the repository. To run it:

# Clone the repository
git clone https://github.com/callstack/timezone-hermes-fix.git
cd timezone-hermes-fix

# Install dependencies
yarn

# Run on iOS
yarn example ios

# Run on Android
yarn example android

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This project is licensed under the MIT License. See LICENSE for details.

Made with ❤️ at Callstack

@callstack/timezone-hermes-fix is an open source project and will always remain free to use. If you think it's cool, please star it 🌟. Callstack is a group of React and React Native geeks, contact us at [email protected] if you need any help with these or just want to say hi!

版本与发布记录

@callstack/timezone-hermes-fix 共发布 6 个版本,首次发布于 2025/07/25;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.5.1latest2026/11/045 天前
0.5.02026/08/212 个月前
0.4.02025/12/0211 个月前
0.3.02025/08/281.2 年前
0.2.02025/07/251.3 年前
0.1.12025/07/251.3 年前

关于 @callstack/timezone-hermes-fix 的常见问题

@callstack/timezone-hermes-fix 是什么?

Fix for resetting the timezone cache, while the timezone is changed

如何安装 @callstack/timezone-hermes-fix?

在项目目录运行 npm install @callstack/timezone-hermes-fix,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(>= 0.87.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@callstack/timezone-hermes-fix 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@callstack/timezone-hermes-fix 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@callstack/timezone-hermes-fix 可以商用吗?

@callstack/timezone-hermes-fix 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@callstack/timezone-hermes-fix 的下载量有多少?

根据 npm 官方下载统计,@callstack/timezone-hermes-fix 在 2026/10/09 – 2026/11/07 这 30 天内被下载 2,969 次,日均约 99 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@callstack/timezone-hermes-fix 还在维护吗?

最新版本 0.5.1 发布于 2026/11/04(5 天前);至今共发布 6 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/07/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。