tz 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +10 -0
- data/lib/tz.rb +229 -0
- data/lib/tz/version.rb +3 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/tz_spec.rb +47 -0
- data/tz.gemspec +26 -0
- metadata +129 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: d92526a5daac6192e54fc04952dd26ffd0f8008a
         | 
| 4 | 
            +
              data.tar.gz: c1b95922ea218cd80ba7a3353dced53f1cfd401a
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: a22caf49560cd427a4d26e0716488b44fa5e7218bbac6bf2c5f82776a93de158e3e50d77eb44fd3bc2bfd5101ec48a0eeb5bbe2a019a6d3adaa6b6a661720bb7
         | 
| 7 | 
            +
              data.tar.gz: 383442c116cb546e31b246933c28c21003e284e3c053a3057fd0fcb1938fdef8871ba796f34dab644370ccd0dd263a6cf79a5b150877a0638163d6068b14f339
         | 
    
        data/.gitignore
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            *.gem
         | 
| 2 | 
            +
            *.rbc
         | 
| 3 | 
            +
            .bundle
         | 
| 4 | 
            +
            .config
         | 
| 5 | 
            +
            .yardoc
         | 
| 6 | 
            +
            Gemfile.lock
         | 
| 7 | 
            +
            InstalledFiles
         | 
| 8 | 
            +
            _yardoc
         | 
| 9 | 
            +
            coverage
         | 
| 10 | 
            +
            doc/
         | 
| 11 | 
            +
            lib/bundler/man
         | 
| 12 | 
            +
            pkg
         | 
| 13 | 
            +
            rdoc
         | 
| 14 | 
            +
            spec/reports
         | 
| 15 | 
            +
            test/tmp
         | 
| 16 | 
            +
            test/version_tmp
         | 
| 17 | 
            +
            tmp
         | 
| 18 | 
            +
            *.bundle
         | 
| 19 | 
            +
            *.so
         | 
| 20 | 
            +
            *.o
         | 
| 21 | 
            +
            *.a
         | 
| 22 | 
            +
            mkmf.log
         | 
| 23 | 
            +
            *.komodoproject
         | 
