Browse Source

Sunrise/Sunset Feature Changes.

v1.2.4
Abhishek Banthia 9 years ago
parent
commit
13ce7729d0
  1. 1
      Clocker/Appearance Tab/CLAppearanceViewController.m
  2. 67
      Clocker/Appearance Tab/en.lproj/CLAppearanceView.xib
  3. 20
      Clocker/ApplicationDelegate.m
  4. 3
      Clocker/Custom Table Cell Views/CLTimezoneCellView.h
  5. 11
      Clocker/Custom Table Cell Views/CLTimezoneCellView.m
  6. 51
      Clocker/EDSunriseSet.h
  7. 447
      Clocker/EDSunriseSet.m
  8. 21
      Clocker/Floating Window/CLFloatingWindowController.m
  9. 31
      Clocker/Floating Window/en.lproj/CLFloatingWindow.xib
  10. 6
      Clocker/Model/CLTimezoneData.h
  11. 157
      Clocker/Model/CLTimezoneData.m
  12. 1
      Clocker/Utilities/CommonStrings.h
  13. 2
      Clocker/Utilities/CommonStrings.m
  14. 39
      Clocker/en.lproj/Panel.xib

1
Clocker/Appearance Tab/CLAppearanceViewController.m

@ -169,5 +169,4 @@
[self refreshMainTableview:NO andUpdateFloatingWindow:YES];
}
@end

67
Clocker/Appearance Tab/en.lproj/CLAppearanceView.xib

@ -15,11 +15,11 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="439" height="524"/>
<rect key="frame" x="0.0" y="0.0" width="439" height="578"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="60" translatesAutoresizingMaskIntoConstraints="NO" id="iVw-cq-zLz">
<rect key="frame" x="188" y="410" width="64" height="18"/>
<rect key="frame" x="188" y="464" width="64" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="2DP-wK-Ga8"/>
<constraint firstAttribute="width" constant="60" id="KEa-ei-G2i"/>
@ -31,7 +31,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="100" translatesAutoresizingMaskIntoConstraints="NO" id="5TC-RQ-gzI">
<rect key="frame" x="168" y="472" width="104" height="18"/>
<rect key="frame" x="168" y="526" width="104" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="gWc-u4-D8E"/>
<constraint firstAttribute="width" constant="100" id="nh0-5K-Aa0"/>
@ -43,7 +43,7 @@
</textFieldCell>
</textField>
<segmentedControl toolTip="Choose a theme for the main panel!" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5tI-fU-0lZ">
<rect key="frame" x="147" y="379" width="147" height="24"/>
<rect key="frame" x="147" y="433" width="147" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="143" id="dW5-vG-EwD"/>
</constraints>
@ -60,7 +60,7 @@
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="150" translatesAutoresizingMaskIntoConstraints="NO" id="YQi-x8-6f8">
<rect key="frame" x="143" y="348" width="154" height="18"/>
<rect key="frame" x="143" y="402" width="154" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="eY8-bV-QLM"/>
<constraint firstAttribute="width" constant="150" id="n8S-fR-UtY"/>
@ -72,7 +72,7 @@
</textFieldCell>
</textField>
<segmentedControl toolTip="Select a time-format!" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="OrL-Ix-fmY">
<rect key="frame" x="102" y="441" width="236" height="24"/>
<rect key="frame" x="102" y="495" width="236" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="232" id="uOJ-Mi-Fin"/>
</constraints>
@ -166,7 +166,7 @@
</connections>
</segmentedControl>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="72r-oi-X0f">
<rect key="frame" x="180" y="262" width="79" height="24"/>
<rect key="frame" x="180" y="316" width="79" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="75" id="H8w-wg-vel"/>
</constraints>
@ -182,8 +182,24 @@
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.displayFutureSlider" id="zRQ-mQ-qBp"/>
</connections>
</segmentedControl>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="14F-6y-MaJ">
<rect key="frame" x="180" y="208" width="79" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="75" id="XbD-oF-Vod"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="d4r-UR-acP">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<segments>
<segment label="Yes" width="36"/>
<segment label="No" width="36" selected="YES" tag="1"/>
</segments>
</segmentedCell>
<connections>
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.showSunriseSetTime" id="ISl-9Q-Snd"/>
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="120" translatesAutoresizingMaskIntoConstraints="NO" id="HTZ-1V-qZb">
<rect key="frame" x="158" y="293" width="124" height="19"/>
<rect key="frame" x="158" y="347" width="124" height="19"/>
<constraints>
<constraint firstAttribute="width" constant="120" id="1Lv-wC-hEM"/>
</constraints>
@ -194,7 +210,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="120" translatesAutoresizingMaskIntoConstraints="NO" id="76h-05-go1">
<rect key="frame" x="158" y="237" width="124" height="19"/>
<rect key="frame" x="158" y="291" width="124" height="19"/>
<constraints>
<constraint firstAttribute="width" constant="120" id="Odw-mb-nT5"/>
</constraints>
@ -204,8 +220,19 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="120" translatesAutoresizingMaskIntoConstraints="NO" id="R46-6I-vYT">
<rect key="frame" x="138" y="235" width="164" height="19"/>
<constraints>
<constraint firstAttribute="width" constant="160" id="3tu-Bf-MZ4"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Show Sunrise/Sunset" id="dPO-nm-S9e">
<font key="font" size="13" name="SFUIDisplay-Light"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<box verticalHuggingPriority="750" title="Box" boxType="separator" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="MHe-dB-GZr">
<rect key="frame" x="0.0" y="195" width="439" height="5"/>
<rect key="frame" x="0.0" y="199" width="439" height="5"/>
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<font key="titleFont" metaFont="system"/>
@ -244,7 +271,7 @@
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" preferredMaxLayoutWidth="175" translatesAutoresizingMaskIntoConstraints="NO" id="X5s-Mc-Yfo">
<rect key="frame" x="130" y="498" width="179" height="18"/>
<rect key="frame" x="130" y="552" width="179" height="18"/>
<constraints>
<constraint firstAttribute="width" constant="175" id="YaE-Og-A4W"/>
<constraint firstAttribute="height" constant="18" id="bTT-ve-oW9"/>
@ -256,7 +283,7 @@
</textFieldCell>
</textField>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="1eh-BT-2fK">
<rect key="frame" x="155" y="317" width="129" height="24"/>
<rect key="frame" x="155" y="371" width="129" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="125" id="u9T-ks-rqA"/>
</constraints>
@ -273,10 +300,10 @@
</connections>
</segmentedControl>
<visualEffectView wantsLayer="YES" appearanceType="vibrantLight" alphaValue="0.90000000000000002" blendingMode="withinWindow" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="kHi-mx-HdE">
<rect key="frame" x="0.0" y="0.0" width="439" height="197"/>
<rect key="frame" x="0.0" y="0.0" width="439" height="201"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="WDP-d4-eNj">
<rect key="frame" x="57" y="85" width="324" height="39"/>
<rect key="frame" x="57" y="87" width="324" height="39"/>
<constraints>
<constraint firstAttribute="width" constant="320" id="3wp-Z6-TrB"/>
<constraint firstAttribute="height" constant="39" id="IyN-y5-6JP"/>
@ -303,7 +330,7 @@
</connections>
</visualEffectView>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SbG-Qh-ziy">
<rect key="frame" x="53" y="206" width="334" height="24"/>
<rect key="frame" x="53" y="260" width="334" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="330" id="T2D-fB-93g"/>
</constraints>
@ -326,9 +353,10 @@
<constraint firstItem="LC1-Sx-uav" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="2M5-Z9-HrL"/>
<constraint firstItem="SbG-Qh-ziy" firstAttribute="top" secondItem="76h-05-go1" secondAttribute="bottom" constant="8" id="4dL-4I-aA9"/>
<constraint firstItem="YQi-x8-6f8" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="6LU-d8-lKX"/>
<constraint firstItem="3d9-qg-dNb" firstAttribute="top" secondItem="MHe-dB-GZr" secondAttribute="bottom" constant="4" id="BZ1-zf-1At"/>
<constraint firstItem="3d9-qg-dNb" firstAttribute="top" secondItem="MHe-dB-GZr" secondAttribute="bottom" constant="8" id="BZ1-zf-1At"/>
<constraint firstItem="3d9-qg-dNb" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="FBj-0N-ltc"/>
<constraint firstAttribute="bottom" secondItem="kHi-mx-HdE" secondAttribute="bottom" id="GqC-hp-yU9"/>
<constraint firstItem="R46-6I-vYT" firstAttribute="top" secondItem="SbG-Qh-ziy" secondAttribute="bottom" constant="8" id="Hiy-x3-7hE"/>
<constraint firstItem="OrL-Ix-fmY" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="JtZ-ra-RaC"/>
<constraint firstItem="SbG-Qh-ziy" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="MAr-WP-e6V"/>
<constraint firstItem="kEn-QZ-niZ" firstAttribute="top" secondItem="atA-2r-FXV" secondAttribute="bottom" constant="5" id="O8m-uk-Ppx"/>
@ -350,13 +378,16 @@
<constraint firstItem="JR8-v7-K0w" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="Wye-84-JgC"/>
<constraint firstItem="76h-05-go1" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="XcN-rp-Cxq"/>
<constraint firstItem="iVw-cq-zLz" firstAttribute="top" secondItem="OrL-Ix-fmY" secondAttribute="bottom" constant="15" id="XgM-Wl-Xap"/>
<constraint firstItem="MHe-dB-GZr" firstAttribute="top" secondItem="SbG-Qh-ziy" secondAttribute="bottom" constant="10" id="Xmd-cX-Eic"/>
<constraint firstItem="iVw-cq-zLz" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="Zh8-Vn-VxM"/>
<constraint firstItem="5tI-fU-0lZ" firstAttribute="top" secondItem="iVw-cq-zLz" secondAttribute="bottom" constant="8" id="bo6-s2-Vfj"/>
<constraint firstItem="R46-6I-vYT" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="c3p-ZZ-E8L"/>
<constraint firstItem="76h-05-go1" firstAttribute="top" secondItem="72r-oi-X0f" secondAttribute="bottom" constant="8" id="cgM-DZ-Mzt"/>
<constraint firstItem="14F-6y-MaJ" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="e4M-c0-gIC"/>
<constraint firstItem="kEn-QZ-niZ" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="eU3-c4-cnM"/>
<constraint firstItem="1eh-BT-2fK" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="fvI-By-5Ef"/>
<constraint firstItem="MHe-dB-GZr" firstAttribute="top" secondItem="14F-6y-MaJ" secondAttribute="bottom" constant="8" id="gpo-Qh-mTk"/>
<constraint firstAttribute="trailing" secondItem="MHe-dB-GZr" secondAttribute="trailing" id="jL7-Cv-YuY"/>
<constraint firstItem="14F-6y-MaJ" firstAttribute="top" secondItem="R46-6I-vYT" secondAttribute="bottom" constant="4" id="k6X-sH-Ybz"/>
<constraint firstItem="5TC-RQ-gzI" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="lc0-ud-Mnw"/>
<constraint firstItem="JR8-v7-K0w" firstAttribute="top" secondItem="LC1-Sx-uav" secondAttribute="bottom" constant="5" id="pHX-KA-5RI"/>
<constraint firstItem="OrL-Ix-fmY" firstAttribute="top" secondItem="5TC-RQ-gzI" secondAttribute="bottom" constant="8" id="rpk-WN-DT9"/>
@ -365,7 +396,7 @@
<constraint firstItem="XwV-hy-YiP" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="x6a-GW-bOn"/>
<constraint firstItem="LC1-Sx-uav" firstAttribute="top" secondItem="XwV-hy-YiP" secondAttribute="bottom" constant="8" id="xFV-GA-ozB"/>
</constraints>
<point key="canvasLocation" x="186.5" y="269"/>
<point key="canvasLocation" x="186.5" y="296"/>
</customView>
<userDefaultsController representsSharedInstance="YES" id="WGI-5h-l6M"/>
</objects>

