time_zone
Version, currently 0.1.02 versions
- 0.1.1latestMay 31, 2018
- 0.1.0not indexedJan 8, 2019
github.com/imdrasil/time_zone
Time Zone provides daylight savings aware transformations between times in different time zones.
Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
time_zone:
github: imdrasil/time_zone
version: ~> 0.1.0Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
# TimeZone [](https://travis-ci.org/imdrasil/time_zone) [](https://github.com/imdrasil/time_zone/releases) [](https://imdrasil.github.io/time_zone/latest/)
**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.
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
time_zone:
github: imdrasil/time_zone
```
## Usage
The following code will obtain the America/New_York timezone (as an instance
of `TZInfo::Timezone`) and convert a time in UTC to local New York time:
```crystal
require "time_zone"
tz = TimeZone::Zone.get("America/New_York")
local = tz.utc_to_local(Time.utc(2005,8,29,15,35,0))
```
Note that the local Time returned will be kind of UTC (`local.kind` will
return `Time::Kind::Utc`). This is because the Crystal `Time` class only supports two timezones:
* UTC
* the current system local timezone.
To convert from a local time to UTC, the `#local_to_utc` method can be used as
follows:
```crystal
utc = tz.local_to_utc(local)
```
Note that the time zone information of the local Time object is ignored (TimeZone
will just read the date and time and treat them as if there were in the `tz`
timezone). The following two lines will return the same result regardless of
the system's local timezone:
```crystal
tz.local_to_utc(Time.new(2006,6,26,1,0,0))
tz.local_to_utc(Time.utc(2006,6,26,1,0,0))
```
The current local time in a `Zone` can be obtained with the
`TimeZone::Zone#now` method:
```crystal
now = tz.now
```
A list of all the available timezone identifiers can be obtained using the
`TimeZone::Zone.all_identifiers` method. `TimeZone::Zone.all` can be called
to get an `Array` of all the `TimeZone::Zone` and `TimeZone::LinkedZone` instances.
Timezones can also be accessed by country (using an ISO 3166-1 alpha-2 country
code). The following code retrieves the `TimeZone::Country` instance representing
the USA (country code 'US') and then gets all the timezone identifiers used in
the USA.
```crystal
us = TimeZone::Country.get('US')
timezones = us.zone_identifiers
```
A list of all the available country codes can be obtained using the
`TimeZone::Country.all_codes` method. `TimeZone::Country.all` can be called to get
an `Array` of all the `Country` instances.
### TimeZone::Time
To 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`:
* `#to_time_zone_time` - converts current time object to `TimeZone::Time` in default time zone;
* `::zone` - returns default time zone.
To set or get default time zone next code can be used:
```crystal
TimeZone::Zone.default # tries to read time zone from `TZ`
# environment variable, otherwise UTC
# will be used
TimeZone::Zone.default = "America/New_York"
# or
TimeZone::Zone.default = TimeZone::Zone.get("America/New_York")
```
To create specific date in time zone:
```crystal
zone.new(2010, 10, 19)
Time.zone.new(2012, 12, 12) # in the default time zone
```
Also `TimeZone::Time` could be parsed from string with grepping given time zone offset:
```crystal
# Time zone will be set to Etc/GMT-5
TimeZone::Time.parse("2014-10-31 10:11:12 +05:00", "%F %T %z")
```
## Development
### Data Generating
All 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`.
## Contributing
1. Fork it ( https://github.com/imdrasil/time_zone/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
## Contributors
* [imdrasil](https://github.com/[your-github-name]) Roman Kalnytskyi - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Jan 8, 2019
- Commit
006bf2a991a3- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/imdrasil/time_zone
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 2