Skip to content

Commit

Permalink
Okay, actually getting the local time was ridiculously easy once I fi…
Browse files Browse the repository at this point in the history
…gured it out.
  • Loading branch information
elaewin committed May 16, 2017
1 parent a2711f2 commit 7489efc
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 75 deletions.
18 changes: 10 additions & 8 deletions CFuWx/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="165.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Location" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="e9u-lJ-p74">
<rect key="frame" x="16" y="4" width="69" height="22"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-Bold" family="Apple SD Gothic Neo" pointSize="18"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Location" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="e9u-lJ-p74">
<rect key="frame" x="16" y="4" width="169" height="22"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-SemiBold" family="Apple SD Gothic Neo" pointSize="18"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" restorationIdentifier="WeatherIcon" translatesAutoresizingMaskIntoConstraints="NO" id="vzh-eD-yFD">
<rect key="frame" x="201" y="46" width="150" height="116"/>
<rect key="frame" x="201" y="48" width="150" height="114"/>
<color key="tintColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Summary" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GyG-Cz-Xbp">
Expand All @@ -64,9 +64,9 @@
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Date" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="d5T-hO-XNq">
<rect key="frame" x="315" y="4" width="36" height="20"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-Bold" family="Apple SD Gothic Neo" pointSize="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Date" textAlignment="right" lineBreakMode="wordWrap" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="d5T-hO-XNq">
<rect key="frame" x="201" y="4" width="150" height="22"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-SemiBold" family="Apple SD Gothic Neo" pointSize="18"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
Expand All @@ -79,13 +79,15 @@
<constraint firstItem="GyG-Cz-Xbp" firstAttribute="leading" secondItem="uEV-Dx-GAt" secondAttribute="leading" constant="16" id="MHk-ZL-muq"/>
<constraint firstAttribute="bottom" secondItem="vzh-eD-yFD" secondAttribute="bottom" constant="4" id="PpP-yU-4nN"/>
<constraint firstItem="GyG-Cz-Xbp" firstAttribute="top" secondItem="htT-X5-unD" secondAttribute="bottom" id="QEn-Hg-oTR"/>
<constraint firstItem="d5T-hO-XNq" firstAttribute="width" secondItem="uEV-Dx-GAt" secondAttribute="width" multiplier="0.4" id="YqW-nc-IvR"/>
<constraint firstItem="htT-X5-unD" firstAttribute="width" secondItem="uEV-Dx-GAt" secondAttribute="width" multiplier="0.45" id="ZPd-aC-3KN"/>
<constraint firstItem="e9u-lJ-p74" firstAttribute="top" secondItem="uEV-Dx-GAt" secondAttribute="top" constant="4" id="bEv-fT-w33"/>
<constraint firstItem="d5T-hO-XNq" firstAttribute="trailing" secondItem="vzh-eD-yFD" secondAttribute="trailing" id="beu-1M-BV3"/>
<constraint firstAttribute="bottom" secondItem="GyG-Cz-Xbp" secondAttribute="bottom" constant="20" id="br5-mO-bOc"/>
<constraint firstItem="GyG-Cz-Xbp" firstAttribute="width" secondItem="uEV-Dx-GAt" secondAttribute="width" multiplier="0.45" id="kAf-Iv-QQY"/>
<constraint firstItem="vzh-eD-yFD" firstAttribute="width" secondItem="uEV-Dx-GAt" secondAttribute="width" multiplier="0.4" id="qHK-SH-tOH"/>
<constraint firstItem="d5T-hO-XNq" firstAttribute="top" secondItem="e9u-lJ-p74" secondAttribute="top" id="tNI-kE-cy4"/>
<constraint firstItem="e9u-lJ-p74" firstAttribute="width" secondItem="uEV-Dx-GAt" secondAttribute="width" multiplier="0.45" id="v1G-uJ-yIw"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
Expand Down Expand Up @@ -214,7 +216,7 @@
</connections>
</containerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sensor Pressure" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hjg-gg-Tuw">
<rect key="frame" x="111" y="428" width="153.5" height="24"/>
<rect key="frame" x="111" y="428" width="154" height="24"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="20"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
Expand Down
8 changes: 5 additions & 3 deletions CFuWx/Conversions.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,17 @@ +(NSString *)convertToKnots:(double)miles {
// Convert Dates & Times
+(NSString *)getTimeZoneDataVersion {
NSTimeZone *timezone = [NSTimeZone timeZoneWithName:[[LocationManager sharedManager] timezone]];
NSString *localeTimeZone = [timezone abbreviation];
return localeTimeZone;
NSString *localTimeZone = [timezone abbreviation];
[NSTimeZone localTimeZone];
return localTimeZone;
}

+(NSString *)convertToFormattedDateOrTimeFrom:(NSDate *)date
withCustomFormat:(NSString *)format {
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[formatter setLocale:locale];
formatter.timeZone = [NSTimeZone timeZoneWithName:[[LocationManager sharedManager] timezone]];
[formatter setDateFormat:format];
return [formatter stringFromDate:date];
}
Expand All @@ -150,7 +152,7 @@ +(NSString *)convertToReadableDate:(NSDate *)date {
// Convert Time
+(NSString *)convertToReadableTime:(NSDate *)date {
return [self convertToFormattedDateOrTimeFrom:date
withCustomFormat:@"HH:mm a"];
withCustomFormat:@"HH:mm"];
}

+(NSString *)convertToHourOnly:(NSDate *)date {
Expand Down
2 changes: 2 additions & 0 deletions CFuWx/DarkSkyAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ +(void)fetchCurrentWeatherWithCompletion:(weatherCompletion)completion {
} else {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
Weather *currentWeather = [[Weather alloc]initWithDictionary:[json valueForKey:@"currently"] andLatitude:json[@"latitude"] andLongitude:json[@"longitude"] andTimezone:json[@"timezone"]];
[[LocationManager sharedManager] setTimezone:currentWeather.timezone];
NSLog(@"TIMEZONE FROM DARK SKY API CALL: %@", [[LocationManager sharedManager] timezone]);
completion(currentWeather);
}];
}
Expand Down
16 changes: 8 additions & 8 deletions CFuWx/Forecast.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@
<rect key="frame" x="0.0" y="20" width="375" height="146.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Location" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="364-DQ-n94">
<rect key="frame" x="16" y="0.0" width="169" height="21"/>
<rect key="frame" x="16" y="0.0" width="169" height="22"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-SemiBold" family="Apple SD Gothic Neo" pointSize="17"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-SemiBold" family="Apple SD Gothic Neo" pointSize="18"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Time | Date" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.59999999999999998" translatesAutoresizingMaskIntoConstraints="NO" id="k9N-Ep-b2e">
<rect key="frame" x="190.5" y="0.0" width="168.5" height="21"/>
<rect key="frame" x="190.5" y="0.0" width="168.5" height="22"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-SemiBold" family="Apple SD Gothic Neo" pointSize="18"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="top" showsTouchWhenHighlighted="YES" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="pqf-6v-JqH">
<rect key="frame" x="71.5" y="29" width="59" height="58.5"/>
<rect key="frame" x="71.5" y="30" width="59" height="58.5"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" secondItem="pqf-6v-JqH" secondAttribute="height" multiplier="1:1" id="isV-fy-lQE"/>
Expand All @@ -59,7 +59,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gln-hh-cEB">
<rect key="frame" x="249.5" y="29" width="52" height="51.5"/>
<rect key="frame" x="249.5" y="30" width="52" height="51.5"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" secondItem="Gln-hh-cEB" secondAttribute="height" multiplier="1:1" id="03V-RV-mlB"/>
Expand All @@ -73,13 +73,13 @@
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="HOURLY" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="G74-Od-CJG">
<rect key="frame" x="63" y="93.5" width="74.5" height="24"/>
<rect key="frame" x="63" y="94.5" width="74.5" height="24"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-SemiBold" family="Apple SD Gothic Neo" pointSize="20"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DAILY" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oc9-6l-vIA">
<rect key="frame" x="249" y="93.5" width="53" height="24"/>
<rect key="frame" x="249" y="94.5" width="53" height="24"/>
<fontDescription key="fontDescription" name="AppleSDGothicNeo-SemiBold" family="Apple SD Gothic Neo" pointSize="20"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
Expand Down
4 changes: 3 additions & 1 deletion CFuWx/ForecastViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,14 @@ -(UIImage *)getBackgroundImage {
imageURL = nightURL;
}

__weak typeof(self) bruce = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];

__strong typeof(bruce) hulk = bruce;
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI
self.backgroundImageView.image = [UIImage imageWithData:imageData];
hulk.backgroundImageView.image = [UIImage imageWithData:imageData];
});
});
return self.backgroundImageView.image;
Expand Down
4 changes: 2 additions & 2 deletions CFuWx/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
TopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TopTableViewCell"];
NSDate *date = [NSDate date];

cell.time.text = [NSString stringWithFormat:@"Forecast at %@", [Conversions convertToReadableTime:date]];
cell.date.text = [Conversions convertToReadableDate:date];
NSString *time = [Conversions convertToReadableTime:date];
cell.date.text = [NSString stringWithFormat:@"%@ at %@", [Conversions convertToReadableDate:date], time];
cell.temperature.text = [NSString stringWithFormat:@"%@°F", [Conversions formatToOneDecimal:self.currentWeather.temperature.floatValue]];
cell.location.text = [self getLocationText];
[cell.weatherIconImage.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
Expand Down
Loading

0 comments on commit 7489efc

Please sign in to comment.