From 3b99622e226ae176a6adf43babc7ce8d7b06b867 Mon Sep 17 00:00:00 2001 From: Bruce Allen Date: Tue, 8 Feb 2005 07:07:19 +0000 Subject: [PATCH] Well, the comment was worth keeping... svn path=/trunk/boinc/; revision=5358 --- sched/sched_send.C | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/sched/sched_send.C b/sched/sched_send.C index 4af81bb9dd..ffbf9f8f3c 100644 --- a/sched/sched_send.C +++ b/sched/sched_send.C @@ -263,36 +263,32 @@ typedef struct urltag { } URLTYPE; +// these global variables are needed to pass information into the +// compare function below. +// +static int tzone=0; +static int hostid=0; + // Evaluate differences between time-zone. Two time zones that differ // by almost 24 hours are actually very close on the surface of the // earth. This function finds the 'shortest way around' // -static int mod_24_hours(int x) { - const int twelve_hours=12*3600; - - if (x < -twelve_hours) - x += 2*twelve_hours; - else if (x > twelve_hours) - x -= 2*twelve_hours; - - return x; -} - -// these global variables are needed to pass information into the -// compare function below. -static int tzone=0; -static int hostid=0; - static int compare(const void *x, const void *y) { URLTYPE *a=(URLTYPE *)x; URLTYPE *b=(URLTYPE *)y; char longname[512]; - int diffa = mod_24_hours(tzone - (a->zone)); - int diffb = mod_24_hours(tzone - (b->zone)); + + const int twelve_hours = 12*3600; - diffa = abs(diffa); - diffb = abs(diffb); + int diffa = abs(tzone - (a->zone)); + int diffb = abs(tzone - (b->zone)); + + if (diffa > twelve_hours) + diffa = 2*twelve_hours-diffa; + + if (diffb > twelve_hours) + diffb = 2*twelve_hours-diffb; if (diffa < diffb) { return -1;