Dart : Show the time until the next time - dart

How to show a countdown time duration until the next alarm
Code:
TimeOfDay _nextSalah(List<SalahModel> salahs) {
DateTime now = DateTime.now();
List<TimeOfDay> times = [];
int currentSalah;
salahs.forEach((s) => times.add(s.time));
times.add(TimeOfDay(hour: now.hour, minute: now.minute));
times.sort((a, b) => a.hour.compareTo(b.hour));
currentSalah = times.indexWhere((time) => time.hour == now.hour);
return TimeOfDay(hour: times[currentSalah].hour, minute: times[currentSalah].minute);
}
But the time difference is wrong and it doesn't animate. Also how to make sure the time difference works when it's the same day and time of the next day i.e. now is Dec 1 2:30 PM and I want to get the difference on Dec 2 6:15 AM.

It does not work because TimeOfDay represents a time during the day, independent of the date that day might fall on or the time zone. The time is represented only by hour and minute.
If you want a countdown that spans multiple days a DateTime must be used and the time difference evaluation needs some math before formatting the result string, something like:
String nextTime(DateTime nextAlarmTime) {
List<int> ctime = [0, 0, 0, 0];
DateTime now = DateTime.now();
int diff = nextAlarmTime.difference(now).inSeconds;
ctime[0] = diff ~/ (24 * 60 * 60); // days
diff -= ctime[0] * 24 * 60 * 60;
ctime[1] = diff ~/ (60 * 60); // hours
diff -= ctime[1] * 60 * 60;
ctime[2] = diff ~/ 60; // minutes
ctime[3] = diff - ctime[2] * 60; // seconds
return ctime.map((val) => val.toString().padLeft(2, '0')).join(':');
}

Related

Running sum in background

Modified Question.
My fitness app will calculate the number of calories burned based on a calculated value for each second. I have a timer that will allow the app to pick back up should it. I can't get the running sum to continue calculating when the app goes into the background. I tried to place the running sum inside of a DispatchQueue but not getting the sum as expected. Any guidance is greatly appreciated.
Here's the code I have placed inside the function that updates the timer.
//MARK: - Update Timer Label
func updateTimerLabel() {
interval = -Int(timerStartDate.timeIntervalSinceNow)
time = interval
let hours = interval / 3600
let minutes = interval / 60 % 60
let seconds = interval % 60
print("Current interval = \(interval)")
timerLabel.text = String(format:"%02i:%02i:%02i", hours, minutes, seconds)
DispatchQueue.global(qos: .background).async {
if self.activityArray[self.currentArrayRow].2 <= 4.5 {
self.cps = self.activityArray[self.currentArrayRow].2 * Double(self.user.userWeightInKilo) / 3600
self.runningCPS = self.runningCPS + self.cps
print("MET \(self.activityArray[self.currentArrayRow].2) <= 4.5 * KG (\(Double(self.user.userWeightInKilo))) * HR (\(Double(self.user.userHeartRate))) / MaxHR (\(Double(self.user.maxHeartRate)) * interval \(Double(self.interval)) / 3600. Gives a cps 0f \(self.cps) and a runningCPS of \(self.runningCPS) ")
} else {
self.cps = self.activityArray[self.currentArrayRow].2 * Double(self.user.userWeightInKilo) * Double(self.user.userHeartRate) / Double(self.user.maxHeartRate) / 3600
self.runningCPS = self.runningCPS + self.cps
print("MET \(self.activityArray[self.currentArrayRow].2) > 4.5 * KG (\(Double(self.user.userWeightInKilo))) * HR (\(Double(self.user.userHeartRate))) / MaxHR (\(Double(self.user.maxHeartRate)) * interval \(Double(self.interval)) / 3600. Gives a cps 0f \(self.cps) and a runningCPS of \(self.runningCPS) ")
}
}
activeLabel.text = String(format: "%0.1f", runningCPS) + " Calories Burned"
}

How to customize my timer display to show only minutes and seconds?

