Example #1
0
def time_json():
    lat = request.args.get('lat')
    lng = request.args.get('lng')
    location = Location(lat,lng)
    
    local_time = external._lookup_time(location)

    if local_time is None:
        return jsonify(None)

    return jsonify({
        'time':      local_time.as_string(),
        'zone_abbr': local_time.zone_abbr,
        'zone_name': local_time.zone_name,
    })
Example #2
0
def test_time():
    class loc(object):
        pass
    loc.lat = '37.7833'
    loc.lng = '-122.4167'
    response = external._lookup_time(loc)
    local = datetime.datetime.now() - datetime.timedelta(hours=8)
    hour = local.hour if local.hour < 12 else local.hour - 12
    hour = str(hour) if hour > 9 else '0' + str(hour)
    min = str(local.minute) if local.minute > 9 else '0' + str(local.minute)
    flag = "AM" if local.hour < 12 else "PM"
    expected_time = hour + ':' + min + ' ' + flag
    assert(expected_time == response.as_string()) # test_time 1
    
    loc.lat = '40.7127'
    loc.lng = '-74.0059'
    response = external._lookup_time(loc)
    local = datetime.datetime.now() - datetime.timedelta(hours=5)
    hour = local.hour if local.hour < 12 else local.hour - 12
    hour = str(hour) if hour > 9 else '0' + str(hour)
    min = str(local.minute) if local.minute > 9 else '0' + str(local.minute)
    flag = "AM" if local.hour < 12 else "PM"
    expected_time = hour + ':' + min + ' ' + flag
    assert(expected_time == response.as_string()) # test_time 2
Example #3
0
    def get_time(self):
        # Note: The time info is not cached because the local time may have
        #       changed since the previous call

        return external._lookup_time(self.location)