{"id":17656512,"url":"https://github.com/imdrasil/time_zone","last_synced_at":"2025-05-07T11:43:37.537Z","repository":{"id":81841577,"uuid":"118049869","full_name":"imdrasil/time_zone","owner":"imdrasil","description":"Time Zone provides daylight savings aware transformations between times in different time zones.","archived":false,"fork":false,"pushed_at":"2019-01-08T16:05:52.000Z","size":426,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-21T08:14:06.359Z","etag":null,"topics":["crystal","time","timezone-conversion","timezones"],"latest_commit_sha":null,"homepage":null,"language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imdrasil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-18T23:16:57.000Z","updated_at":"2023-07-25T14:14:23.000Z","dependencies_parsed_at":"2023-10-31T18:00:24.820Z","dependency_job_id":null,"html_url":"https://github.com/imdrasil/time_zone","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imdrasil%2Ftime_zone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imdrasil%2Ftime_zone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imdrasil%2Ftime_zone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imdrasil%2Ftime_zone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imdrasil","download_url":"https://codeload.github.com/imdrasil/time_zone/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252873854,"owners_count":21817708,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","time","timezone-conversion","timezones"],"created_at":"2024-10-23T14:33:15.416Z","updated_at":"2025-05-07T11:43:37.529Z","avatar_url":"https://github.com/imdrasil.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TimeZone [![Build Status](https://travis-ci.org/imdrasil/time_zone.svg)](https://travis-ci.org/imdrasil/time_zone) [![Latest Release](https://img.shields.io/github/release/imdrasil/time_zone.svg)](https://github.com/imdrasil/time_zone/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://imdrasil.github.io/time_zone/latest/)\n\n\u003e Crystal already has own logic of taking care of time zones. Therefore prefer [native](https://crystal-lang.org/api/0.27.0/Time/Location.html) crystal implementation over this library.\n\n**Time Zone** provides daylight savings aware transformations between times in different time zones. Also this is a port of ruby [tzinfo](https://github.com/tzinfo/tzinfo) gem.\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  time_zone:\n    github: imdrasil/time_zone\n```\n\n## Usage\n\nThe following code will obtain the America/New_York timezone (as an instance\nof `TZInfo::Timezone`) and convert a time in UTC to local New York time:\n\n```crystal\nrequire \"time_zone\"\n\ntz = TimeZone::Zone.get(\"America/New_York\")\nlocal = tz.utc_to_local(Time.utc(2005,8,29,15,35,0))\n```\n\nNote that the local Time returned will be kind of UTC (`local.kind` will\nreturn `Time::Kind::Utc`). This is because the Crystal `Time` class only supports two timezones:\n\n* UTC\n* the current system local timezone.\n\nTo convert from a local time to UTC, the `#local_to_utc` method can be used as\nfollows:\n\n```crystal\nutc = tz.local_to_utc(local)\n```\n\nNote that the time zone information of the local Time object is ignored (TimeZone\nwill just read the date and time and treat them as if there were in the `tz`\ntimezone). The following two lines will return the same result regardless of\nthe system's local timezone:\n\n```crystal\ntz.local_to_utc(Time.new(2006,6,26,1,0,0))\ntz.local_to_utc(Time.utc(2006,6,26,1,0,0))\n```\n\nThe current local time in a `Zone` can be obtained with the\n`TimeZone::Zone#now` method:\n\n```crystal\nnow = tz.now\n```\n\nA list of all the available timezone identifiers can be obtained using the\n`TimeZone::Zone.all_identifiers` method. `TimeZone::Zone.all` can be called\nto get an `Array` of all the `TimeZone::Zone` and `TimeZone::LinkedZone` instances.\n\nTimezones can also be accessed by country (using an ISO 3166-1 alpha-2 country\ncode). The following code retrieves the `TimeZone::Country` instance representing\nthe USA (country code 'US') and then gets all the timezone identifiers used in\nthe USA.\n\n```crystal\nus = TimeZone::Country.get('US')\ntimezones = us.zone_identifiers\n```\n\nA list of all the available country codes can be obtained using the\n`TimeZone::Country.all_codes` method. `TimeZone::Country.all` can be called to get\nan `Array` of all the `Country` instances.\n\n### TimeZone::Time\n\nTo hold time zone in the time object `TimeZone::Time` struct could be used. It provides almost same interface as the `Time` does. Also there is 2 methods added to `Time`:\n\n* `#to_time_zone_time` - converts current time object to `TimeZone::Time` in default time zone;\n* `::zone` - returns default time zone.\n\nTo set or get default time zone next code can be used:\n\n```crystal\nTimeZone::Zone.default # tries to read time zone from `TZ`\n                       # environment variable, otherwise UTC\n                       # will be used\nTimeZone::Zone.default = \"America/New_York\"\n# or\nTimeZone::Zone.default = TimeZone::Zone.get(\"America/New_York\")\n```\n\nTo create specific date in time zone:\n\n```crystal\nzone.new(2010, 10, 19)\nTime.zone.new(2012, 12, 12) # in the default time zone\n```\n\nAlso `TimeZone::Time` could be parsed from string with grepping given time zone offset:\n\n```crystal\n# Time zone will be set to Etc/GMT-5\nTimeZone::Time.parse(\"2014-10-31 10:11:12 +05:00\", \"%F %T %z\")\n```\n\n## Development\n\n### Data Generating\n\nAll code in `src/time_zone/data` folder is automatically generated so please don't try to make any change there because they will be lost after next regenerating. To generate new version please paste all files from original [repo](https://github.com/eggert/tz) to the `data` folder in this repo root and invoke `ruby scripts/build.rb`.\n\n## Contributing\n\n1. Fork it ( https://github.com/imdrasil/time_zone/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## Contributors\n\n* [imdrasil](https://github.com/imdrasil) Roman Kalnytskyi - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimdrasil%2Ftime_zone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimdrasil%2Ftime_zone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimdrasil%2Ftime_zone/lists"}