20
Clocker/ApplicationDelegate.m

@ -54,10 +54,12 @@ void *kContextActivePanel = &kContextActivePanel;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == kContextActivePanel) {
if (context == kContextActivePanel)
{
self.menubarController.hasActiveIcon = self.panelController.hasActivePanel;
}
else {
else
{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
@ -67,7 +69,7 @@ void *kContextActivePanel = &kContextActivePanel;
//Configure iRate
[iRate sharedInstance].useAllAvailableLanguages = YES;
[iVersion sharedInstance].useAllAvailableLanguages = YES;
[[iRate sharedInstance] setVerboseLogging:YES];
[[iRate sharedInstance] setVerboseLogging:NO];
[[iVersion sharedInstance] setVerboseLogging:NO];
[iRate sharedInstance].promptForNewVersionIfUserRated = YES;
}
@ -100,7 +102,6 @@ void *kContextActivePanel = &kContextActivePanel;
}
}
if (startedAtLogin)
{
[[NSDistributedNotificationCenter defaultCenter]
@ -115,7 +116,7 @@ void *kContextActivePanel = &kContextActivePanel;
NSString *onboarding = [[NSUserDefaults standardUserDefaults] objectForKey:@"initialLaunch"];
if (onboarding == nil)
if (onboarding != nil)
{
CLOnboardingWindowController *windowController = [CLOnboardingWindowController sharedWindow];
[windowController showWindow:nil];
@ -126,8 +127,8 @@ void *kContextActivePanel = &kContextActivePanel;
[[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"NSApplicationCrashOnExceptions": @YES }];
[[Crashlytics sharedInstance] setDebugMode:NO];
[Fabric with:@[[Crashlytics class]]];
// [[Crashlytics sharedInstance] setDebugMode:NO];
// [Fabric with:@[[Crashlytics class]]];
}
@ -189,6 +190,11 @@ void *kContextActivePanel = &kContextActivePanel;
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLShowAppInForeground];
}
NSNumber *showSunriseSunsetTime = [[NSUserDefaults standardUserDefaults] objectForKey:CLSunriseSunsetTime];
if (showSunriseSunsetTime == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@1 forKey:CLSunriseSunsetTime];
}
//If mode selected is 1, then show the window when the app starts
if (displayMode.integerValue == 1)
{

3
Clocker/Custom Table Cell Views/CLTimezoneCellView.h

@ -13,8 +13,11 @@
@property (weak) IBOutlet NSTextField *customName;
@property (weak) IBOutlet NSTextField *relativeDate;
@property (weak) IBOutlet NSTextField *time;
@property (weak) IBOutlet NSTextField *sunriseSetTime;
@property (weak) IBOutlet NSImageView *sunriseSetImage;
@property (nonatomic, assign) NSInteger rowNumber;
- (void)updateTextColorWithColor:(NSColor *)color andCell:(CLTimezoneCellView*)cell;
- (void)setUpAutoLayoutWithCell:(CLTimezoneCellView *)cell;

11
Clocker/Custom Table Cell Views/CLTimezoneCellView.m

@ -14,7 +14,8 @@
@implementation CLTimezoneCellView
- (void)drawRect:(NSRect)dirtyRect {
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
// Drawing code here.
@ -28,7 +29,6 @@
NSNumber *displayMode = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowAppInForeground];
[[[NSApplication sharedApplication] windows] enumerateObjectsUsingBlock:^(NSWindow * _Nonnull window, NSUInteger idx, BOOL * _Nonnull stop)
{
if (displayMode.integerValue == 0)
@ -45,15 +45,12 @@
floatingWindow = window.windowController;
}
}
}];
NSString *originalValue = customLabelCell.stringValue;
NSString *customLabelValue = [originalValue stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
if ([[sender superview] isKindOfClass:[self class]])
{
CLTimezoneCellView *cellView = (CLTimezoneCellView *)[sender superview];
@ -82,7 +79,6 @@
}];
}
timezoneObject.customLabel = (customLabelValue.length > 0) ? customLabelValue : CLEmptyString;
if ([timezoneObject.isFavourite isEqualToNumber:@1])
@ -112,7 +108,6 @@
[[NSNotificationCenter defaultCenter]
postNotificationName:CLCustomLabelChangedNotification
object:nil];
}
}
@ -126,6 +121,7 @@
cell.relativeDate.textColor = color;
cell.customName.textColor = color;
cell.time.textColor = color;
cell.sunriseSetTime.textColor = color;
}
- (void)setUpAutoLayoutWithCell:(CLTimezoneCellView *)cell
@ -146,7 +142,6 @@
- (void)controlTextDidEndEditing:(NSNotification *)obj
{
CLFloatingWindowController *windowController = [CLFloatingWindowController sharedFloatingWindow];
[windowController.floatingWindowTimer start];

51
Clocker/EDSunriseSet.h

@ -0,0 +1,51 @@
//
// EDSunriseSet.h
//
// Created by Ernesto GarcĂ­a on 20/08/11.
// Copyright 2011 Ernesto GarcĂ­a. All rights reserved.
//
// C/C++ sun calculations created by Paul Schlyter
// sunriset.c
// http://stjarnhimlen.se/english.html
// SUNRISET.C - computes Sun rise/set times, start/end of twilight, and
// the length of the day at any date and latitude
// Written as DAYLEN.C, 1989-08-16
// Modified to SUNRISET.C, 1992-12-01
// (c) Paul Schlyter, 1989, 1992
// Released to the public domain by Paul Schlyter, December 1992
//
#import <Foundation/Foundation.h>
#if ! __has_feature(objc_arc)
#error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag in this file.
#endif
@interface EDSunriseSet : NSObject
@property (readonly, strong) NSDate *date;
@property (readonly, strong) NSDate *sunset;
@property (readonly, strong) NSDate *sunrise;
@property (readonly, strong) NSDate *civilTwilightStart;
@property (readonly, strong) NSDate *civilTwilightEnd;
@property (readonly, strong) NSDate *nauticalTwilightStart;
@property (readonly, strong) NSDate *nauticalTwilightEnd;
@property (readonly, strong) NSDate *astronomicalTwilightStart;
@property (readonly, strong) NSDate *astronomicalTwilightEnd;
@property (readonly, strong) NSDateComponents* localSunrise;
@property (readonly, strong) NSDateComponents* localSunset;
@property (readonly, strong) NSDateComponents* localCivilTwilightStart;
@property (readonly, strong) NSDateComponents* localCivilTwilightEnd;
@property (readonly, strong) NSDateComponents* localNauticalTwilightStart;
@property (readonly, strong) NSDateComponents* localNauticalTwilightEnd;
@property (readonly, strong) NSDateComponents* localAstronomicalTwilightStart;
@property (readonly, strong) NSDateComponents* localAstronomicalTwilightEnd;
-(instancetype)initWithDate:(NSDate*)date timezone:(NSTimeZone*)timezone latitude:(double)latitude longitude:(double)longitude NS_DESIGNATED_INITIALIZER;
+(instancetype)sunrisesetWithDate:(NSDate*)date timezone:(NSTimeZone*)timezone latitude:(double)latitude longitude:(double)longitude;
-(instancetype) init __attribute__((unavailable("init not available. Use initWithDate:timeZone:latitude:longitude: instead")));
@end

447
Clocker/EDSunriseSet.m

@ -0,0 +1,447 @@
//
// EDSunriseSet.m
//
// Created by Ernesto GarcĂ­a on 20/08/11.
// Copyright 2011 Ernesto GarcĂ­a. All rights reserved.
//
// C/C++ sun calculations created by Paul Schlyter
// sunriset.c
// http://stjarnhimlen.se/english.html
// SUNRISET.C - computes Sun rise/set times, start/end of twilight, and
// the length of the day at any date and latitude
// Written as DAYLEN.C, 1989-08-16
// Modified to SUNRISET.C, 1992-12-01
// (c) Paul Schlyter, 1989, 1992
// Released to the public domain by Paul Schlyter, December 1992
//
#import "EDSunriseSet.h"
//
// Defines from sunriset.c
//
#define INV360 ( 1.0 / 360.0 )
#define RADEG ( 180.0 / M_PI )
#define DEGRAD ( M_PI / 180.0 )
/* The trigonometric functions in degrees */
#define sind(x) sin((x)*DEGRAD)
#define cosd(x) cos((x)*DEGRAD)
#define tand(x) tan((x)*DEGRAD)
#define atand(x) (RADEG*atan(x))
#define asind(x) (RADEG*asin(x))
#define acosd(x) (RADEG*acos(x))
#define atan2d(y,x) (RADEG*atan2(y,x))
/* A macro to compute the number of days elapsed since 2000 Jan 0.0 */
/* (which is equal to 1999 Dec 31, 0h UT) */
#define days_since_2000_Jan_0(y,m,d) \
(367L*(y)-((7*((y)+(((m)+9)/12)))/4)+((275*(m))/9)+(d)-730530L)
#if defined(__IPHONE_8_0) || defined (__MAC_10_10)
#define EDGregorianCalendar NSCalendarIdentifierGregorian
#else
#define EDGregorianCalendar NSGregorianCalendar
#endif
#pragma mark - Readwrite accessors only private
@interface EDSunriseSet()
@property (nonatomic) double latitude;
@property (nonatomic) double longitude;
@property (nonatomic, strong) NSTimeZone *timezone;
@property (nonatomic, strong) NSCalendar *calendar;
@property (nonatomic, strong) NSTimeZone *utcTimeZone;
@property (readwrite, strong) NSDate *date;
@property (readwrite, strong) NSDate *sunset;
@property (readwrite, strong) NSDate *sunrise;
@property (readwrite, strong) NSDate *civilTwilightStart;
@property (readwrite, strong) NSDate *civilTwilightEnd;
@property (readwrite, strong) NSDate *nauticalTwilightStart;
@property (readwrite, strong) NSDate *nauticalTwilightEnd;
@property (readwrite, strong) NSDate *astronomicalTwilightStart;
@property (readwrite, strong) NSDate *astronomicalTwilightEnd;
@property (readwrite, strong) NSDateComponents* localSunrise;
@property (readwrite, strong) NSDateComponents* localSunset;
@property (readwrite, strong) NSDateComponents* localCivilTwilightStart;
@property (readwrite, strong) NSDateComponents* localCivilTwilightEnd;
@property (readwrite, strong) NSDateComponents* localNauticalTwilightStart;
@property (readwrite, strong) NSDateComponents* localNauticalTwilightEnd;
@property (readwrite, strong) NSDateComponents* localAstronomicalTwilightStart;
@property (readwrite, strong) NSDateComponents* localAstronomicalTwilightEnd;
@end
#pragma mark - Calculations from sunriset.c
@implementation EDSunriseSet(Calculations)
/*****************************************/
/* Reduce angle to within 0..360 degrees */
/*****************************************/
-(double) revolution:(double) x
{
return( x - 360.0 * floor( x * INV360 ) );
}
/*********************************************/
/* Reduce angle to within -180..+180 degrees */
/*********************************************/
-(double) rev180:(double) x
{
return( x - 360.0 * floor( x * INV360 + 0.5 ) );
}
-(double) GMST0:(double) d
{
double sidtim0;
/* Sidtime at 0h UT = L (Sun's mean longitude) + 180.0 degr */
/* L = M + w, as defined in sunpos(). Since I'm too lazy to */
/* add these numbers, I'll let the C compiler do it for me. */
/* Any decent C compiler will add the constants at compile */
/* time, imposing no runtime or code overhead. */
sidtim0 = [self revolution: ( 180.0 + 356.0470 + 282.9404 ) +
( 0.9856002585 + 4.70935E-5 ) * d];
return sidtim0;
}
/******************************************************/
/* Computes the Sun's ecliptic longitude and distance */
/* at an instant given in d, number of days since */
/* 2000 Jan 0.0. The Sun's ecliptic latitude is not */
/* computed, since it's always very near 0. */
/******************************************************/
-(void) sunposAtDay:(double)d longitude:(double*)lon r:(double *)r
{
double M, /* Mean anomaly of the Sun */
w, /* Mean longitude of perihelion */
/* Note: Sun's mean longitude = M + w */
e, /* Eccentricity of Earth's orbit */
E, /* Eccentric anomaly */
x, y, /* x, y coordinates in orbit */
v; /* True anomaly */
/* Compute mean elements */
M = [self revolution:( 356.0470 + 0.9856002585 * d )];
w = 282.9404 + 4.70935E-5 * d;
e = 0.016709 - 1.151E-9 * d;
/* Compute true longitude and radius vector */
E = M + e * RADEG * sind(M) * ( 1.0 + e * cosd(M) );
x = cosd(E) - e;
y = sqrt( 1.0 - e*e ) * sind(E);
*r = sqrt( x*x + y*y ); /* Solar distance */
v = atan2d( y, x ); /* True anomaly */
*lon = v + w; /* True solar longitude */
if ( *lon >= 360.0 )
*lon -= 360.0; /* Make it 0..360 degrees */
}
-(void) sun_RA_decAtDay:(double)d RA:(double*)RA decl:(double *)dec r:(double *)r
{
double lon, obl_ecl;
double xs, ys, zs;
double xe, ye, ze;
/* Compute Sun's ecliptical coordinates */
//sunpos( d, &lon, r );
[self sunposAtDay:d longitude:&lon r:r];
/* Compute ecliptic rectangular coordinates */
xs = *r * cosd(lon);
ys = *r * sind(lon);
zs = 0; /* because the Sun is always in the ecliptic plane! */
/* Compute obliquity of ecliptic (inclination of Earth's axis) */
obl_ecl = 23.4393 - 3.563E-7 * d;
/* Convert to equatorial rectangular coordinates - x is unchanged */
xe = xs;
ye = ys * cosd(obl_ecl);
ze = ys * sind(obl_ecl);
/* Convert to spherical coordinates */
*RA = atan2d( ye, xe );
*dec = atan2d( ze, sqrt(xe*xe + ye*ye) );
} /* sun_RA_dec */
#define sun_rise_set(year,month,day,lon,lat,rise,set) \
__sunriset__( year, month, day, lon, lat, -35.0/60.0, 1, rise, set )
-(int)sunRiseSetForYear:(int)year month:(int)month day:(int)day longitude:(double)lon latitude:(double)lat
trise:(double *)trise tset:(double *)tset
{
return [self sunRiseSetHelperForYear:year month:month day:day longitude:lon latitude:lat altitude:(-35.0/60.0)
upper_limb:1 trise:trise tset:tset];
}
/*
#define civil_twilight(year,month,day,lon,lat,start,end) \
__sunriset__( year, month, day, lon, lat, -6.0, 0, start, end )
*/
-(int) civilTwilightForYear:(int)year month:(int)month day:(int)day longitude:(double)lon latitude:(double)lat
trise:(double *)trise tset:(double *)tset
{
return [self sunRiseSetHelperForYear:year month:month day:day longitude:lon latitude:lat altitude:-6.0
upper_limb:0 trise:trise tset:tset];
}
/*
#define nautical_twilight(year,month,day,lon,lat,start,end) \
__sunriset__( year, month, day, lon, lat, -12.0, 0, start, end )
*/
-(int) nauticalTwilightForYear:(int)year month:(int)month day:(int)day longitude:(double)lon latitude:(double)lat
trise:(double *)trise tset:(double *)tset
{
return [self sunRiseSetHelperForYear:year month:month day:day longitude:lon latitude:lat altitude:-12.0
upper_limb:0 trise:trise tset:tset];
}
/*
#define astronomical_twilight(year,month,day,lon,lat,start,end) \
__sunriset__( year, month, day, lon, lat, -18.0, 0, start, end )
*/
-(int) astronomicalTwilightForYear:(int)year month:(int)month day:(int)day longitude:(double)lon latitude:(double)lat
trise:(double *)trise tset:(double *)tset
{
return [self sunRiseSetHelperForYear:year month:month day:day longitude:lon latitude:lat altitude:-18.0
upper_limb:0 trise:trise tset:tset];
}
/***************************************************************************/
/* Note: year,month,date = calendar date, 1801-2099 only. */
/* Eastern longitude positive, Western longitude negative */
/* Northern latitude positive, Southern latitude negative */
/* The longitude value IS critical in this function! */
/* altit = the altitude which the Sun should cross */
/* Set to -35/60 degrees for rise/set, -6 degrees */
/* for civil, -12 degrees for nautical and -18 */
/* degrees for astronomical twilight. */
/* upper_limb: non-zero -> upper limb, zero -> center */
/* Set to non-zero (e.g. 1) when computing rise/set */
/* times, and to zero when computing start/end of */
/* twilight. */
/* *rise = where to store the rise time */
/* *set = where to store the set time */
/* Both times are relative to the specified altitude, */
/* and thus this function can be used to comupte */
/* various twilight times, as well as rise/set times */
/* Return value: 0 = sun rises/sets this day, times stored at */
/* *trise and *tset. */
/* +1 = sun above the specified "horizon" 24 hours. */
/* *trise set to time when the sun is at south, */
/* minus 12 hours while *tset is set to the south */
/* time plus 12 hours. "Day" length = 24 hours */
/* -1 = sun is below the specified "horizon" 24 hours */
/* "Day" length = 0 hours, *trise and *tset are */
/* both set to the time when the sun is at south. */
/* */
/**********************************************************************/
-(int)sunRiseSetHelperForYear:(int)year month:(int)month day:(int)day longitude:(double)lon latitude:(double)lat
altitude:(double)altit upper_limb:(int)upper_limb trise:(double *)trise tset:(double *)tset
{
double d, /* Days since 2000 Jan 0.0 (negative before) */
sr, /* Solar distance, astronomical units */
sRA, /* Sun's Right Ascension */
sdec, /* Sun's declination */
sradius, /* Sun's apparent radius */
t, /* Diurnal arc */
tsouth, /* Time when Sun is at south */
sidtime; /* Local sidereal time */
int rc = 0; /* Return cde from function - usually 0 */
/* Compute d of 12h local mean solar time */
d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
/* Compute local sideral time of this moment */
//sidtime = revolution( GMST0(d) + 180.0 + lon );
sidtime = [self revolution:[self GMST0:d] + 180.0 + lon];
/* Compute Sun's RA + Decl at this moment */
//sun_RA_dec( d, &sRA, &sdec, &sr );
[self sun_RA_decAtDay:d RA: &sRA decl:&sdec r:&sr];
/* Compute time when Sun is at south - in hours UT */
//tsouth = 12.0 - rev180(sidtime - sRA)/15.0;
tsouth = 12.0 - [self rev180:sidtime - sRA] / 15.0;
/* Compute the Sun's apparent radius, degrees */
sradius = 0.2666 / sr;
/* Do correction to upper limb, if necessary */
if ( upper_limb )
altit -= sradius;
/* Compute the diurnal arc that the Sun traverses to reach */
/* the specified altitide altit: */
{
double cost;
cost = ( sind(altit) - sind(lat) * sind(sdec) ) /
( cosd(lat) * cosd(sdec) );
if ( cost >= 1.0 )
rc = -1, t = 0.0; /* Sun always below altit */
else if ( cost <= -1.0 )
rc = +1, t = 12.0; /* Sun always above altit */
else
t = acosd(cost)/15.0; /* The diurnal arc, hours */
}
/* Store rise and set times - in hours UT */
*trise = tsouth - t;
*tset = tsouth + t;
return rc;
} /* __sunriset__ */
@end
#pragma mark - Private Implementation
@implementation EDSunriseSet(Private)
static const int kSecondsInHour= 60.0*60.0;
-(NSDate*)utcTime:(NSDateComponents*)dateComponents withOffset:(NSTimeInterval)interval
{
[self.calendar setTimeZone:self.utcTimeZone];
return [[self.calendar dateFromComponents:dateComponents] dateByAddingTimeInterval:(NSTimeInterval)(interval)];
}
-(NSDateComponents*)localTime:(NSDate*)refDate
{
[self.calendar setTimeZone:self.timezone];
// Return only hour, minute, seconds
NSDateComponents *dc = [self.calendar components:( NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond) fromDate:refDate] ;
return dc;
}
- (instancetype) init {
[super doesNotRecognizeSelector:_cmd];
return nil;
}
-(NSString *)description
{
return [NSString stringWithFormat:
@"Date: %@\nTimeZone: %@\n"
@"Local Sunrise: %@\n"
@"Local Sunset: %@\n"
@"Local Civil Twilight Start: %@\n"
@"Local Civil Twilight End: %@\n"
@"Local Nautical Twilight Start: %@\n"
@"Local Nautical Twilight End: %@\n"
@"Local Astronomical Twilight Start: %@\n"
@"Local Astronomical Twilight End: %@\n",
self.date.description, self.timezone.name,
self.localSunrise.description, self.localSunset.description,
self.localCivilTwilightStart, self.localCivilTwilightEnd,
self.localNauticalTwilightStart, self.localNauticalTwilightEnd,
self.localAstronomicalTwilightStart, self.localAstronomicalTwilightEnd
];
}
#pragma mark - Calculation methods
-(void)calculateSunriseSunset
{
// Get date components
[self.calendar setTimeZone:self.timezone];
NSDateComponents *dateComponents = [self.calendar components:( NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay ) fromDate:self.date];
// Calculate sunrise and sunset
double rise=0.0, set=0.0;
[self sunRiseSetForYear:(int)[dateComponents year] month:(int)[dateComponents month] day:(int)[dateComponents day] longitude:self.longitude latitude:self.latitude
trise:&rise tset:&set ];
NSTimeInterval secondsRise = rise*kSecondsInHour;
NSTimeInterval secondsSet = set*kSecondsInHour;
self.sunrise = [self utcTime:dateComponents withOffset:(NSTimeInterval)secondsRise];
self.sunset = [self utcTime:dateComponents withOffset:(NSTimeInterval)secondsSet];
self.localSunrise = [self localTime:self.sunrise];
self.localSunset = [self localTime:self.sunset];
}
-(void)calculateTwilight
{
// Get date components
[self.calendar setTimeZone:self.timezone];
NSDateComponents *dateComponents = [self.calendar components:( NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay ) fromDate:self.date];
double start=0.0, end=0.0;
// Civil twilight
[self civilTwilightForYear:(int)[dateComponents year] month:(int)[dateComponents month] day:(int)[dateComponents day] longitude:self.longitude latitude:self.latitude
trise:&start tset:&end ];
self.civilTwilightStart = [self utcTime:dateComponents withOffset:(NSTimeInterval)(start*kSecondsInHour)];
self.civilTwilightEnd = [self utcTime:dateComponents withOffset:(NSTimeInterval)(end*kSecondsInHour)];
self.localCivilTwilightStart = [self localTime:self.civilTwilightStart];
self.localCivilTwilightEnd = [self localTime:self.civilTwilightEnd];
// Nautical twilight
[self nauticalTwilightForYear:(int)[dateComponents year] month:(int)[dateComponents month] day:(int)[dateComponents day] longitude:self.longitude latitude:self.latitude
trise:&start tset:&end ];
self.nauticalTwilightStart = [self utcTime:dateComponents withOffset:(NSTimeInterval)(start*kSecondsInHour)];
self.nauticalTwilightEnd = [self utcTime:dateComponents withOffset:(NSTimeInterval)(end*kSecondsInHour)];
self.localNauticalTwilightStart = [self localTime:self.nauticalTwilightStart];
self.localNauticalTwilightEnd = [self localTime:self.nauticalTwilightEnd];
// Astronomical twilight
[self astronomicalTwilightForYear:(int)[dateComponents year] month:(int)[dateComponents month] day:(int)[dateComponents day] longitude:self.longitude latitude:self.latitude
trise:&start tset:&end ];
self.astronomicalTwilightStart = [self utcTime:dateComponents withOffset:(NSTimeInterval)(start*kSecondsInHour)];
self.astronomicalTwilightEnd = [self utcTime:dateComponents withOffset:(NSTimeInterval)(end*kSecondsInHour)];
self.localAstronomicalTwilightStart = [self localTime:self.astronomicalTwilightStart];
self.localAstronomicalTwilightEnd = [self localTime:self.astronomicalTwilightEnd];
}
-(void)calculate
{
[self calculateSunriseSunset];
[self calculateTwilight];
}
@end
#pragma mark - Public Implementation
@implementation EDSunriseSet
#pragma mark - Initialization
-(EDSunriseSet*)initWithDate:(NSDate*)date timezone:(NSTimeZone*)tz latitude:(double)latitude longitude:(double)longitude {
self = [super init];
if( self )
{
self.latitude = latitude;
self.longitude = longitude;
self.timezone = tz;
self.date = date;
self.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:EDGregorianCalendar];
self.utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
[self calculate];
}
return self;
}
+(EDSunriseSet*)sunrisesetWithDate:(NSDate*)date timezone:(NSTimeZone*)tz latitude:(double)latitude longitude:(double)longitude {
return [[EDSunriseSet alloc] initWithDate:date timezone:tz latitude:latitude longitude:longitude];
}
@end