| 24 | 
            +
            .rbenv-gemsets
         | 
    
        data/.ruby-version
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            2.1.2
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2014 Cecilia Rivero and Cristian Rasch
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # Tz
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Displays UTC time/datatime objects in a specified timezone.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                gem 'tz'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            And then execute:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                $ bundle
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            Or install it yourself as:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ gem install tz
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## Usage
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ```ruby
         | 
| 22 | 
            +
            TZ::TimeWithZone.new(Time.now).in_time_zone("Eastern Time (US & Canada)")
         | 
| 23 | 
            +
            # => "Sat, 07 Jun 2014 17:23:53 EDT -04:00"
         | 
| 24 | 
            +
            ```
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            ## Contributing
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            1. Fork it ( https://github.com/wecodeio/tz/fork )
         | 
| 29 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 30 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 31 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 32 | 
            +
            5. Create a new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/lib/tz.rb
    ADDED
    
    | @@ -0,0 +1,229 @@ | |
| 1 | 
            +
            require "tzinfo"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative "tz/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module TZ
         | 
| 6 | 
            +
              class TimeWithZone
         | 
| 7 | 
            +
                MAPPING = {
         | 
| 8 | 
            +
                  "International Date Line West" => "Pacific/Midway",
         | 
| 9 | 
            +
                  "Midway Island"                => "Pacific/Midway",
         | 
| 10 | 
            +
                  "American Samoa"               => "Pacific/Pago_Pago",
         | 
| 11 | 
            +
                  "Hawaii"                       => "Pacific/Honolulu",
         | 
| 12 | 
            +
                  "Alaska"                       => "America/Juneau",
         | 
| 13 | 
            +
                  "Pacific Time (US & Canada)"   => "America/Los_Angeles",
         | 
| 14 | 
            +
                  "Tijuana"                      => "America/Tijuana",
         | 
| 15 | 
            +
                  "Mountain Time (US & Canada)"  => "America/Denver",
         | 
| 16 | 
            +
                  "Arizona"                      => "America/Phoenix",
         | 
| 17 | 
            +
                  "Chihuahua"                    => "America/Chihuahua",
         | 
| 18 | 
            +
                  "Mazatlan"                     => "America/Mazatlan",
         | 
| 19 | 
            +
                  "Central Time (US & Canada)"   => "America/Chicago",
         | 
| 20 | 
            +
                  "Saskatchewan"                 => "America/Regina",
         | 
| 21 | 
            +
                  "Guadalajara"                  => "America/Mexico_City",
         | 
| 22 | 
            +
                  "Mexico City"                  => "America/Mexico_City",
         | 
| 23 | 
            +
                  "Monterrey"                    => "America/Monterrey",
         | 
| 24 | 
            +
                  "Central America"              => "America/Guatemala",
         | 
| 25 | 
            +
                  "Eastern Time (US & Canada)"   => "America/New_York",
         | 
| 26 | 
            +
                  "Indiana (East)"               => "America/Indiana/Indianapolis",
         | 
| 27 | 
            +
                  "Bogota"                       => "America/Bogota",
         | 
| 28 | 
            +
                  "Lima"                         => "America/Lima",
         | 
| 29 | 
            +
                  "Quito"                        => "America/Lima",
         | 
| 30 | 
            +
                  "Atlantic Time (Canada)"       => "America/Halifax",
         | 
| 31 | 
            +
                  "Caracas"                      => "America/Caracas",
         | 
| 32 | 
            +
                  "La Paz"                       => "America/La_Paz",
         | 
| 33 | 
            +
                  "Santiago"                     => "America/Santiago",
         | 
| 34 | 
            +
                  "Newfoundland"                 => "America/St_Johns",
         | 
| 35 | 
            +
                  "Brasilia"                     => "America/Sao_Paulo",
         | 
| 36 | 
            +
                  "Buenos Aires"                 => "America/Argentina/Buenos_Aires",
         | 
| 37 | 
            +
                  "Montevideo"                   => "America/Montevideo",
         | 
| 38 | 
            +
                  "Georgetown"                   => "America/Guyana",
         | 
| 39 | 
            +
                  "Greenland"                    => "America/Godthab",
         | 
| 40 | 
            +
                  "Mid-Atlantic"                 => "Atlantic/South_Georgia",
         | 
| 41 | 
            +
                  "Azores"                       => "Atlantic/Azores",
         | 
| 42 | 
            +
                  "Cape Verde Is."               => "Atlantic/Cape_Verde",
         | 
| 43 | 
            +
                  "Dublin"                       => "Europe/Dublin",
         | 
| 44 | 
            +
                  "Edinburgh"                    => "Europe/London",
         | 
| 45 | 
            +
                  "Lisbon"                       => "Europe/Lisbon",
         | 
| 46 | 
            +
                  "London"                       => "Europe/London",
         | 
| 47 | 
            +
                  "Casablanca"                   => "Africa/Casablanca",
         | 
| 48 | 
            +
                  "Monrovia"                     => "Africa/Monrovia",
         | 
| 49 | 
            +
                  "UTC"                          => "Etc/UTC",
         | 
| 50 | 
            +
                  "Belgrade"                     => "Europe/Belgrade",
         | 
| 51 | 
            +
                  "Bratislava"                   => "Europe/Bratislava",
         | 
| 52 | 
            +
                  "Budapest"                     => "Europe/Budapest",
         | 
| 53 | 
            +
                  "Ljubljana"                    => "Europe/Ljubljana",
         | 
| 54 | 
            +
                  "Prague"                       => "Europe/Prague",
         | 
| 55 | 
            +
                  "Sarajevo"                     => "Europe/Sarajevo",
         | 
| 56 | 
            +
                  "Skopje"                       => "Europe/Skopje",
         | 
| 57 | 
            +
                  "Warsaw"                       => "Europe/Warsaw",
         | 
| 58 | 
            +
                  "Zagreb"                       => "Europe/Zagreb",
         | 
| 59 | 
            +
                  "Brussels"                     => "Europe/Brussels",
         | 
| 60 | 
            +
                  "Copenhagen"                   => "Europe/Copenhagen",
         | 
| 61 | 
            +
                  "Madrid"                       => "Europe/Madrid",
         | 
| 62 | 
            +
                  "Paris"                        => "Europe/Paris",
         | 
| 63 | 
            +
                  "Amsterdam"                    => "Europe/Amsterdam",
         | 
| 64 | 
            +
                  "Berlin"                       => "Europe/Berlin",
         | 
| 65 | 
            +
                  "Bern"                         => "Europe/Berlin",
         | 
| 66 | 
            +
                  "Rome"                         => "Europe/Rome",
         | 
| 67 | 
            +
                  "Stockholm"                    => "Europe/Stockholm",
         | 
| 68 | 
            +
                  "Vienna"                       => "Europe/Vienna",
         | 
| 69 | 
            +
                  "West Central Africa"          => "Africa/Algiers",
         | 
| 70 | 
            +
                  "Bucharest"                    => "Europe/Bucharest",
         | 
| 71 | 
            +
                  "Cairo"                        => "Africa/Cairo",
         | 
| 72 | 
            +
                  "Helsinki"                     => "Europe/Helsinki",
         | 
| 73 | 
            +
                  "Kyiv"                         => "Europe/Kiev",
         | 
| 74 | 
            +
                  "Riga"                         => "Europe/Riga",
         | 
| 75 | 
            +
                  "Sofia"                        => "Europe/Sofia",
         | 
| 76 | 
            +
                  "Tallinn"                      => "Europe/Tallinn",
         | 
| 77 | 
            +
                  "Vilnius"                      => "Europe/Vilnius",
         | 
| 78 | 
            +
                  "Athens"                       => "Europe/Athens",
         | 
| 79 | 
            +
                  "Istanbul"                     => "Europe/Istanbul",
         | 
| 80 | 
            +
                  "Minsk"                        => "Europe/Minsk",
         | 
| 81 | 
            +
                  "Jerusalem"                    => "Asia/Jerusalem",
         | 
| 82 | 
            +
                  "Harare"                       => "Africa/Harare",
         | 
| 83 | 
            +
                  "Pretoria"                     => "Africa/Johannesburg",
         | 
| 84 | 
            +
                  "Moscow"                       => "Europe/Moscow",
         | 
| 85 | 
            +
                  "St. Petersburg"               => "Europe/Moscow",
         | 
| 86 | 
            +
                  "Volgograd"                    => "Europe/Moscow",
         | 
| 87 | 
            +
                  "Kuwait"                       => "Asia/Kuwait",
         | 
| 88 | 
            +
                  "Riyadh"                       => "Asia/Riyadh",
         | 
| 89 | 
            +
                  "Nairobi"                      => "Africa/Nairobi",
         | 
| 90 | 
            +
                  "Baghdad"                      => "Asia/Baghdad",
         | 
| 91 | 
            +
                  "Tehran"                       => "Asia/Tehran",
         | 
| 92 | 
            +
                  "Abu Dhabi"                    => "Asia/Muscat",
         | 
| 93 | 
            +
                  "Muscat"                       => "Asia/Muscat",
         | 
| 94 | 
            +
                  "Baku"                         => "Asia/Baku",
         | 
| 95 | 
            +
                  "Tbilisi"                      => "Asia/Tbilisi",
         | 
| 96 | 
            +
                  "Yerevan"                      => "Asia/Yerevan",
         | 
| 97 | 
            +
                  "Kabul"                        => "Asia/Kabul",
         | 
| 98 | 
            +
                  "Ekaterinburg"                 => "Asia/Yekaterinburg",
         | 
| 99 | 
            +
                  "Islamabad"                    => "Asia/Karachi",
         | 
| 100 | 
            +
                  "Karachi"                      => "Asia/Karachi",
         | 
| 101 | 
            +
                  "Tashkent"                     => "Asia/Tashkent",
         | 
| 102 | 
            +
                  "Chennai"                      => "Asia/Kolkata",
         | 
| 103 | 
            +
                  "Kolkata"                      => "Asia/Kolkata",
         | 
| 104 | 
            +
                  "Mumbai"                       => "Asia/Kolkata",
         | 
| 105 | 
            +
                  "New Delhi"                    => "Asia/Kolkata",
         | 
| 106 | 
            +
                  "Kathmandu"                    => "Asia/Kathmandu",
         | 
| 107 | 
            +
                  "Astana"                       => "Asia/Dhaka",
         | 
| 108 | 
            +
                  "Dhaka"                        => "Asia/Dhaka",
         | 
| 109 | 
            +
                  "Sri Jayawardenepura"          => "Asia/Colombo",
         | 
| 110 | 
            +
                  "Almaty"                       => "Asia/Almaty",
         | 
| 111 | 
            +
                  "Novosibirsk"                  => "Asia/Novosibirsk",
         | 
| 112 | 
            +
                  "Rangoon"                      => "Asia/Rangoon",
         | 
| 113 | 
            +
                  "Bangkok"                      => "Asia/Bangkok",
         | 
| 114 | 
            +
                  "Hanoi"                        => "Asia/Bangkok",
         | 
| 115 | 
            +
                  "Jakarta"                      => "Asia/Jakarta",
         | 
| 116 | 
            +
                  "Krasnoyarsk"                  => "Asia/Krasnoyarsk",
         | 
| 117 | 
            +
                  "Beijing"                      => "Asia/Shanghai",
         | 
| 118 | 
            +
                  "Chongqing"                    => "Asia/Chongqing",
         | 
| 119 | 
            +
                  "Hong Kong"                    => "Asia/Hong_Kong",
         | 
| 120 | 
            +
                  "Urumqi"                       => "Asia/Urumqi",
         | 
| 121 | 
            +
                  "Kuala Lumpur"                 => "Asia/Kuala_Lumpur",
         | 
| 122 | 
            +
                  "Singapore"                    => "Asia/Singapore",
         | 
| 123 | 
            +
                  "Taipei"                       => "Asia/Taipei",
         | 
| 124 | 
            +
                  "Perth"                        => "Australia/Perth",
         | 
| 125 | 
            +
                  "Irkutsk"                      => "Asia/Irkutsk",
         | 
| 126 | 
            +
                  "Ulaanbaatar"                  => "Asia/Ulaanbaatar",
         | 
| 127 | 
            +
                  "Seoul"                        => "Asia/Seoul",
         | 
| 128 | 
            +
                  "Osaka"                        => "Asia/Tokyo",
         | 
| 129 | 
            +
                  "Sapporo"                      => "Asia/Tokyo",
         | 
| 130 | 
            +
                  "Tokyo"                        => "Asia/Tokyo",
         | 
| 131 | 
            +
                  "Yakutsk"                      => "Asia/Yakutsk",
         | 
| 132 | 
            +
                  "Darwin"                       => "Australia/Darwin",
         | 
| 133 | 
            +
                  "Adelaide"                     => "Australia/Adelaide",
         | 
| 134 | 
            +
                  "Canberra"                     => "Australia/Melbourne",
         | 
| 135 | 
            +
                  "Melbourne"                    => "Australia/Melbourne",
         | 
| 136 | 
            +
                  "Sydney"                       => "Australia/Sydney",
         | 
| 137 | 
            +
                  "Brisbane"                     => "Australia/Brisbane",
         | 
| 138 | 
            +
                  "Hobart"                       => "Australia/Hobart",
         | 
| 139 | 
            +
                  "Vladivostok"                  => "Asia/Vladivostok",
         | 
| 140 | 
            +
                  "Guam"                         => "Pacific/Guam",
         | 
| 141 | 
            +
                  "Port Moresby"                 => "Pacific/Port_Moresby",
         | 
| 142 | 
            +
                  "Magadan"                      => "Asia/Magadan",
         | 
| 143 | 
            +
                  "Solomon Is."                  => "Pacific/Guadalcanal",
         | 
| 144 | 
            +
                  "New Caledonia"                => "Pacific/Noumea",
         | 
| 145 | 
            +
                  "Fiji"                         => "Pacific/Fiji",
         | 
| 146 | 
            +
                  "Kamchatka"                    => "Asia/Kamchatka",
         | 
| 147 | 
            +
                  "Marshall Is."                 => "Pacific/Majuro",
         | 
| 148 | 
            +
                  "Auckland"                     => "Pacific/Auckland",
         | 
| 149 | 
            +
                  "Wellington"                   => "Pacific/Auckland",
         | 
| 150 | 
            +
                  "Nuku'alofa"                   => "Pacific/Tongatapu",
         | 
| 151 | 
            +
                  "Tokelau Is."                  => "Pacific/Fakaofo",
         | 
| 152 | 
            +
                  "Chatham Is."                  => "Pacific/Chatham",
         | 
| 153 | 
            +
                  "Samoa"                        => "Pacific/Apia"
         | 
| 154 | 
            +
                }.freeze
         | 
| 155 | 
            +
                
         | 
| 156 | 
            +
                ONE_HOUR_IN_SECS = 3600
         | 
| 157 | 
            +
                ONE_HOUR_IN_MINS = 60
         | 
| 158 | 
            +
                TIME_FORMAT = "%02d".freeze
         | 
| 159 | 
            +
                
         | 
| 160 | 
            +
                attr_reader :time_zone
         | 
| 161 | 
            +
                
         | 
| 162 | 
            +
                # Public: Class constructor.
         | 
| 163 | 
            +
                #
         | 
| 164 | 
            +
                # date_or_time - The Date, Time or DateTime object to be formatted.
         | 
| 165 | 
            +
                # time_zone - The ActiveSupport String specifying the target time zone.
         | 
| 166 | 
            +
                #
         | 
| 167 | 
            +
                # Examples
         | 
| 168 | 
            +
                #
         | 
| 169 | 
            +
                #   TZ::TimeWithZone.new(Time.now.utc, "Eastern Time (US & Canada)")
         | 
| 170 | 
            +
                #   # => an instance of the TZ::TimeWithZone class
         | 
| 171 | 
            +
                #
         | 
| 172 | 
            +
                # Returns a fresh TZ::TimeWithZone object.
         | 
| 173 | 
            +
                def initialize(date_or_time, time_zone)
         | 
| 174 | 
            +
                  @utc_object = to_utc(date_or_time)
         | 
| 175 | 
            +
                  @time_zone = begin
         | 
| 176 | 
            +
                    tz = MAPPING[time_zone]
         | 
| 177 | 
            +
                    TZInfo::Timezone.get(tz)
         | 
| 178 | 
            +
                  end
         | 
| 179 | 
            +
                end
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                # Public: formats the input date/time/datetime object.
         | 
| 182 | 
            +
                #
         | 
| 183 | 
            +
                # Examples
         | 
| 184 | 
            +
                #
         | 
| 185 | 
            +
                #   TZ::TimeWithZone.new(Time.now.utc, "Eastern Time (US & Canada)")
         | 
| 186 | 
            +
                #   # => "Sat, 07 Jun 2014 17:23:53 EDT -04:00"
         | 
| 187 | 
            +
                #
         | 
| 188 | 
            +
                # Returns the formatted String version of the input date/time/datetime object.
         | 
| 189 | 
            +
                def in_time_zone
         | 
| 190 | 
            +
                  "#{formatted_local_time} #{time_zone_code} #{formatted_time}"
         | 
| 191 | 
            +
                end
         | 
| 192 | 
            +
                
         | 
| 193 | 
            +
              private
         | 
| 194 | 
            +
              
         | 
| 195 | 
            +
                def formatted_local_time
         | 
| 196 | 
            +
                  local_time.rfc822.split(" ")[0..-2].join(" ")
         | 
| 197 | 
            +
                end
         | 
| 198 | 
            +
              
         | 
| 199 | 
            +
                def time_zone_code
         | 
| 200 | 
            +
                  period.zone_identifier
         | 
| 201 | 
            +
                end
         | 
| 202 | 
            +
              
         | 
| 203 | 
            +
                def formatted_time
         | 
| 204 | 
            +
                  offset = period.offset.utc_total_offset
         | 
| 205 | 
            +
                  hours, minutes = offset.divmod(ONE_HOUR_IN_SECS)
         | 
| 206 | 
            +
                  minutes /= ONE_HOUR_IN_MINS
         | 
| 207 | 
            +
                  sign = hours < 0 ? "-" : "+"
         | 
| 208 | 
            +
                  padded_hours = TIME_FORMAT % hours.abs
         | 
| 209 | 
            +
                  padded_minutes = TIME_FORMAT % minutes
         | 
| 210 | 
            +
                  "#{sign}#{padded_hours}:#{padded_minutes}"
         | 
| 211 | 
            +
                end
         | 
| 212 | 
            +
              
         | 
| 213 | 
            +
                def period
         | 
| 214 | 
            +
                  @period ||= @time_zone.period_for_utc(@utc_object)
         | 
| 215 | 
            +
                end
         | 
| 216 | 
            +
              
         | 
| 217 | 
            +
                def local_time
         | 
| 218 | 
            +
                  @time_zone.utc_to_local(@utc_object)
         | 
| 219 | 
            +
                end
         | 
| 220 | 
            +
              
         | 
| 221 | 
            +
                def to_utc(date_or_time)
         | 
| 222 | 
            +
                  return date_or_time.to_datetime.to_time.utc if date_or_time.is_a?(Date)
         | 
| 223 | 
            +
                  return date_or_time.utc if date_or_time.respond_to?(:utc?) && !date_or_time.utc? &&
         | 
| 224 | 
            +
                           date_or_time.respond_to?(:utc)
         | 
| 225 | 
            +
                           
         | 
| 226 | 
            +
                  date_or_time
         | 
| 227 | 
            +
                end
         | 
| 228 | 
            +
              end
         | 
| 229 | 
            +
            end
         | 
    
        data/lib/tz/version.rb
    ADDED
    
    
    
        data/spec/spec_helper.rb
    ADDED
    
    
    
        data/spec/tz_spec.rb
    ADDED
    
    | @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            require_relative "spec_helper"
         | 
| 2 | 
            +
            require_relative "../lib/tz"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module TZ
         | 
| 5 | 
            +
              describe TimeWithZone do
         | 
| 6 | 
            +
                let(:time_zone) { "Eastern Time (US & Canada)" }
         | 
| 7 | 
            +
                let(:utc_object) { Time.utc(2014, 6, 13, 12, 0, 0) }
         | 
| 8 | 
            +
                
         | 
| 9 | 
            +
                subject { TimeWithZone.new(utc_object, time_zone) }
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                describe "when the input object is a UTC time" do
         | 
| 12 | 
            +
                  it "formats the input time object" do
         | 
| 13 | 
            +
                    subject.in_time_zone.must_equal "Fri, 13 Jun 2014 08:00:00 EDT -04:00"
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                describe "when the input object is an instance of the Date class" do
         | 
| 18 | 
            +
                  let(:utc_object) { Date.new(2014, 6, 13) }
         | 
| 19 | 
            +
                  
         | 
| 20 | 
            +
                  it "formats the input date object" do
         | 
| 21 | 
            +
                    subject.in_time_zone.must_equal "Thu, 12 Jun 2014 20:00:00 EDT -04:00"
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                describe "when the input object is a non-UTC time" do
         | 
| 26 | 
            +
                  let(:utc_object) do
         | 
| 27 | 
            +
                    utc_time = Time.utc(2014, 6, 13, 15, 0, 0)
         | 
| 28 | 
            +
                    tz = TZInfo::Timezone.get("America/Argentina/Buenos_Aires")
         | 
| 29 | 
            +
                    tz.local_to_utc(utc_time).tap do |time|
         | 
| 30 | 
            +
                      def time.utc?
         | 
| 31 | 
            +
                        false
         | 
| 32 | 
            +
                      end
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                  
         | 
| 36 | 
            +
                  it "formats the input time object" do
         | 
| 37 | 
            +
                    subject.in_time_zone.must_equal "Fri, 13 Jun 2014 14:00:00 EDT -04:00"
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
                
         | 
| 41 | 
            +
                describe "#time_zone" do
         | 
| 42 | 
            +
                  it "returns the tzinfo time zone object" do
         | 
| 43 | 
            +
                    subject.time_zone.must_be_instance_of TZInfo::DataTimezone
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/tz.gemspec
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'tz/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "tz"
         | 
| 8 | 
            +
              spec.version       = TZ::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Cecilia Rivero", "Cristian Rasch"]
         | 
| 10 | 
            +
              spec.email         = ["contact@ceciliarivero.com", "cristian@box.cristianrasch.com.ar"]
         | 
| 11 | 
            +
              spec.summary       = %q{Displays UTC time/datatime objects in a specified timezone.}
         | 
| 12 | 
            +
              spec.homepage      = "https://github.com/wecodeio/tz"
         | 
| 13 | 
            +
              spec.license       = "MIT"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              spec.files         = `git ls-files -z`.split("\x0")
         | 
| 16 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 17 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 18 | 
            +
              spec.require_paths = ["lib"]
         | 
| 19 | 
            +
              
         | 
| 20 | 
            +
              spec.add_runtime_dependency "tzinfo"
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              spec.add_development_dependency "bundler", "~> 1.6"
         | 
| 23 | 
            +
              spec.add_development_dependency "rake"
         | 
| 24 | 
            +
              spec.add_development_dependency "minitest", "~> 5.3.4"
         | 
| 25 | 
            +
              spec.add_development_dependency "minitest-line"
         | 
| 26 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,129 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: tz
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Cecilia Rivero
         | 
| 8 | 
            +
            - Cristian Rasch
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2014-06-07 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: tzinfo
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                requirements:
         | 
| 18 | 
            +
                - - ">="
         | 
| 19 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 20 | 
            +
                    version: '0'
         | 
| 21 | 
            +
              type: :runtime
         | 
| 22 | 
            +
              prerelease: false
         | 
| 23 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 24 | 
            +
                requirements:
         | 
| 25 | 
            +
                - - ">="
         | 
| 26 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 27 | 
            +
                    version: '0'
         | 
| 28 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 29 | 
            +
              name: bundler
         | 
| 30 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 31 | 
            +
                requirements:
         | 
| 32 | 
            +
                - - "~>"
         | 
| 33 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 34 | 
            +
                    version: '1.6'
         | 
| 35 | 
            +
              type: :development
         | 
| 36 | 
            +
              prerelease: false
         | 
| 37 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 38 | 
            +
                requirements:
         | 
| 39 | 
            +
                - - "~>"
         | 
| 40 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 41 | 
            +
                    version: '1.6'
         | 
| 42 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 43 | 
            +
              name: rake
         | 
| 44 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 45 | 
            +
                requirements:
         | 
| 46 | 
            +
                - - ">="
         | 
| 47 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 48 | 
            +
                    version: '0'
         | 
| 49 | 
            +
              type: :development
         | 
| 50 | 
            +
              prerelease: false
         | 
| 51 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 52 | 
            +
                requirements:
         | 
| 53 | 
            +
                - - ">="
         | 
| 54 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 55 | 
            +
                    version: '0'
         | 
| 56 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 57 | 
            +
              name: minitest
         | 
| 58 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 59 | 
            +
                requirements:
         | 
| 60 | 
            +
                - - "~>"
         | 
| 61 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 62 | 
            +
                    version: 5.3.4
         | 
| 63 | 
            +
              type: :development
         | 
| 64 | 
            +
              prerelease: false
         | 
| 65 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 66 | 
            +
                requirements:
         | 
| 67 | 
            +
                - - "~>"
         | 
| 68 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                    version: 5.3.4
         | 
| 70 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 71 | 
            +
              name: minitest-line
         | 
| 72 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 73 | 
            +
                requirements:
         | 
| 74 | 
            +
                - - ">="
         | 
| 75 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 76 | 
            +
                    version: '0'
         | 
| 77 | 
            +
              type: :development
         | 
| 78 | 
            +
              prerelease: false
         | 
| 79 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 80 | 
            +
                requirements:
         | 
| 81 | 
            +
                - - ">="
         | 
| 82 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 83 | 
            +
                    version: '0'
         | 
| 84 | 
            +
            description: 
         | 
| 85 | 
            +
            email:
         | 
| 86 | 
            +
            - contact@ceciliarivero.com
         | 
| 87 | 
            +
            - cristian@box.cristianrasch.com.ar
         | 
| 88 | 
            +
            executables: []
         | 
| 89 | 
            +
            extensions: []
         | 
| 90 | 
            +
            extra_rdoc_files: []
         | 
| 91 | 
            +
            files:
         | 
| 92 | 
            +
            - ".gitignore"
         | 
| 93 | 
            +
            - ".ruby-version"
         | 
| 94 | 
            +
            - Gemfile
         | 
| 95 | 
            +
            - LICENSE.txt
         | 
| 96 | 
            +
            - README.md
         | 
| 97 | 
            +
            - Rakefile
         | 
| 98 | 
            +
            - lib/tz.rb
         | 
| 99 | 
            +
            - lib/tz/version.rb
         | 
| 100 | 
            +
            - spec/spec_helper.rb
         | 
| 101 | 
            +
            - spec/tz_spec.rb
         | 
| 102 | 
            +
            - tz.gemspec
         | 
| 103 | 
            +
            homepage: https://github.com/wecodeio/tz
         | 
| 104 | 
            +
            licenses:
         | 
| 105 | 
            +
            - MIT
         | 
| 106 | 
            +
            metadata: {}
         | 
| 107 | 
            +
            post_install_message: 
         | 
| 108 | 
            +
            rdoc_options: []
         | 
| 109 | 
            +
            require_paths:
         | 
| 110 | 
            +
            - lib
         | 
| 111 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 112 | 
            +
              requirements:
         | 
| 113 | 
            +
              - - ">="
         | 
| 114 | 
            +
                - !ruby/object:Gem::Version
         | 
| 115 | 
            +
                  version: '0'
         | 
| 116 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 117 | 
            +
              requirements:
         | 
| 118 | 
            +
              - - ">="
         | 
| 119 | 
            +
                - !ruby/object:Gem::Version
         | 
| 120 | 
            +
                  version: '0'
         | 
| 121 | 
            +
            requirements: []
         | 
| 122 | 
            +
            rubyforge_project: 
         | 
| 123 | 
            +
            rubygems_version: 2.2.2
         | 
| 124 | 
            +
            signing_key: 
         | 
| 125 | 
            +
            specification_version: 4
         | 
| 126 | 
            +
            summary: Displays UTC time/datatime objects in a specified timezone.
         | 
| 127 | 
            +
            test_files:
         | 
| 128 | 
            +
            - spec/spec_helper.rb
         | 
| 129 | 
            +
            - spec/tz_spec.rb
         |