My Timer is displaying Minutes and Hours, but once it gets to 60 minutes it restarts from 0 Minute.
Should I get rid of the modulo ( % 60 ) for minutes.
I would like my timer to display for ex: 80:45 ( basically not stopping at 60 min once it reaches 1 hour)
var min = 0
var sec = 0
func stringFromTimeInterval(interval: NSTimeInterval) -> String {
let interval = Int(interval)
let seconds = interval % 60
let minutes = (interval / 60) % 60
//let hours = (interval / 3600)// I don't need the hours
return String(format: "%02d:%02d",minutes, seconds)
}
% 60 means that it will spit out a minutes value that is the remainder when divided by 60(minutes). This is most probably because for time in the form hh:mm, you want it to go from 5:59 to 6:00, not 5:60. So changing the following line will give you what you seek.
let minutes = (interval / 60) % 60 -> let minutes = interval / 60

Display a negative time in Obj-C

It may sound simple however I am unsure how to do this. How do I display time in the following format?:
-00:00:00
I have tried using float and int values of the interval difference between two times however neither give a consistent display in the 00:00:00 format. I have also tried converting the time difference into date and then display as String.
This is the code I have used to convert my intervals :
NSDate * now = [NSDate date];
NSTimeInterval totalTime1 = [now timeIntervalSinceDate: timeEntry1];
NSTimeInterval totalTime2 = [now timeIntervalSinceDate: timeEntry2];
//must always be this way
int adjustedTime = totalTime1 - totalTime2;
int hours = adjustedTime / 3600;
int minutes = (adjustedTime / 60) % 60;
int seconds = adjustedTime % 60;
NSString * newTime = [NSString stringWithFormat:#"%02u:%02u:%02u", hours, minutes, seconds];
The above works fine for displaying positive time differences. However presents a variety of 00:423456:978098 and so on when it goes negative in both the NSLog and the Label.
When I convert and save as a type of NSDate I get (null) in NSLog and nothing in my Label.
When I use float it works but does not consistently display in the 00:00:00 format.
NOTE
The code I am using works immaculately for positive time differences. I need negative time differences to also display.
I also need to be able to save the negative time to CoreData. If this is not possible then I will work around, but displaying negative time formatted correctly is the main issue.
EDIT
My new revised code:
NSDate * now = [NSDate date];
NSTimeInterval totalTime1 = [now timeIntervalSinceDate: timeEntry1];
NSTimeInterval totalTime2 = [now timeIntervalSinceDate: timeEntry2];
//must always be this way
int adjustedTime = (int) (totalTime1 - totalTime2);
NSLog (#"What is the adjustedTime? %d", adjustedTime);
int hours = adjustedTime / 3600;
int minutes = (adjustedTime / 60) % 60;
int seconds = adjustedTime % 60;
NSString * newTime = [NSString stringWithFormat:#"%#%02d:%02d:%02d", adjustedTime < 0 ?#"-":#"", hours, minutes, seconds];
NSLog(#"What is the newTime? %#", newTime);
It is closer as now it displays negative numbers however the display is still incorrect when negative.
EDIT 2
A person who answered below suggested I try checking for negative if it is a boolean. Displaying did not change. Below are more log statements to demonstrate. NOTE I stopped using an updated seconds for sake of working out whether it affected the display and stored seconds separate to test, which is why there is no - sign or alteration to the seconds.
2015-01-09 09:30:14.526 App2.0[8398:498707] What is time 2 : 720
2015-01-09 09:30:14.526 App2.0[8398:498707] What is time 1 : 771
2015-01-09 09:30:14.526 App2.0[8398:498707] What is the adjusted time? 51
2015-01-09 09:30:14.527 App2.0[8398:498707] New Time: 00:00:51
2015-01-09 09:30:18.249 App2.0[8398:498707] What is time 2 : 900
2015-01-09 09:30:18.249 App2.0[8398:498707] What is time 1 : 771
2015-01-09 09:30:18.249 App2.0[8398:498707] What is the adjusted time? -129
2015-01-09 09:30:18.249 App2.0[8398:498707] New Time: -00:-2:51
2015-01-09 09:30:20.281 App2.0[8398:498707] What is time 2 : 840
2015-01-09 09:30:20.281 App2.0[8398:498707] What is time 1 : 771
2015-01-09 09:30:20.281 App2.0[8398:498707] What is the adjusted time? -69
2015-01-09 09:30:20.281 App2.0[8398:498707] New Time: -00:-1:51
2015-01-09 09:30:21.725 App2.0[8398:498707] What is time 2 : 780
2015-01-09 09:30:21.726 App2.0[8398:498707] What is time 1 : 771
2015-01-09 09:30:21.726 App2.0[8398:498707] What is the adjusted time? -9
2015-01-09 09:30:21.726 App2.0[8398:498707] New Time: -00:00:51
2015-01-09 09:30:30.161 App2.0[8398:498707] What is time 2 : 1080
2015-01-09 09:30:30.161 App2.0[8398:498707] What is time 1 : 771
2015-01-09 09:30:30.162 App2.0[8398:498707] What is the adjusted time? -309
2015-01-09 09:30:30.162 App2.0[8398:498707] New Time: -00:-5:51
2015-01-09 09:30:33.389 App2.0[8398:498707] What is time 2 : 4680
2015-01-09 09:30:33.389 App2.0[8398:498707] What is time 1 : 771
2015-01-09 09:30:33.390 App2.0[8398:498707] What is the adjusted time? -3909
2015-01-09 09:30:33.390 App2.0[8398:498707] New Time: --1:-5:51
2015-01-09 09:30:36.186 App2.0[8398:498707] What is time 2 : 8280
2015-01-09 09:30:36.187 App2.0[8398:498707] What is time 1 : 771
2015-01-09 09:30:36.187 App2.0[8398:498707] What is the adjusted time? -7509
2015-01-09 09:30:36.187 App2.0[8398:498707] New Time: --2:-5:51
2015-01-09 09:30:43.918 App2.0[8398:498707] What is time 2 : 660
2015-01-09 09:30:43.918 App2.0[8398:498707] What is time 1 : 771
2015-01-09 09:30:43.919 App2.0[8398:498707] What is the adjusted time? 111
2015-01-09 09:30:43.919 App2.0[8398:498707] New Time: 00:01:51
Since you're displaying the time components separately, you'll probably need some conditional logic to adjust the display depending on whether totalTime2 is before or after totalTime1
:
NSString *newTime = nil;
if (adjustedTime < 0) {
newTime = [NSString stringWithFormat:#"-%02d:%02d:%02d", hours, minutes, seconds];
}
else {
newTime = [NSString stringWithFormat:#"%02d:%02d:%02d", hours, minutes, seconds];
}
or if you prefer something more compact:
NSString *newTime = adjustedTime < 0 ? #"-" : #"";
newTime = [newTime stringByAppendingFormat:#"%02d:%02d:%02d", hours, minutes, seconds];
Also, as Wain points out in the comments, you'll need to take the absolute value of each component before using it to display:
int hours = abs(adjustedTime / 3600);
int minutes = abs((adjustedTime / 60) % 60);
int seconds = abs(adjustedTime % 60);
That should do the trick:
NSDate *now = [NSDate date];
NSTimeInterval totalTime1 = [now timeIntervalSinceDate: timeEntry1];
NSTimeInterval totalTime2 = [now timeIntervalSinceDate: timeEntry2];
NSLog(#"totalTime1: %f", totalTime1); // => -60.00;
NSLog(#"totalTime2: %f", totalTime2); // => 6023.00;
//must always be this way
int timeOffset = (int) (totalTime1 - totalTime2);
NSLog(#"timeOffset: %d", timeOffset); // => -6083;
BOOL showNegativePrefix = timeOffset < 0;
int hours = abs(timeOffset / 3600); // => 01
int minutes = abs((timeOffset / 60 ) % 60); // => 41
int seconds = abs(timeOffset % 60); // => 23
NSString * newTime = [NSString stringWithFormat:#"%#%02d:%02d:%02d", showNegativePrefix ? #"-" : #"", hours, minutes, seconds];
NSLog(#"%#", newTime); // => -01:41:23
You are almost there, all you need extra is a flag if the value is negative and to then format the positive difference preceded by a sign if needed. First set a flag and make the difference always positive:
int adjustedTime = ...;
BOOL isNeg;
if (adjustedTime < 0)
{
isNeg = YES;
adjustedTime = -adjustedTime; // make value +ve
}
else
isNeg = NO;
then do your math as before and change the format line to:
NSString *newTime = [NSString stringWithFormat:#"%#%02d:%02d:%02d", (isNeg ? #"-" : #""), hours, minutes, seconds];
Note: you need to use %d as your values are int not unsigned int.
HTH
Addendum
Here is the code again, including the bit of yours I skipped ("do your math as before"), with added comments:
int adjustedTime = totalTime1 - totalTime2;
// At this point adjustedTime may be negative, use the standard approach
// test if it is -ve, and if so set a flag and make the value +ve
BOOL isNeg;
if (adjustedTime < 0)
{
// we are here if -ve, set flag
isNeg = YES;
// and make the value +ve
adjustedTime = -adjustedTime;
}
else
isNeg = NO;
// at this point adjustedValue is ALWAYS +ve, isNeg is set if it was originally -ve
int hours = adjustedTime / 3600;
int minutes = (adjustedTime / 60) % 60;
int seconds = adjustedTime % 60;
// at this point hours, minutes & seconds MUST BE +VE as adjustedTime is +ve
// format the values, an optional sign based on isNeg followed by three POSITIVE numbers
NSString *newTime = [NSString stringWithFormat:#"%#%02d:%02d:%02d", (isNeg ? #"-" : #""), hours, minutes, seconds];
This can only print AT MOST ONE minus sign at the start from the string.
This approach (though with a test for the minimum negative integer as that cannot be negated) is the standard way to handle this issue.
The solutions presented by Sebastian Keller and CRD both suffer a problem when rolling over from negative to positive values, for example when displaying a countdown that starts with a negative value:
-1.896893 -00:00:01
-1.498020 -00:00:01
-1.099442 -00:00:01
-0.996686 00:00:00
-0.896971 00:00:00
-0.195021 00:00:00
-0.095020 00:00:00
0.004988 00:00:00
0.104940 00:00:00
0.504980 00:00:00
0.904981 00:00:00
1.000516 00:00:01
1.104926 00:00:01
As can be seen, both solutions actually display 00:00:00 for 2 seconds.
The code below instead produces the correct output:
-1.899441 -00:00:02
-1.499838 -00:00:02
-1.095019 -00:00:02
-0.994941 -00:00:01
-0.899903 -00:00:01
-0.195743 -00:00:01
-0.097564 -00:00:01
0.001758 00:00:00
0.100495 00:00:00
0.503691 00:00:00
0.904986 00:00:00
1.004998 00:00:01
1.103652 00:00:01
2.004936 00:00:02
It's actually a category I wrote on NSNumber but the principle should also be applicable to any floating point number:
- (NSString *)ut_hmsString {
NSString *sign = (self.floatValue < 0.0f) ? #"-" : #" ";
float corr = (self.floatValue < 0.0f) ? 1.0000001f : 0;
int seconds = fmodf(fabsf(floorf(self.floatValue)), 60.0f);
int fakesec = fabsf(self.floatValue - corr);
int minutes = fakesec / 60 % 60;
int hours = fakesec / 3600;
return [NSString stringWithFormat:#"%#%02i:%02i:%02i", sign, hours, minutes, seconds];
}

Converting MPH to minute miles

I'm attempting to convert MPH into minute miles. I'm currently running code to do this by doing 60 / the miles per hour which gives me the result in minute miles.
For example 60/8mph = 7.5
However the answer I get I need to convert into minutes and seconds so that I would have 7 minutes 30 seconds. Is there a way I can get the numbers after the decimal point so I can multiply it by 60 to convert it to seconds, then add it back to the minutes.
You can use remainder,
double remainder = fmod(a_double, another_double);
should include <math.h>
Well, I don't know whether there is an existing class that handles this, but to answer your specific question, the fractional part of the decimal (mantissa?) would be:
((60 % 8) / 8.0f)
You can multiply that by 60.
Do it in seconds...
3600/8 = 450
450/60 = 7 remainder 30
= 7:30
It's pretty simple, you're on the right path actually.
What you need to do is:
Get Minutes
Get Seconds
Convert seconds from int to real time (0.5 to 30, etc..)
Add seconds to minutes
Get minutes by casting it to an Integer:
int minutes = 60/8;
Get seconds by using the remainder:
float seconds = 60%8;
Convert seconds to real time:
int realSeconds = seconds * 60;
Now get result back by adding both:
int totalSeconds = minuts + realSeconds;
Here's a little function that does it (typed directly to browser, probably won't compile)
#include <math.h>
int getMinuteMiles(float mph){
int minutes = 60/mph;
double seconds = fmod(60, mph);
int realSeconds = seconds * 60;
return minutes+realSeconds;
}

Where is the bug in these length-of-daylight/night approximations?

I am trying to make an approximation of the length of day from sunrise to sunset, and the length of night from sunset to sunrise. My present approximation is crude (it assumes yesterday and tomorrow have equivalent values to today), but for now I am not specifically concerned with pinpointing yesterday sunset, today sunrise, today sunset, and tomorrow sunrise (yet). My goal is a calculation based on twelve equal hours per night (twelve equal to each other, not equal to a standard hour or daytime hour), and twelve equal hours per day.
What I am concerned with is that in my iOS app, the calculation is way off; a minute flies by in 5-6 (standard) seconds' time. When I use unmodified time, in other code from here, the clock moves at a standard pace, but when I try to get this code to feed the clock code, something is out of bounds.
The code I've been working on, as an approximation, is:
NSDate *now = [[NSDate alloc] init];
NSDate *factory = [[NSDate alloc] init];
NSDate *summerSolstice2013 = [factory initWithTimeIntervalSinceReferenceDate:_referenceSummerSolstice];
double distanceAlong = [now timeIntervalSinceDate:summerSolstice2013];
double angleAlong = M_PI * 2 * distanceAlong / (2 * (_referenceWinterSolstice - _referenceSummerSolstice));
double currentHeight = cos(angleAlong) * _latitudeAngle + _tiltAngle;
...
if (_secondsAreNatural)
{
_secondsAreShadowed = FALSE;
double dayDuration = 12 * 60 * 60 + 12 * 60 * 60 * sin(currentHeight);
double midday = fmod(24 * 60 * 60 * _longitudeAngle / (2 * M_PI) + 12 * 60 * 60, 24 * 60 * 60);
double sunrise = midday - dayDuration / 2;
double sunset = midday + dayDuration / 2;
double seconds = fmod([now timeIntervalSinceReferenceDate], 24 * 60 * 60);
double proportionAlong = 0;
if (seconds < sunrise)
{
_naturalSeconds = (seconds - sunset - 24 * 60 * 60) / (sunrise - sunset - 24 * 60 * 60);
}
else if (seconds > sunset)
{
_naturalSeconds = 12 * 60 * 60 * (seconds - sunset) / (sunrise + 24 * 60 * 60 - sunset) + 18 * 60 * 60;
}
else
{
_naturalSeconds = 12 * 60 * 60 * (seconds - sunrise) / (sunset - sunrise) + 6 * 60 * 60;
}
}
Are there any problems (given that this approximation can probably be refined to any extent) you can pinpoint in this code?
Thanks,
--EDIT--
The code I wrote above was fairly demanding in terms of the loose ends presented to someone reading it. I tried to take another pass, and rewrite it in simpler terms and with a purer mathematical model. I wrote, comments added:
NSDate *now = [[NSDate alloc] init];
NSDate *summerSolstice2013 = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:_referenceSummerSolstice];
double distanceAlong = [now timeIntervalSinceDate:summerSolstice2013];
// How far along are we, in seconds, since the reference date?
double angleAlong = M_PI * 2 * distanceAlong / (2 * (_referenceWinterSolstice - _referenceSummerSolstice));
// What's the angle if 2 π radians corresponds to a whole year?
double currentHeight = cos(angleAlong) * _latitudeAngle + _tiltAngle;
// _latitudeAngle is the angle represented by our latitude; _tiltAngle is the angle of the earth's tilt.
NSInteger day = 24 * 60 * 60;
// 'day' could have been called secondsInADay, but it was mean to reduce the number of multiplicands represented in the code.
// If we are in the endless day or endless night around the poles, leave the user with standard clock hours.
if (currentHeight > M_PI / 2)
{
_secondsAreShadowed = TRUE;
}
else if (currentHeight < - M_PI / 2)
{
_secondsAreShadowed = TRUE;
}
// Otherwise, calculate the time this routine is meant to calculate. (This is the main intended use case.)
else if (_secondsAreNatural)
{
_secondsAreShadowed = FALSE;
// closestDay is intended to be the nearest midnight (or, in another hemisphere, midday), not exactly in hours offset from UTC, but in longitude offset from Greenwich.
double closestDay;
if (fmod(distanceAlong, day) < .5 * day)
{
closestDay = distanceAlong - fmod(distanceAlong, day);
}
else
{
closestDay = day + distanceAlong - fmod(distanceAlong, day);
}
// As we go through the calculations, for the most part we keep up information on the previous and next days, which will to some degree be consulted at the end.
double previousDay = closestDay - day;
double nextDay = closestDay + day;
// For the three days, what proportion of the way along are they from the solstices?
double closestDayAngleAlong = M_PI * 2 * closestDay / (2 * (_referenceWinterSolstice - _referenceSummerSolstice));
double previousDayAngleAlong = M_PI * 2 * previousDay / (2 * (_referenceWinterSolstice - _referenceSummerSolstice));
double nextDayAngleAlong = M_PI * 2 * nextDay / (2 * (_referenceSummerSolstice - _referenceSummerSolstice));
// What angle are we placed by on the year's cycle, between _latitudeAngle + _tiltAngle and -latitudeAngle + _tiltAngle?
double closestDayHeight = cos(closestDayAngleAlong) * _latitudeAngle + _tiltAngle;
double previousDayHeight = cos(previousDayAngleAlong) * _latitudeAngle + _tiltAngle;
double nextDayHeight = cos(nextDayAngleAlong) * _latitudeAngle + _tiltAngle;
// Based on that, what are the daylight durations for the three twenty-four hour days?
double closestDayDuration = day / 2 + (day / 2) * sin(closestDayHeight);
double previousDayDuration = day / 2 + (day / 2) * sin(previousDayHeight);
double nextDayDuration = day / 2 + (day / 2) * sin(nextDayHeight);
// Here we use both morning and evening for the closest day, and the previous day's morning and the next day's evening.
double closestDayMorning = closestDay + (day / 2) - (closestDayDuration / 2);
double closestDayEvening = closestDay + (day / 2) + (closestDayDuration / 2);
double previousDayEvening = previousDay + (day / 2) + (previousDayDuration / 2);
double nextDayMorning = nextDay + (day / 2) + (nextDayDuration / 2);
// We calculate the proportion along the day that we are between evening and morning (or morning and evening), along with the sooner endpoint of that interval.
double proportion;
double referenceTime;
if (distanceAlong < closestDayMorning)
{
proportion = (distanceAlong - previousDayEvening) / (closestDayMorning - previousDayEvening);
referenceTime = previousDay + day * 3 / 4;
}
else if (distanceAlong > closestDayEvening)
{
proportion = (distanceAlong - closestDayEvening) / (nextDayMorning - closestDayEvening);
referenceTime = closestDay + day * 3 / 4;
}
else
{
proportion = (distanceAlong - closestDayMorning) / (closestDayEvening - closestDayMorning);
referenceTime = closestDay + day * 1 / 4;
}
// Lastly, we take both that endpoint and the proportion of it, and we get the number of seconds according to the daylight / nighttime calculation intended.
_naturalSeconds = referenceTime + proportion * day / 2;
I was hoping to make the code clearer and easier to grasp, and I think I did that, but it is displaying similar behavior to my previous attempt: the clock hands spin by at about ten times natural time when they should be within a factor of .8 to 1.2 of standard hours/minutes/seconds.
Any advice? Has my edited code been any clearer either about what is intended or what is wrong?
Thanks,
Your code is hard to follow, but I'll try to get you some tips:
There are existing libraries out there that compute solar angle/azimuth and sunrise/sunset for a given date. Use google as a help, here's some relevant resources: http://www.esrl.noaa.gov/gmd/grad/solcalc/ If you don't find any useful source code, I could post some.
Do not use double to calculate with dates and times. That's confusing and results in errors. Use a data type that is intended to store dates.
For your code, you say that the time is running to fast. Since referenceTime and day in the last line are constant (at least for half a day), the error must be in proportion. I think you're mixing to many cases there. The interpolation should go from the start of the range to the end, so in the case
proportion = (distanceAlong - previousDayEvening) / (closestDayMorning - previousDayEvening);
referenceTime = previousDay + day * 3 / 4;
proportion should run from (previousDay + day * 3 / 4) to (closestDay + day * 3 / 4), or, described differently, from the dusk to dawn of closestDay. But it's completely unclear how this interpolation should work.
Try to draw a diagram of the different cases (I believe there should only be two, one for day and one for night) and the corresponding interpolation.
But: What are you trying to achieve after all? The resulting time is just a forward running time, it is actually independent of latitude or longitude or time of day. So to make the time run, you don't need to know where the sun is.

Resources