21
Clocker/Floating Window/CLFloatingWindowController.m

@ -111,6 +111,8 @@ NSString *const CLTimezoneCellIdentifier = @"timeZoneCell";
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.defaultPreferences[row]];
cell.sunriseSetTime.stringValue = [dataObject getFormattedSunriseOrSunsetTime];
NSTextView *customLabel = (NSTextView*)[cell.relativeDate.window
fieldEditor:YES
forObject:cell.relativeDate];
@ -124,6 +126,10 @@ NSString *const CLTimezoneCellIdentifier = @"timeZoneCell";
[cell.customName setDrawsBackground:YES];
[cell.customName setBackgroundColor:[NSColor blackColor]];
customLabel.insertionPointColor = [NSColor whiteColor];
cell.sunriseSetImage.image = dataObject.sunriseOrSunset ?
[NSImage imageNamed:@"White Sunrise"] : [NSImage imageNamed:@"White Sunset"];
cell.sunriseSetImage.image = dataObject.sunriseOrSunset ?
[NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"Sunset"];
}
else
{
@ -145,14 +151,13 @@ NSString *const CLTimezoneCellIdentifier = @"timeZoneCell";
NSNumber *displayFutureSlider = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplayFutureSliderKey];
if ([displayFutureSlider isEqualToNumber:[NSNumber numberWithInteger:1]])
{
self.futureSlider.hidden = YES;
}
else
{
self.futureSlider.hidden = NO;
}
self.futureSlider.hidden = [displayFutureSlider isEqualToNumber:[NSNumber numberWithInteger:1]] ? YES : NO;
NSNumber *displaySunriseSunsetTime = [[NSUserDefaults standardUserDefaults] objectForKey:CLSunriseSunsetTime];
cell.sunriseSetTime.hidden = [displaySunriseSunsetTime isEqualToNumber:@(1)] ? YES : NO;
cell.sunriseSetImage.hidden = [displaySunriseSunsetTime isEqualToNumber:@(1)] ? YES : NO;
[cell setUpAutoLayoutWithCell:cell];

