/* time, imposing no runtime or code overhead. */
sidtim0 = astro_revolution((180.0 + 356.0470 + 282.9404) + (0.9856002585 + 4.70935E-5) * d);
return sidtim0;
-}
+}
/* This function computes the Sun's position at any instant */
/**
* Note: timestamp = unixtimestamp (NEEDS to be 00:00:00 UT)
- * 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 compute
- * 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.
- *
+ * 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 compute
+ * 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 timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit)
{
timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d)
{
timelib_sll dow, day;
-
+
/* Figure out the dayofweek for y-1-1 */
dow = timelib_day_of_week(y, 1, 1);
/* then use that to figure out the offset for day 1 of week 1 */
if (strcasecmp("utc", word) == 0 || strcasecmp("gmt", word) == 0) {
return timelib_timezone_utc;
}
-
+
for (tp = timelib_timezone_lookup; tp->name; tp++) {
if (strcasecmp(word, tp->name) == 0) {
if (!first_found) {
{
uchar *cursor = s->cur;
char *str, *ptr = NULL;
-
+
std:
s->tok = cursor;
s->len = 0;
TIMELIB_INIT;
TIMELIB_HAVE_DATE();
TIMELIB_HAVE_RELATIVE();
-
+
s->time->y = timelib_get_nr((char **) &ptr, 4);
w = timelib_get_nr((char **) &ptr, 2);
d = timelib_get_nr((char **) &ptr, 1);
TIMELIB_INIT;
TIMELIB_HAVE_DATE();
TIMELIB_HAVE_RELATIVE();
-
+
s->time->y = timelib_get_nr((char **) &ptr, 4);
w = timelib_get_nr((char **) &ptr, 2);
d = 1;
if (s->time->relative.weekday_behavior != 2) {
s->time->relative.weekday_behavior = 1;
}
-
+
TIMELIB_DEINIT;
return TIMELIB_WEEKDAY;
}
add_pbf_error(s, "A textual day could not be found", string, begin);
break;
} else {
- in.time->have_relative = 1;
+ in.time->have_relative = 1;
in.time->relative.have_weekday_relative = 1;
in.time->relative.weekday = tmprel->multiplier;
in.time->relative.weekday_behavior = 1;
/* do funky checking whether the parsed time was valid time */
if (s->time->h != TIMELIB_UNSET && s->time->i != TIMELIB_UNSET &&
- s->time->s != TIMELIB_UNSET &&
+ s->time->s != TIMELIB_UNSET &&
!timelib_valid_time( s->time->h, s->time->i, s->time->s)) {
add_pbf_warning(s, "The parsed time was invalid", string, ptr);
}
/* do funky checking whether the parsed date was valid date */
if (s->time->y != TIMELIB_UNSET && s->time->m != TIMELIB_UNSET &&
- s->time->d != TIMELIB_UNSET &&
+ s->time->d != TIMELIB_UNSET &&
!timelib_valid_date( s->time->y, s->time->m, s->time->d)) {
add_pbf_warning(s, "The parsed date was invalid", string, ptr);
}
printf ("%04d-%02d-%02d %02d:%02d:%02d.%-5d %+04d %1d",
time.y, time.m, time.d, time.h, time.i, time.s, time.f, time.z, time.dst);
if (time.have_relative) {
- printf ("%3dY %3dM %3dD / %3dH %3dM %3dS",
+ printf ("%3dY %3dM %3dD / %3dH %3dM %3dS",
time.relative.y, time.relative.m, time.relative.d, time.relative.h, time.relative.i, time.relative.s);
}
if (time.have_weekday_relative) {
if (time.have_weeknr_day) {
printf(" / %dW%d", time.relative.weeknr_day.weeknr, time.relative.weeknr_day.dayofweek);
}
- return 0;
+ return 0;
}
#endif
{
uchar *cursor = s->cur;
char *str, *ptr = NULL;
-
+
std:
s->tok = cursor;
s->len = 0;
case 'D': s->period->d = nr; break;
case 'H': s->period->h = nr; break;
case 'S': s->period->s = nr; break;
- case 'M':
+ case 'M':
if (in_time) {
s->period->i = nr;
} else {
- s->period->m = nr;
+ s->period->m = nr;
}
break;
default:
/*!max:re2c */
-void timelib_strtointerval(char *s, int len,
- timelib_time **begin, timelib_time **end,
- timelib_rel_time **period, int *recurrences,
+void timelib_strtointerval(char *s, int len,
+ timelib_time **begin, timelib_time **end,
+ timelib_rel_time **period, int *recurrences,
struct timelib_error_container **errors)
{
Scanner in;
#if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__))
# if defined(__LITTLE_ENDIAN__)
# undef WORDS_BIGENDIAN
-# else
+# else
# if defined(__BIG_ENDIAN__)
# define WORDS_BIGENDIAN
# endif
/* read ID */
version = (*tzf)[3] - '0';
*tzf += 4;
-
+
/* read BC flag */
tz->bc = (**tzf == '\1');
*tzf += 1;
memcpy(cbuffer, *tzf, sizeof(unsigned char) * tz->timecnt);
*tzf += sizeof(unsigned char) * tz->timecnt;
}
-
+
tz->trans = buffer;
tz->trans_idx = cbuffer;
}
cur_locale = strdup(tmp);
}
setlocale(LC_CTYPE, "C");
-#endif
+#endif
do {
int mid = ((unsigned)left + right) >> 1;
#ifdef HAVE_SETLOCALE
setlocale(LC_CTYPE, cur_locale);
if (cur_locale) free(cur_locale);
-#endif
+#endif
return 1;
}
#ifdef HAVE_SETLOCALE
setlocale(LC_CTYPE, cur_locale);
if (cur_locale) free(cur_locale);
-#endif
+#endif
return 0;
}
{
ttinfo *to;
timelib_sll dummy;
-
+
if ((to = fetch_timezone_offset(tz, ts, &dummy))) {
return to->isdst;
}
{
timelib_time_offset *gmt_offset;
timelib_sll retval;
-
+
switch (t->zone_type) {
case TIMELIB_ZONETYPE_ABBR:
case TIMELIB_ZONETYPE_OFFSET:
return (t->z + t->dst) * -60;
-
+
case TIMELIB_ZONETYPE_ID:
gmt_offset = timelib_get_time_zone_info(t->sse, t->tz_info);
retval = gmt_offset->offset;
tmp->timecnt = tz->timecnt;
tmp->typecnt = tz->typecnt;
tmp->charcnt = tz->charcnt;
-
+
tmp->trans = (int32_t *) malloc(tz->timecnt * sizeof(int32_t));
tmp->trans_idx = (unsigned char*) malloc(tz->timecnt * sizeof(unsigned char));
memcpy(tmp->trans, tz->trans, tz->timecnt * sizeof(int32_t));
if ((options & 1) == 1) {
if (d->have_relative) {
- printf("%3lldY %3lldM %3lldD / %3lldH %3lldM %3lldS",
+ printf("%3lldY %3lldM %3lldD / %3lldH %3lldM %3lldS",
d->relative.y, d->relative.m, d->relative.d, d->relative.h, d->relative.i, d->relative.s);
if (d->relative.first_last_day_of != 0) {
switch (d->relative.first_last_day_of) {
void timelib_dump_rel_time(timelib_rel_time *d)
{
- printf("%3lldY %3lldM %3lldD / %3lldH %3lldM %3lldS (days: %lld)%s",
+ printf("%3lldY %3lldM %3lldD / %3lldH %3lldM %3lldS (days: %lld)%s",
d->y, d->m, d->d, d->h, d->i, d->s, d->days, d->invert ? " inverted" : "");
if (d->first_last_day_of != 0) {
switch (d->first_last_day_of) {
/* From parse_iso_intervals.re */
void timelib_strtointerval(char *s, int len,
- timelib_time **begin, timelib_time **end,
- timelib_rel_time **period, int *recurrences,
+ timelib_time **begin, timelib_time **end,
+ timelib_rel_time **period, int *recurrences,
struct timelib_error_container **errors);
timelib_sll days_this_month;
timelib_sll last_month, last_year;
timelib_sll days_last_month;
-
+
/* can jump an entire leap year period quickly */
if (*d >= DAYS_PER_LYEAR_PERIOD || *d <= -DAYS_PER_LYEAR_PERIOD) {
*y += YEARS_PER_LYEAR_PERIOD * (*d / DAYS_PER_LYEAR_PERIOD);
timelib_time_offset *before, *after;
timelib_sll tmp;
int in_transistion;
-
+
tz->is_localtime = 1;
before = timelib_get_time_zone_info(tz->sse, tzi);
after = timelib_get_time_zone_info(tz->sse - before->offset, tzi);
((tz->sse - after->offset) >= (after->transistion_time + (before->offset - after->offset))) &&
((tz->sse - after->offset) < after->transistion_time)
);
-
+
if ((before->offset != after->offset) && !in_transistion) {
tmp = -after->offset;
} else {
printf ("%04d-%02d-%02d %02d:%02d:%02d.%-5d %+04d %1d",
time.y, time.m, time.d, time.h, time.i, time.s, time.f, time.z, time.dst);
if (time.have_relative) {
- printf ("%3dY %3dM %3dD / %3dH %3dM %3dS",
+ printf ("%3dY %3dM %3dD / %3dH %3dM %3dS",
time.relative.y, time.relative.m, time.relative.d, time.relative.h, time.relative.i, time.relative.s);
}
if (time.have_weekday_relative) {
signed int dst = tm->dst;
sse = tm->sse;
-
+
switch (tm->zone_type) {
case TIMELIB_ZONETYPE_ABBR:
case TIMELIB_ZONETYPE_OFFSET: {
case TIMELIB_ZONETYPE_ID: {
timelib_time_offset *gmt_offset;
-
+
gmt_offset = timelib_get_time_zone_info(tm->sse, tm->tz_info);
timelib_unixtime2gmt(tm, tm->sse + gmt_offset->offset);
timelib_time_offset_dtor(gmt_offset);
-
+
goto cleanup;
}
case TIMELIB_ZONETYPE_OFFSET: {
int z = tm->z;
signed int dst = tm->dst;
-
+
timelib_unixtime2gmt(tm, ts - (tm->z * 60) + (tm->dst * 3600));
tm->z = z;
timelib_unixtime2gmt(tm, ts + gmt_offset->offset);
/* we need to reset the sse here as unixtime2gmt modifies it */
- tm->sse = ts;
+ tm->sse = ts;
tm->dst = gmt_offset->is_dst;
tm->z = gmt_offset->offset;
tm->tz_info = tz;