Skip to content

Commit

Permalink
trying to get local time for searched cities to display.
Browse files Browse the repository at this point in the history
  • Loading branch information
elaewin committed May 2, 2017
1 parent c3f7af3 commit 9392a9b
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CFuWx/Assets.xcassets/cfuwx-icon.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
"images" : [
{
"idiom" : "universal",
"filename" : "cfuwx-icon.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "cfuwx-icon.jpg",
"filename" : "cfuwx-icon@3x.jpg",
"scale" : "3x"
}
],
Expand Down
Binary file modified CFuWx/Assets.xcassets/cfuwx-icon.imageset/cfuwx-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions CFuWx/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<view key="view" contentMode="scaleAspectFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="barometer" translatesAutoresizingMaskIntoConstraints="NO" id="6J5-X7-gl0">
<rect key="frame" x="37" y="20" width="300" height="467"/>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="cfuwx-icon" translatesAutoresizingMaskIntoConstraints="NO" id="6J5-X7-gl0">
<rect key="frame" x="18.5" y="20" width="337.5" height="467"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</imageView>
Expand All @@ -34,12 +34,12 @@
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.0072500552050769329" green="0.49597853422164917" blue="0.99889200925827026" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="6J5-X7-gl0" firstAttribute="height" secondItem="Ze5-6b-2t3" secondAttribute="height" multiplier="0.7" id="0GI-kk-OfN"/>
<constraint firstAttribute="trailing" secondItem="swC-bn-djX" secondAttribute="trailing" constant="16" id="2pv-pc-9IL"/>
<constraint firstItem="6J5-X7-gl0" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="67H-iL-7I7"/>
<constraint firstItem="6J5-X7-gl0" firstAttribute="width" secondItem="Ze5-6b-2t3" secondAttribute="width" multiplier="0.8" id="7Py-Mw-wj1"/>
<constraint firstItem="6J5-X7-gl0" firstAttribute="width" secondItem="Ze5-6b-2t3" secondAttribute="width" multiplier="0.9" id="7Py-Mw-wj1"/>
<constraint firstItem="swC-bn-djX" firstAttribute="bottom" secondItem="6J5-X7-gl0" secondAttribute="bottom" id="GZp-6W-axH"/>
<constraint firstItem="swC-bn-djX" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="16" id="d6p-5r-7lk"/>
<constraint firstItem="6J5-X7-gl0" firstAttribute="top" secondItem="Llm-lL-Icb" secondAttribute="bottom" id="jvl-Bm-mMX"/>
Expand All @@ -52,6 +52,6 @@
</scene>
</scenes>
<resources>
<image name="barometer" width="1200" height="1200"/>
<image name="cfuwx-icon" width="433" height="433"/>
</resources>
</document>
3 changes: 2 additions & 1 deletion CFuWx/Conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
+(NSString *)convertToReadableDate:(NSDate *)date;

// Convert Time
+(NSString *)convertToHourOnly:(NSDate *)date;
+(NSString *)convertToReadableTime:(NSDate *)date;
+(NSString *)convertToHourAndMinutes:(NSDate *)date;
+(NSString *)convertToHourOnly:(NSDate *)date;

// Convert degrees to bearing
+(NSString *)windDirectionFromDegrees:(double)degrees;
Expand Down
7 changes: 6 additions & 1 deletion CFuWx/Conversions.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ +(NSString *)convertToReadableTime:(NSDate *)date {
withCustomFormat:@"HH:mm a"];
}