31
Clocker/Floating Window/en.lproj/CLFloatingWindow.xib

@ -57,6 +57,26 @@
<rect key="frame" x="1" y="0.0" width="279" height="60"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7Tq-t6-KS6">
<rect key="frame" x="203" y="4" width="20" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="20" id="JLt-So-9GB"/>
<constraint firstAttribute="height" constant="20" id="gQ5-I6-hfW"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="Sunrise" id="aeR-XC-8J2"/>
</imageView>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="w0H-z4-Qmv">
<rect key="frame" x="224" y="7" width="49" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="45" id="v6B-Bv-Ye1"/>
<constraint firstAttribute="height" constant="17" id="zYu-u6-R0W"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" alignment="center" placeholderString="07:00 PM" id="ENI-4b-K6F">
<font key="font" size="11" name="SFUIDisplay-Ultralight"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" tag="100" preferredMaxLayoutWidth="150" translatesAutoresizingMaskIntoConstraints="NO" id="Zyy-Fw-K7Z" customClass="CLPanelTextField">
<rect key="frame" x="7" y="33" width="154" height="22"/>
<constraints>
@ -86,7 +106,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" tag="101" preferredMaxLayoutWidth="110" translatesAutoresizingMaskIntoConstraints="NO" id="DSw-uJ-JCx">
<rect key="frame" x="159" y="21" width="114" height="35"/>
<rect key="frame" x="159" y="24" width="114" height="35"/>
<constraints>
<constraint firstAttribute="width" constant="110" id="seR-NV-Bdf"/>
<constraint firstAttribute="height" constant="35" id="wBx-lE-7e5"/>
@ -103,12 +123,18 @@
<constraint firstItem="Zyy-Fw-K7Z" firstAttribute="top" secondItem="8mq-8K-c34" secondAttribute="top" constant="5" id="B0D-ik-bxk"/>
<constraint firstAttribute="trailing" secondItem="DSw-uJ-JCx" secondAttribute="trailing" constant="8" id="IA6-vj-gHR"/>
<constraint firstItem="Zyy-Fw-K7Z" firstAttribute="leading" secondItem="8mq-8K-c34" secondAttribute="leading" constant="9" id="JFG-Yz-esL"/>
<constraint firstItem="DSw-uJ-JCx" firstAttribute="centerY" secondItem="8mq-8K-c34" secondAttribute="centerY" constant="-8" id="ko5-Yd-e4R"/>
<constraint firstItem="w0H-z4-Qmv" firstAttribute="top" secondItem="DSw-uJ-JCx" secondAttribute="bottom" id="XQh-GT-9wS"/>
<constraint firstItem="DSw-uJ-JCx" firstAttribute="top" secondItem="8mq-8K-c34" secondAttribute="top" constant="1" id="Zib-Mn-8DY"/>
<constraint firstItem="w0H-z4-Qmv" firstAttribute="leading" secondItem="7Tq-t6-KS6" secondAttribute="trailing" constant="3" id="lla-8q-Xtc"/>
<constraint firstItem="wFR-Xg-kpb" firstAttribute="leading" secondItem="8mq-8K-c34" secondAttribute="leading" constant="10" id="p0N-YR-EDR"/>
<constraint firstItem="7Tq-t6-KS6" firstAttribute="top" secondItem="DSw-uJ-JCx" secondAttribute="bottom" id="wrv-xK-4wC"/>
<constraint firstAttribute="trailing" secondItem="w0H-z4-Qmv" secondAttribute="trailing" constant="8" id="wtp-3R-eGY"/>
</constraints>
<connections>
<outlet property="customName" destination="Zyy-Fw-K7Z" id="X1r-mx-tOf"/>
<outlet property="relativeDate" destination="wFR-Xg-kpb" id="Yur-Tf-mwV"/>
<outlet property="sunriseSetImage" destination="7Tq-t6-KS6" id="Wrx-aS-zy4"/>
<outlet property="sunriseSetTime" destination="w0H-z4-Qmv" id="bAH-4f-3Uh"/>
<outlet property="textField" destination="Zyy-Fw-K7Z" id="8fF-LK-hhX"/>
<outlet property="time" destination="DSw-uJ-JCx" id="vCh-BC-lB4"/>
</connections>
@ -264,5 +290,6 @@
<image name="ClockerIcon-16" width="16" height="16"/>
<image name="NSActionTemplate" width="14" height="14"/>
<image name="PowerIcon" width="270" height="270"/>
<image name="Sunrise" width="512" height="512"/>
</resources>
</document>

