How to get the sunrise/ sunset time for remote location in their timezone, not device timezone when using open weather api, in Objective C? - objective-c

I am getting the sunrise/sunset time but it is in the timezone that my device is using. For example, I am in New York, when I look up cities that are in EST, it returns the sunrise/sunset time in the right timezone. But if I look up Dubai, the hours are off. The sunset time returned for Dubai is 10:57PM. Which is the time in New York(EST) when the sun sets in Dubai.
Here is my OpenWeatherAPI response-
base = stations;
clouds = {
all = 20;
};
cod = 200;
coord = {
lat = "25.27";
lon = "55.3";
};
dt = 1565620936;
id = 292223;
main = {
humidity = 71;
pressure = 995;
temp = 36;
"temp_max" = 36;
"temp_min" = 36;
};
name = Dubai;
sys = {
country = AE;
id = 7537;
message = "0.0067";
sunrise = 1565574654;
sunset = 1565621827;
type = 1;
};
timezone = 14400;
visibility = 7000;
weather = (
{
description = "few clouds";
icon = 02d;
id = 801;
main = Clouds;
}
);
wind = {
deg = 340;
speed = "4.6";
};
How do I get the sunrise/sunset time in the remote time zone that I am querying in Objective-C?

I figured it out, this is how you do it-
You use the timezone field returned in the API response and set it as the offset.
double offset = [json[#"timezone"]doubleValue]; //getting timezone offset
double sunriseTimestampval = [json[#"sys"][#"sunrise"]doubleValue];
NSTimeInterval sunriseTimestamp = (NSTimeInterval)sunriseTimestampval;
NSDate* sunriseDate = [NSDate dateWithTimeIntervalSince1970:sunriseTimestamp];
NSDateFormatter *sunriseDateFormatter = [[NSDateFormatter alloc] init];
[sunriseDateFormatter setDateFormat:#"hh:mm"];
[sunriseDateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:offset]];//->Converting to remote timezone
NSString *sunriseTime = [sunriseDateFormatter stringFromDate:sunriseDate];

Related

AFNetworking post request fails due to nsdictionary value with double quotes

When I set nsdictionary as request parameters, dictionary values with special character are added with double quotes and that cause the post request to failed but when I use same dictionary values using "Rest client (Chrome Add-ons)" request post successfully. How to fix the issue?
for example lat and long should be float value because of special character double quotes are added automatically. Here is my NSDictionary log->
**
AptSuiteNo = 20;
BuildingName = "the ";
BuiltInYear = 2014;
BuiltUpAreaSize = 200;
CityName = Dhaka;
CountryName = Bangladesh;
CreateDate = "19-04-2016";
CreatedByCompanyID = 7746;
CreatedByUserID = 7915;
CurrencyID = 1;
Description = "The ";
LastUpdateDate = "19-04-2016";
LastUpdatedByUserID = 7915;
Latitude = "23.832637";
LocalityName = Cantonment;
Longitude = "90.416590";
NeighborhoodName = "Nikunja 2";
PlaceID = ChIJieh0al7GVTcRvMjqALwGYVc;
PostedBy = owner;
Price = 200;
PropertyBathroomNumber = 1;
PropertyBedroomNumber = 1;
PropertyBuildUpAreaSizeTypeID = 1;
PropertyID = 0;
PropertyLotSize = 250;
PropertyLotSizeTypeID = 1;
PropertyName = "the ";
PropertyTransactionTypeCategoryID = 1;
PropertyTransactionTypeID = 1;
PropertyTypeID = 10;
StateName = "Dhaka Division";
StateTicker = "Dhaka Division";
ZipCode = 1229;
**
NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:#"POST" URLString:RequestURL parameters:[self requestDataString] error:&error];

Restkit response mapping for get API

I'm new for Restkit response mapping. I'm not able to map it properly. I have Event and Venue model with all necessary attributes. Could any one set request mapping for it.
Thanks in advance.
*Printing description of mappingResult:
<RKMappingResult: 0x7b1e2da0, results={
"" = {
events = (
{
date = "Saturday,17 Jan 2015";
"event_list" = (
{
"already_attending" = 0;
attending = 1;
description = "<null>";
"event_end_date" = "Saturday,17 Jan 2015 07:30pm";
"event_start_date" = "Saturday,17 Jan 2015 07:30pm";
id = 54b3e2fe7265646a782f0000;
"is_limited" = 1;
"is_private_community_event" = 1;
name = Drinks;
picture = "http://veozen.systech-soft.com/pictures/original/missing.png";
"user_picture" = "http://veozen.systech-soft.com/profile_pictures/original/missing.png";
venue = {
latitude = "51.505968";
longitude = "-0.027865";
"venue_address" = "4.3";
"venue_name" = "Cafe Brera";
"venue_picture" = "https://maps.googleapis.com/maps/api/place/photo?photoreference=CnRnAAAAZk6z2twchk-xU6AGo-ZwK6ykDWTsf6LWh6TjX0ho7K5gLqr4-FkAtGpSr9MNK4Ytc7ejQerAvTO7w2_-fFUoTFF_W_vG3isNz3rKzxf-WMep-VC2loBE2Exmt4Lbr8q4kTKdwUNpckm5Lqy1b7UXTBIQeZjov6oDTrT21gjtv0XzYBoUetjjOaRuGeX262g6k4V8U0-o1H8&key=AIzaSyDfB1L32kL2bgdd0Wz5IJTeI0OiHONLmbQ&sensor=false&maxwidth=320";
};
}
);
}
);
};
}>*

Line break in date axis with amcharts

As you can see here http://allopensensors.com/profile/andreas/
the date on x-axis is nonreadable. I'd like to add a line break. How can i solve this?
AmCharts.ready(function () {
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "http://allopensensors.com/amcharts/images/";
chart.dataProvider = chartData;
chart.marginLeft = 10;
chart.categoryField = "year";
chart.dataDateFormat = "YYYY-MM-DD JJ:NN:SS";
// listen for "dataUpdated" event (fired when chart is inited) and call zoomChart method when it happens
chart.addListener("dataUpdated", zoomChart);
// AXES
// category
var categoryAxis = chart.categoryAxis;
// categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
categoryAxis.minPeriod = "200"; // our data is yearly, so we set minPeriod to YYYY
categoryAxis.dashLength = 3;
categoryAxis.minorGridEnabled = true;
categoryAxis.minorGridAlpha = 0.1;
// value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0;
valueAxis.inside = true;
valueAxis.dashLength = 3;
chart.addValueAxis(valueAxis);
// GRAPH
graph = new AmCharts.AmGraph();
graph.type = "smoothedLine"; // this line makes the graph smoothed line.
graph.lineColor = "#d1655d";
graph.negativeLineColor = "#637bb6"; // this line makes the graph to change color when it drops below 0
graph.bullet = "round";
graph.bulletSize = 8;
graph.bulletBorderColor = "#FFFFFF";
graph.bulletBorderAlpha = 1;
graph.bulletBorderThickness = 2;
graph.lineThickness = 2;
graph.valueField = "value";
graph.balloonText = "[[category]]<br><b><span style='font-size:14px;'>[[value]]</span></b>";
chart.addGraph(graph);
// CURSOR
var chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorAlpha = 0;
chartCursor.cursorPosition = "mouse";
chartCursor.categoryBalloonDateFormat = "JJ:NN:SS";
chart.addChartCursor(chartCursor);
// SCROLLBAR
var chartScrollbar = new AmCharts.ChartScrollbar();
chart.addChartScrollbar(chartScrollbar);
chart.creditsPosition = "bottom-right";
// WRITE
chart.write("chartdiv");
});
// this method is called when chart is first inited as we listen for "dataUpdated" event
function zoomChart() {
// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
// chart.zoomToDates(new Date(1972, 0), new Date(2200, 0));
chart.zoomToIndexes(chartData.length - 40, chartData.length - 1);
}
To make it readable, you can rotate the labels with custom angle. Try categoryAxis.labelRotation : 45
For Reference: http://www.amcharts.com/demos/column-with-rotated-series/
Hope it helps!

placing movie clips around a 24hr clock face (as2) - time management

I am currently working on a project to plot the activities of my day out by placing them around a 24 hr clock face. the final out come of this is a time management app that allows you to find spaces in your day that could be used more proficiently; however; I have hit a bit of a snafu and that is assigning each movie clip (each of which represents an activity) to its correct place of on the clock face.
I am using an XML file to pull the times from and the calculation of the angle where the movie clip should be placed on the clock is done in relation to a central movie clip.
for (i = 0; i < TimeSheet.length; i++) {
var counter = i + 1;
sortXML(TimeSheet);
}
}
};
function sortXML(TimeSheet){
var activity = TimeSheet[i].firstChild.nodeValue;
var description = TimeSheet[i].firstChild.nextSibling.childNodes;
var HrStart = TimeSheet[i].firstChild.nextSibling.nextSibling.childNodes;
var MinStart = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.childNodes;
var HrEnd = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var MinEnd = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var place = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var creativity = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var usefulness = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var enjoyment = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var focus = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
category = TimeSheet[i].nodeName;
HourStart = parseInt(HrStart, 10);
MinuteStart = parseInt(MinStart, 10);
HourEnd = parseInt(HrEnd, 10);
MinuteEnd = parseInt(MinEnd, 10);
Creativity = parseInt(creativity, 10);
Focus = parseInt(focus, 10);
Usefulness = parseInt(usefulness, 10)
var TimeSpent = ((HourEnd*60)+MinuteEnd) - ((HourStart*60)+MinuteStart) ;
//var ActivityMinutes = (HourStart*60)+MinuteStart;
var TimeStart = (HourStart*60)+MinuteStart;
var BobPlacement = ((TimeStart/1440)*360) // where the bob gets blaced on the circle
//var BobPlacement = (360/1440)*TimeStart;
//var radius = 150 + Usefulness;
var radius = 200 + (Usefulness/2);
var xcenter = _root.bobCentral._x;
var ycenter = _root.bobCentral._y;
var degree = (BobPlacement + 180)*-1;;
var radian;
radian = (degree/180)*Math.PI;
newBob._x = xcenter+Math.cos(radian)*radius;
newBob._y = ycenter-Math.sin(radian)*radius;
/*trace("-----------------------------------");
trace("category = "+category);
trace("activity = " + activity);
trace("Description = " + description);
trace("time start = " + HourStart + ":" + MinuteStart);
trace("time end = " + HourEnd + ":" + MinuteEnd);
trace("Duration of activity = "+TimeSpent);
trace("place = "+ place);
trace("creativity = "+ creativity);
trace("usefulness = "+ usefulness);
trace("enjoyment = "+ enjoyment);
trace("focus = "+ focus);
trace("Time Started = "+ TimeStart);
trace("palce on circle = "+ BobPlacement);
*/
dupeMC(TimeSheet, category, activity, description, HourStart, MinuteStart, TimeSpent, Creativity, Focus, Usefulness);
}
function dupeMC(TimeSheet, category, activity, description, HourStart, MinuteStart, TimeSpent, Creativity, Focus, Usefulness){
bob.duplicateMovieClip("bob"+i, i);
newBob = eval("bob"+i);
Any help would be much appreciated
I apologies in advance if the way I have put this question forward is confusing in any way.

Accessing a Key in JSON Response

How in the following JSON response can I check if uids is nil ?
{
height = 480;
pid = "F#dd705e6b96a6e894556c0db84870501e_d97383cc80238c38b8907d99690fa1c9";
tags = (
{
attributes = {
glasses = {
confidence = 97;
value = false;
};
smiling = {
confidence = 97;
value = false;
};
};
center = {
x = "60.83";
y = "75.21";
};
gid = "<null>";
height = "49.58";
label = "";
manual = 0;
nose = {
x = "76.21";
y = "77.16";
};
pitch = "-5.55";
recognizable = 0;
roll = "-0.45";
uids = ( // <<<<<========== UIDs Key
);
width = "66.11";
yaw = "-19.56";
}
);
url = "http://face.com/images/ph/a6e529853432599dad6da996746cb070.jpg";
width = 360;
}
When I try :
if ([[[[photo objectForKey:#"tags"] objectAtIndex:0] valueForKey:#"uids"] count] == 0)
It keeps returning FALSE all the time.
I'm able to access a lot of these keys successfully. But it's just this one key that's giving me issues.
Like, to access the url key, I am using :
[photo objectForKey:#"url"];
And it's working absolutely fine.
What am I doing wrong with the uids key ?