This `rails-timezone` package (version 1.2.0) provides essential utility functions for converting between the time zone names used by Rails' ActiveSupport and the universally recognized IANA Time Zone Database (also known as the Olsen database). Its primary purpose is to bridge the naming discrepancy between these two systems, ensuring compatibility for applications that interface with Rails backends. The library implements the exact mapping found in ActiveSupport's `time_zone.rb`, guaranteeing consistent conversions. While major releases are likely tied to significant changes in Rails' time zone handling, its current version offers stable functionality for both Node.js and browser environments, complete with TypeScript type definitions for improved development. Its key differentiator is its direct and accurate reflection of Rails' specific time zone naming conventions, unlike more general time zone libraries.
npm install rails-timezoneVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting time zone names between Rails ActiveSupport and IANA formats, including handling unmapped inputs which return `undefined`.
Always pin the `rails-timezone` package version in your project to ensure consistent behavior. Check release notes for updates when upgrading your Rails backend or `rails-timezone`.
Always check the return value for `undefined` before using the result: `const iana = from(railsZone); if (iana) { /* use iana */ } else { /* handle unmapped zone */ }`.If a collision is suspected or to avoid it proactively, consider using a module bundler (like Webpack, Rollup, or Vite) to scope the library's imports, or ensure careful management of global namespaces in your application.
For ES modules, use named import: `import { from } from 'rails-timezone';`. For CommonJS, use destructuring: `const { from } = require('rails-timezone');`.Add a declaration file (`.d.ts`) to your project or augment the `Window` interface: `declare global { interface Window { RailsTimeZone: { from: (tz: string) => string | undefined; to: (tz: string) => string | undefined; }; } }`.Run `npm install rails-timezone` or `yarn add rails-timezone`. Verify that the import path `'rails-timezone'` is correct.
No dependency data recorded yet.