Esempio n. 1
0
    def __repr__(self):
        """Self-documenting string representation.

        :rtype: ``str``
        :return: String to recreate ``Zone`` object
        """
        location = utils.to_iso6709(self.latitude, self.longitude, format="dms")[:-1]
        return utils.repr_assist(self, {"location": location})
Esempio n. 2
0
def test_to_iso6709_location_page():
    # The following tests are from the Latitude, Longitude and Altitude format
    # for geospatial information page
    # (http://www.w3.org/2005/Incubator/geo/Wiki/LatitudeLongitudeAltitude)

    #  Mount Everest
    expect(to_iso6709(27.5916, 86.563999999999993, 8850.0)) == \
        '+27.5916+086.5640+8850/'
    #  South Pole
    expect(to_iso6709(-90.0, 0.0, 2800.0, 'd')) == '-90+000+2800/'
    #  New York City
    expect(to_iso6709(40.75, -74.0, None, precision=2)) == '+40.75-074.00/'
    #  Mount Fuji
    expect(to_iso6709(35.360833333333332, 138.72749999999999, 3776.0,
                      'dms')) == '+352139+1384339+3776/'
    #  Tokyo Tower
    expect(to_iso6709(35.658631999999997, 139.74541099999999, None,
                      precision=6)) == '+35.658632+139.745411/'
Esempio n. 3
0
    def __repr__(self):
        """Self-documenting string representation

        >>> Zone("+513030-0000731", 'GB', "Europe/London")
        Zone('+513030-0000730', 'GB', 'Europe/London', None)

        :rtype: ``str``
        :return: String to recreate ``Zone`` object

        """
        location = utils.to_iso6709(self.latitude, self.longitude,
                                    format="dms")[:-1]
        return utils.repr_assist(self, {"location": location})
Esempio n. 4
0
def test_to_iso6709_wiki_page():
    # The following tests are from the examples contained in the wikipedia
    # ISO 6709 page(http://en.wikipedia.org/wiki/ISO_6709)

    #  Atlantic Ocean
    expect(to_iso6709(0.0, -25.0, None, 'd')) == '+00-025/'
    #  France
    expect(to_iso6709(46.0, 2.0, None, 'd')) == '+46+002/'
    #  Paris
    expect(to_iso6709(48.866666666666667, 2.3333333333333335, None, 'dm')) == \
        '+4852+00220/'

    #FIXME
    #  The following test is skipped, because the example from wikipedia
    #  uses differing precision widths for latitude and longitude. Also,
    #  that degree of formatting flexibility is not seen anywhere else and
    #  adds very little.
    #  Eiffel Tower
    #expect(to_iso6709(48.857700000000001, 2.2949999999999999, None)) == \
    #    '+48.8577+002.295/'

    #  Mount Everest
    expect(to_iso6709(27.5916, 86.563999999999993, 8850.0)) == \
        '+27.5916+086.5640+8850/'
    #  North Pole
    expect(to_iso6709(90.0, 0.0, None, 'd')) == '+90+000/'
    #  Pacific Ocean
    expect(to_iso6709(0.0, -160.0, None, 'd')) == '+00-160/'
    #  South Pole
    expect(to_iso6709(-90.0, 0.0, 2800.0, 'd')) == '-90+000+2800/'
    #  United States
    expect(to_iso6709(38.0, -97.0, None, 'd')) == '+38-097/'
    #  New York City
    expect(to_iso6709(40.75, -74.0, None, precision=2)) == '+40.75-074.00/'
    #  Statue of Liberty
    expect(to_iso6709(40.689399999999999, -74.044700000000006, None)) == \
        '+40.6894-074.0447/'
Esempio n. 5
0
    def dump_zone_file(self):
        """Generate a zoneinfo compatible zone description table.

        :rtype: ``list``
        :return: zoneinfo descriptions
        """
        data = []
        for zone in sorted(self, key=attrgetter("country")):
            text = [
                "%s	%s	%s"
                % (zone.country, utils.to_iso6709(zone.latitude, zone.longitude, format="dms")[:-1], zone.zone)
            ]
            if zone.comments:
                text.append("	%s" % ", ".join(zone.comments))
            data.append("".join(text))
        return data
Esempio n. 6
0
    def dump_zone_file(self):
        """Generate a zoneinfo compatible zone description table

        >>> zones = Zones(open("timezones"))
        >>> Zones.dump_zone_file(zones)
        ['AN\\t+121100-0690000\\tAmerica/Curacao',
         'AO\\t-084800+0131400\\tAfrica/Luanda',
         'AQ\\t-775000+1663600\\tAntarctica/McMurdo\\tMcMurdo Station, Ross Island']

        :rtype: ``list``
        :return: zoneinfo descriptions

        """
        data = []
        for zone in sorted(self, key=attrgetter("country")):
            text = ["%s	%s	%s"
                    % (zone.country,
                       utils.to_iso6709(zone.latitude, zone.longitude,
                                        format="dms")[:-1],
                       zone.zone), ]
            if zone.comments:
                text.append("	%s" % ", ".join(zone.comments))
            data.append("".join(text))
        return data
Esempio n. 7
0
def test_to_iso6709_location_page(args, kwargs, result):
    # These tests are from the Latitude, Longitude and Altitude format for
    # geospatial information page
    # (http://www.w3.org/2005/Incubator/geo/Wiki/LatitudeLongitudeAltitude)

    assert to_iso6709(*args, **kwargs) == result
Esempio n. 8
0
def test_to_iso6709_wiki_page(data, result):
    # These tests are from the examples contained in the wikipedia ISO 6709
    # page(http://en.wikipedia.org/wiki/ISO_6709)
    assert to_iso6709(*data) == result