+(NSString *)convertToHourOnly:(NSDate *)date {
+(NSString *)convertToHourAndMinutes:(NSDate *)date {
return [self convertToFormattedDateOrTimeFrom:date
withCustomFormat:@"HH:00"];
}

+(NSString *)convertToHourOnly:(NSDate *)date {
return [self convertToFormattedDateOrTimeFrom:date
withCustomFormat:@"HH"];
}

// Convert degrees to bearing
+(NSString *)windDirectionFromDegrees:(double)degrees {
NSArray *directions = @[@"N", @"NNE", @"NE", @"ENE", @"E", @"ESE", @"SE", @"SSE", @"S", @"SSW", @"SW", @"WSW", @"W", @"WNW", @"NW", @"NNW"];
Expand Down
3 changes: 1 addition & 2 deletions CFuWx/DarkSkyAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ +(NSURL *)createDarkSkyAuthURL:(NSURLQueryItem *)queryItem {
NSURLComponents *components = [[NSURLComponents alloc]init];
components.scheme = @"https";
components.host = @"api.darksky.net";
// components.path = [NSString stringWithFormat:@"/forecast/%@/%f,%f", @"key", coordinate.latitude, coordinate.longitude];
components.path = [NSString stringWithFormat:@"/forecast/%@/%f,%f", kDarkSkyAPIKey, coordinate.latitude, coordinate.longitude];
components.queryItems = @[queryItem];
NSURL *url = components.URL;
Expand Down Expand Up @@ -148,7 +147,7 @@ +(void)fetchDailyWeatherWithCompletion:(weatherCompletionWithArray)completion {
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];

[[session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
// NSLog(@"Response: %@", response);
NSLog(@"Response: %@", response);

if(error) {
NSLog(@"There was a problem getting current weather data from API - Error: %@", error.localizedDescription);
Expand Down
23 changes: 20 additions & 3 deletions CFuWx/ForecastViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
Weather *forecast = [self.hourlyWeatherArray objectAtIndex:indexPath.row];

NSDate *date = [NSDate dateWithTimeIntervalSince1970:[forecast.time doubleValue]];
hourlyCell.hourlyTimeLabel.text = [Conversions convertToHourOnly:date];
hourlyCell.hourlyTimeLabel.text = [Conversions convertToHourAndMinutes:date];
hourlyCell.hourlyTempLabel.text = [NSString stringWithFormat:@"%@°F", [Conversions formatToOneDecimal:forecast.temperature.floatValue]];
hourlyCell.hourlyWindLabel.text = [NSString stringWithFormat:@"%@ mph", [Conversions formatToOneDecimal:forecast.windSpeed.floatValue]];
hourlyCell.hourlyPrecipLabel.text = [NSString stringWithFormat:@"%@%%", [Conversions convertToPercentage:forecast.precipProbability.floatValue]];
Expand Down Expand Up @@ -191,11 +191,28 @@ -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPat
// return 45;
//}

// code for background images from collection via unsplash
// code for background images from collections via unsplash
//-(NSURL *)getURLForLocalTimeOfForecast {
// return [NSURL URLWithString:@"https://source.unsplash.com/collection/566474"];
//}


-(UIImage *)getBackgroundImage {
// setting background to image grabbed from "Forecast Backgrounds" collection in unsplash.com
NSURL *imageURL = [NSURL URLWithString:@"https://source.unsplash.com/collection/566474"];

NSURL *imageURL = [[NSURL alloc] init];
NSDate *date = [NSDate date];
NSString *time = [Conversions convertToHourOnly:date];

if (time.integerValue > 6 && time.integerValue < 18) {
NSURL *dayURL = [NSURL URLWithString:@"https://source.unsplash.com/collection/566474"];
imageURL = dayURL;
} else {
NSURL *nightURL = [NSURL URLWithString:@"https://source.unsplash.com/collection/791499"];
imageURL = nightURL;
}

// NSURL *imageURL = [NSURL URLWithString:@"https://source.unsplash.com/collection/566474"];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
Expand Down
3 changes: 3 additions & 0 deletions CFuWx/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ - (void)viewDidLoad {
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView reloadData];
NSTimeInterval interval = self.currentWeather.time.floatValue;
NSDate *time = [NSDate dateWithTimeIntervalSince1970:interval];
NSLog(@"LOCAL TIME: %@", [Conversions convertToHourAndMinutes:time]);
}

-(void)setCurrentWeather:(Weather *)currentWeather {
Expand Down
2 changes: 1 addition & 1 deletion CFuWx/LocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ -(CLLocation *)getLocationForLatitude:(double)latitude andLongitude:(double)long
}


//MARK: CLLocationManager Delegate Methods Go Here:
//MARK: CLLocationManager Delegate Methods:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
[self setCurrentLocation:locations.lastObject];
Expand Down

0 comments on commit 9392a9b

Please sign in to comment.