README 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. = TZInfo -- Daylight-savings aware timezone support for Ruby
  2. TZInfo[http://tzinfo.rubyforge.org] uses the tz database
  3. (http://www.twinsun.com/tz/tz-link.htm) to provide
  4. daylight-savings aware transformations between times in different timezones.
  5. This is the same database as used for zoneinfo on Unix machines.
  6. The tz database has been imported (using TZDataParser) and turned into a set of
  7. Ruby modules (which are packaged with this release).
  8. == Example usage
  9. To convert a time in UTC to a local time in the America/New_York timezone, you
  10. can do the following:
  11. require 'tzinfo'
  12. tz = TZInfo::Timezone.get('America/New_York')
  13. local = tz.utc_to_local(Time.utc(2005,8,29,15,35,0))
  14. Note that the Time returned will look like it is UTC (Time.zone will return
  15. "UTC"). This is because it is not currently possible to change the offset of
  16. an individual Time instance.
  17. To convert from a local time to UTC, the local_to_utc method can be used.
  18. utc = tz.local_to_utc(local)
  19. Note that the timezone information of the time you pass in is ignored. The
  20. following two lines will return the same result regardless of the local
  21. timezone:
  22. tz.local_to_utc(Time.local(2006,6,26,1,0,0))
  23. tz.local_to_utc(Time.utc(2006,6,26,1,0,0))
  24. To get information about the rules in force at a particular UTC or local time,
  25. the Timezone.period_for_utc and Timezone.period_for_local methods can be used.
  26. Both of these methods return TimezonePeriod objects. The following gets the
  27. identifier for the period (in this case EDT).
  28. period = tz.period_for_utc(DateTime.new(2005,8,29,15,35,0))
  29. id = period.zone_identifier
  30. In all the above examples, instances of Time can be used instead of DateTime.
  31. Timezone#utc_to_local and Timezone#local_to_utc both return the type they are
  32. passed.
  33. You can get the current local time in a Timezone with the Timezone#now method:
  34. now = tz.now
  35. All methods in TZInfo that take a time can be used with either Time, DateTime
  36. or Integers (Time#to_i). The return type will be the same as the type passed in.
  37. You can also access Timezones by Country (ISO 3166 country code). The following
  38. gets all the Timezone identifiers for the US:
  39. us = TZInfo::Country.get('US')
  40. timezones = us.zone_identifiers
  41. The zone_info method of Country provides an additional description and
  42. location for each Timezone in the Country.
  43. The above covers the most common uses of Timezone and Country. For more detail,
  44. see the API documentation for the individual classes.
  45. == Download
  46. The latest version of TZInfo can be found at
  47. * http://rubyforge.org/frs/?group_id=894
  48. API documentation can be found at
  49. * http://tzinfo.rubyforge.org/doc/
  50. == Installation
  51. The preferred method of installing TZInfo is through the GEM file (RubyGems[http://docs.rubygems.org/] required):
  52. % gem install tzinfo-x.y.z.gem
  53. or to automatically download and install:
  54. % gem install tzinfo --remote
  55. == License
  56. TZInfo is released under the MIT[http://opensource.org/licenses/mit-license.html] license.
  57. == Support
  58. Please post to the TZInfo Users mailing list (http://rubyforge.org/mailman/listinfo/tzinfo-users)
  59. if you require assistance or have any suggestions.
  60. Alternatively, you can contact the author Philip Ross directly at phil.ross@gmail.com.