6
Clocker/Model/CLTimezoneData.h

@ -24,12 +24,14 @@ typedef enum : NSUInteger {
@property (copy, nonatomic) NSString *longitude;
@property (strong, nonatomic) NSDate *nextUpdate;
@property (strong, nonatomic) NSNumber *isFavourite;
@property (strong, nonatomic) NSDate *sunriseTime;
@property (strong, nonatomic) NSDate *sunsetTime;
@property (assign, nonatomic) BOOL sunriseOrSunset; //YES for Sunrise, NO for Sunset
+ (instancetype)getCustomObject:(NSData *)encodedData;
+ (void)setInitialTimezoneData;
- (void)sendAnalyticsData;
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
- (BOOL)saveObjectToPreferences;
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue;
@ -38,6 +40,8 @@ typedef enum : NSUInteger {
- (NSString *)getDateForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue andDisplayType:(CLDateDisplayType)type;
- (NSString *)formatStringShouldContainCity:(BOOL)value;
- (NSString *)getMenuTitle;
- (NSString *)getFormattedSunriseOrSunsetTime;
- (NSImage *)getFormattedSunriseOrSunsetImage;
/*
- (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell;

157
Clocker/Model/CLTimezoneData.m

@ -13,7 +13,7 @@
#import "PanelController.h"
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include "EDSunriseSet.h"
@implementation CLTimezoneData
@ -81,8 +81,12 @@
[coder encodeObject:self.formattedAddress forKey:@"formattedAddress"];
[coder encodeObject:self.customLabel forKey:@"customLabel"];
[coder encodeObject:self.timezoneID forKey:@"timezoneID"];
[coder encodeObject:self.nextUpdate forKey:@"latitude"];
[coder encodeObject:self.nextUpdate forKey:@"nextUpdate"];
[coder encodeObject:self.latitude forKey:@"latitude"];
[coder encodeObject:self.longitude forKey:@"longitude"];
[coder encodeObject:self.isFavourite forKey:@"isFavourite"];
[coder encodeObject:self.sunriseTime forKey:@"sunriseTime"];
[coder encodeObject:self.sunsetTime forKey:@"sunsetTime"];
}
- (instancetype)initWithCoder:(NSCoder *)coder
@ -95,8 +99,12 @@
self.formattedAddress = [coder decodeObjectForKey:@"formattedAddress"];
self.customLabel = [coder decodeObjectForKey:@"customLabel"];
self.timezoneID = [coder decodeObjectForKey:@"timezoneID"];
self.nextUpdate = [coder decodeObjectForKey:@"latitude"];
self.nextUpdate = [coder decodeObjectForKey:@"nextUpdate"];
self.latitude = [coder decodeObjectForKey:@"latitude"];
self.longitude = [coder decodeObjectForKey:@"longitude"];
self.isFavourite = [coder decodeObjectForKey:@"isFavourite"];
self.sunriseTime = [coder decodeObjectForKey:@"sunriseTime"];
self.sunsetTime = [coder decodeObjectForKey:@"sunsetTime"];
}
return self;
@ -104,13 +112,15 @@
-(NSString *)description
{
return [NSString stringWithFormat:@"TimezoneID: %@\nFormatted Address: %@\nCustom Label: %@\nLatitude: %@\nLongitude:%@\nPlaceID: %@\nisFavourite: %@", self.timezoneID,
return [NSString stringWithFormat:@"TimezoneID: %@\nFormatted Address: %@\nCustom Label: %@\nLatitude: %@\nLongitude:%@\nPlaceID: %@\nisFavourite: %@\nSunrise Time: %@\nSunset Time: %@", self.timezoneID,
self.formattedAddress,
self.customLabel,
self.latitude,
self.longitude,
self.place_id,
self.isFavourite];
self.isFavourite,
self.sunriseTime,
self.sunsetTime];
}
- (NSString *)formatStringShouldContainCity:(BOOL)value
@ -142,47 +152,6 @@
}
/*
- (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell
{
if (!self.shouldFetchSunTimings) {
return CLEmptyString;
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSDate *sunTime = [formatter dateFromString:self.sunriseTime];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
dateFormatter.timeStyle = kCFDateFormatterShortStyle;
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *newDate = [dateFormatter stringFromDate:[NSDate date]];
NSDateFormatter *dateConversion = [[NSDateFormatter alloc] init];
dateConversion.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
dateConversion.dateStyle = kCFDateFormatterShortStyle;
dateConversion.timeStyle = kCFDateFormatterShortStyle;
dateConversion.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey];
if ([sunTime laterDate:[dateConversion dateFromString:newDate]] == sunTime)
{
cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ?
[NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"White Sunrise"];
return [self.sunriseTime substringFromIndex:11];
}
else
{
cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ?
[NSImage imageNamed:@"Sunset"] : [NSImage imageNamed:@"White Sunset"];
return [self.sunsetTime substringFromIndex:11];
}
}*/
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue
{
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar];
@ -203,6 +172,13 @@
return [dateFormatter stringFromDate:newDate];
}
-(void)initializeSunriseSunset
{
EDSunriseSet *sunriseSetObject = [EDSunriseSet sunrisesetWithDate:[NSDate date] timezone:[NSTimeZone timeZoneWithName:self.timezoneID] latitude:self.latitude.doubleValue longitude:self.longitude.doubleValue];
self.sunriseTime = sunriseSetObject.sunrise;
self.sunsetTime = sunriseSetObject.sunset;
}
- (NSString *)getLocalCurrentDate
{
NSDateFormatter *dateFormatter = [NSDateFormatter new];
@ -400,57 +376,68 @@
}
}
if (menuTitle.length > 0)
{
[menuTitle appendFormat:@" %@",[self getTimeForTimeZoneWithFutureSliderValue:0]];
}
else
{
[menuTitle appendString:[self getTimeForTimeZoneWithFutureSliderValue:0]];
}
menuTitle.length > 0 ?
[menuTitle appendFormat:@" %@",[self getTimeForTimeZoneWithFutureSliderValue:0]] :
[menuTitle appendString:[self getTimeForTimeZoneWithFutureSliderValue:0]];
return menuTitle;
}
- (void)sendAnalyticsData
-(NSString *)getFormattedSunriseOrSunsetTime
{
NSString *uniqueIdentifier = [self getSerialNumber];
if (uniqueIdentifier == nil)
{
uniqueIdentifier = @"N/A";
}
[self initializeSunriseSunset];
NSString *timezoneDate = [self getFullFledgedDateForTime];
NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateFormat = @"yyyy-MM-d hh:mm a";
NSDate *formattedDate = [formatter dateFromString:timezoneDate];
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar];
self.sunriseOrSunset = [self.sunriseTime isLaterThanOrEqualTo:formattedDate];
/*
NSDate *newDate = self.sunriseOrSunset ?
[currentCalendar dateByAddingUnit:NSCalendarUnitMinute
value:0
toDate:self.sunriseTime
options:kNilOptions] :
[currentCalendar dateByAddingUnit:NSCalendarUnitMinute
value:0
toDate:self.sunsetTime
options:kNilOptions];
PFObject *feedbackObject = [PFObject objectWithClassName:@"CLTimezoneData"];
feedbackObject[@"formattedAddress"] = self.formattedAddress;
feedbackObject[@"timezoneID"] = self.timezoneID;
feedbackObject[@"uniqueID"] = uniqueIdentifier;
[feedbackObject saveEventually];*/
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateStyle = kCFDateFormatterNoStyle;
NSNumber *is24HourFormatSelected = [[NSUserDefaults standardUserDefaults] objectForKey:CL24hourFormatSelectedKey];
is24HourFormatSelected.boolValue ? [dateFormatter setDateFormat:@"HH:mm"] : [dateFormatter setDateFormat:@"hh:mm a"];
//In the format 22:10
return [dateFormatter stringFromDate:newDate];
}
- (NSString *)getSerialNumber
- (NSString *)getFullFledgedDateForTime
{
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
IOServiceMatching("IOPlatformExpertDevice"));
CFStringRef serialNumberAsCFString = NULL;
if (platformExpert) {
serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert,
CFSTR(kIOPlatformSerialNumberKey),
kCFAllocatorDefault, 0);
IOObjectRelease(platformExpert);
}
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate *newDate = [currentCalendar dateByAddingUnit:NSCalendarUnitMinute
value:0
toDate:[NSDate date]
options:kNilOptions];
NSDateFormatter *dateFormatter = [NSDateFormatter new];
NSString *serialNumberAsNSString = nil;
if (serialNumberAsCFString) {
serialNumberAsNSString = [NSString stringWithString:(__bridge NSString *)serialNumberAsCFString];
CFRelease(serialNumberAsCFString);
}
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm a"];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
return serialNumberAsNSString;
return [dateFormatter stringFromDate:newDate];
}
@end

