It looks like you are using a library from a Code Project article (
C# Class for Calculating Sunrise and Sunset Times[
^]). There seems to be a bug or two in the code an the author is no longer updating the code. However, I believe the fix will be to remove the following lines from the author's code:
if ((Sign(zone) == Sign(lon)) && (zone != 0))
{
Debug.Print("WARNING: time zone and longitude are incompatible!");
return false;
}
This is an error check that doesn't seem to really work. The only issue is that now you will not be checking for valid coordinates, but since the check didn't work in the first place, that shouldn't be an issue.
The reason why you were returning the same value is because this error check fails the method. Since your sunrise and sunset variables are passed in as
ref
objects, they retain the values they were initially set with (which was the time when the application was run).
If you find that the values aren't fully accurate, you might want to check in the comments of that article. There is a comment set by Rafone called "Nice one but question" where, after a couple responses, he posts code he modified to get better results. That might be something to look into.