{"library":"rails-timezone","title":"Rails TimeZone Converter","description":"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.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install rails-timezone"],"cli":null},"imports":["import { from } from 'rails-timezone';","import { to } from 'rails-timezone';","window.RailsTimeZone.from('Eastern Time (US & Canada)');","const { from, to } = require('rails-timezone');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { from, to } from 'rails-timezone';\n\n// Example 1: Convert from Rails ActiveSupport name to IANA\nconst railsTimeZoneName = 'Eastern Time (US & Canada)';\nconst ianaTimeZone = from(railsTimeZoneName);\nconsole.log(`Rails TimeZone \"${railsTimeZoneName}\" converts to IANA: \"${ianaTimeZone}\"`);\n// Expected output (America/New_York)\n\n// Example 2: Convert from IANA name to Rails ActiveSupport\nconst ianaTimeZoneName = 'Europe/Berlin';\nconst railsTimeZone = to(ianaTimeZoneName);\nconsole.log(`IANA TimeZone \"${ianaTimeZoneName}\" converts to Rails: \"${railsTimeZone}\"`);\n// Expected output (Berlin)\n\n// Example 3: Handling unknown time zones gracefully (returns undefined)\nconst unknownRails = 'Galactic Time';\nconst unknownIana = from(unknownRails);\nconsole.log(`Unknown Rails TimeZone \"${unknownRails}\" converts to IANA: \"${unknownIana}\"`);\n// Expected output (undefined)\n\nconst unknownIanaName = 'Mars/Equatorial';\nconst unknownRailsName = to(unknownIanaName);\nconsole.log(`Unknown IANA TimeZone \"${unknownIanaName}\" converts to Rails: \"${unknownRailsName}\"`);\n// Expected output (undefined)\n","lang":"typescript","description":"Demonstrates converting time zone names between Rails ActiveSupport and IANA formats, including handling unmapped inputs which return `undefined`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}