1
Clocker/Utilities/CommonStrings.h

@ -29,5 +29,6 @@ extern NSString *const CLShowPlaceInMenu;
extern NSString *const CLDisplayFutureSliderKey;
extern NSString *const CLStartAtLogin;
extern NSString *const CLShowAppInForeground;
extern NSString *const CLSunriseSunsetTime;
@end

2
Clocker/Utilities/CommonStrings.m

@ -27,6 +27,6 @@ NSString *const CLShowDateInMenu = @"showDate";
NSString *const CLShowPlaceInMenu = @"showPlaceName";
NSString *const CLStartAtLogin = @"startAtLogin";
NSString *const CLShowAppInForeground = @"displayAppAsForegroundApp";
NSString *const CLSunriseSunsetTime = @"showSunriseSetTime";
@end

39
Clocker/en.lproj/Panel.xib

@ -54,11 +54,11 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="timeZoneCell" id="qbN-ba-fho" customClass="CLTimezoneCellView">
<rect key="frame" x="1" y="0.0" width="279" height="60"/>
<rect key="frame" x="1" y="0.0" width="279" height="61"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" tag="100" preferredMaxLayoutWidth="150" translatesAutoresizingMaskIntoConstraints="NO" id="etF-33-bCB">
<rect key="frame" x="7" y="33" width="154" height="22"/>
<rect key="frame" x="7" y="34" width="154" height="22"/>
<constraints>
<constraint firstAttribute="width" constant="150" id="32b-h6-joo"/>
<constraint firstAttribute="height" constant="22" id="vod-YN-iNX"/>
@ -73,7 +73,7 @@
</connections>
</textField>
<textField verticalHuggingPriority="750" tag="102" preferredMaxLayoutWidth="72" translatesAutoresizingMaskIntoConstraints="NO" id="QUd-7D-q14">
<rect key="frame" x="8" y="11" width="76" height="20"/>
<rect key="frame" x="8" y="12" width="76" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="42Y-hy-Uo7"/>
<constraint firstAttribute="width" constant="72" id="fkH-oq-qvM"/>
@ -85,7 +85,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" tag="101" preferredMaxLayoutWidth="110" translatesAutoresizingMaskIntoConstraints="NO" id="vnv-J2-7r1">
<rect key="frame" x="159" y="21" width="114" height="35"/>
<rect key="frame" x="159" y="25" width="114" height="35"/>
<constraints>
<constraint firstAttribute="height" constant="35" id="3WU-de-OQL"/>
<constraint firstAttribute="width" constant="110" id="cQV-gJ-zMz"/>
@ -96,24 +96,50 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7OQ-cr-VJS">
<rect key="frame" x="203" y="5" width="20" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="20" id="Vmz-Ji-Y0Q"/>
<constraint firstAttribute="height" constant="20" id="qNj-EP-era"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="Sunrise" id="U2f-NK-Gua"/>
</imageView>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="uOg-ij-alO">
<rect key="frame" x="224" y="8" width="49" height="17"/>
<constraints>
<constraint firstAttribute="height" constant="17" id="89H-r0-Dnh"/>
<constraint firstAttribute="width" constant="45" id="8KH-Ks-d4T"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" alignment="center" placeholderString="07:00 PM" id="qpH-kn-cMT">
<font key="font" size="11" name="SFUIDisplay-Ultralight"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="QUd-7D-q14" firstAttribute="leading" secondItem="qbN-ba-fho" secondAttribute="leading" constant="10" id="0Qz-Ev-efP"/>
<constraint firstItem="uOg-ij-alO" firstAttribute="leading" secondItem="7OQ-cr-VJS" secondAttribute="trailing" constant="3" id="6bc-YK-jtD"/>
<constraint firstItem="etF-33-bCB" firstAttribute="top" secondItem="qbN-ba-fho" secondAttribute="top" constant="5" id="Lct-kG-usb"/>
<constraint firstItem="vnv-J2-7r1" firstAttribute="centerY" secondItem="qbN-ba-fho" secondAttribute="centerY" constant="-8" id="TuQ-gE-ZUh"/>
<constraint firstAttribute="trailing" secondItem="uOg-ij-alO" secondAttribute="trailing" constant="8" id="Siz-97-mYl"/>
<constraint firstItem="QUd-7D-q14" firstAttribute="top" secondItem="etF-33-bCB" secondAttribute="bottom" constant="2" id="VO6-Zn-eA3"/>
<constraint firstItem="uOg-ij-alO" firstAttribute="top" secondItem="vnv-J2-7r1" secondAttribute="bottom" id="j2E-3l-6B2"/>
<constraint firstItem="7OQ-cr-VJS" firstAttribute="top" secondItem="vnv-J2-7r1" secondAttribute="bottom" id="uZd-y0-d6A"/>
<constraint firstItem="etF-33-bCB" firstAttribute="leading" secondItem="qbN-ba-fho" secondAttribute="leading" constant="9" id="ueW-ow-ZRq"/>
<constraint firstItem="vnv-J2-7r1" firstAttribute="top" secondItem="qbN-ba-fho" secondAttribute="top" constant="1" id="vGp-XY-wiJ"/>
<constraint firstAttribute="trailing" secondItem="vnv-J2-7r1" secondAttribute="trailing" constant="8" id="zXo-eA-0bQ"/>
</constraints>
<connections>
<outlet property="customName" destination="etF-33-bCB" id="6Yz-qc-WmD"/>
<outlet property="relativeDate" destination="QUd-7D-q14" id="Ath-zr-bGo"/>
<outlet property="sunriseSetImage" destination="7OQ-cr-VJS" id="gIq-Tc-B7e"/>
<outlet property="sunriseSetTime" destination="uOg-ij-alO" id="PgN-VP-joq"/>
<outlet property="textField" destination="etF-33-bCB" id="6fd-cc-Qq2"/>
<outlet property="time" destination="vnv-J2-7r1" id="XFD-GQ-9CD"/>
</connections>
</tableCellView>
<tableCellView identifier="ratingCellView" id="wWn-9q-AYl" customClass="CLRatingCellView">
<rect key="frame" x="1" y="61" width="279" height="50"/>
<rect key="frame" x="1" y="62" width="279" height="50"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="gRN-xJ-bfq">
@ -264,5 +290,6 @@
<image name="ClockerIcon-16" width="16" height="16"/>
<image name="NSActionTemplate" width="14" height="14"/>
<image name="PowerIcon" width="270" height="270"/>
<image name="Sunrise" width="512" height="512"/>
</resources>
</document>

Loading…
Cancel
Save