Julian operator+(Julian const & j, detail::packaged_year y) { year_t year = j.year() + static_cast<year_t>(y.nYears_); return Julian( year, j.month(), j.month() == 2 && j.day() == 29 && !is_julian_leapyear(year) ? 28 : j.day(), j.hour(), j.minute(), j.second()); }
Julian operator-(Julian const & j, detail::packaged_month m) { year_t year = j.year() - m.nMonths_ / 12; month_t month = j.month() - m.nMonths_ % 12; double adjust = (month - 1) / 12 + (month - 12) / 12; year += static_cast<year_t>(adjust); month -= static_cast<month_t>(adjust * 12); day_t day = j.day() < julian_days_in_month(month, is_julian_leapyear(year)) ? j.day() : julian_days_in_month(month, is_julian_leapyear(year)); return Julian(year, month, day, j.hour(), j.minute(), j.second()); }
int GetAccessDate(char const *file) { struct stat statbuf; struct tm *t1; if (stat(file, &statbuf)) return -1; t1 = localtime(&(statbuf.st_atime)); if (t1->tm_year + 1900 < BASE) return 0; else return Julian(t1->tm_year+1900, t1->tm_mon, t1->tm_mday); }
void Statement::GetDataInRow(unsigned int column, Nullable<Julian> &result) { if (column >= _resultParams.size()) { throw DatabaseException("Error in Statement::GetDataInRow", 0, "----", "column out of range"); } if ((_resultBind[column].buffer_type != MYSQL_TYPE_TIMESTAMP) && (_resultBind[column].buffer_type != MYSQL_TYPE_DATE) && (_resultBind[column].buffer_type != MYSQL_TYPE_TIME) && (_resultBind[column].buffer_type != MYSQL_TYPE_DATETIME)) { throw DatabaseException("Error in Statement::GetDataInRow", 0, "----", "column not of correct type"); } MYSQL_TIME time; if (! (*(_resultParams[column]->IsNull()))) { time = *((MYSQL_TIME *) _resultParams[column]->Buffer()); GregorianBreakdown gb(time, 0); result = Julian(gb); } else { result.ClearValue(); } }
void ProduceCalendar(void) { int y, m, d; if (UseUTF8Chars) { linestruct = &UTF8Drawing; } else if (UseVTChars) { linestruct = &VT100Drawing; } else { linestruct = &NormalDrawing; } ShouldCache = 1; ColSpaces = (CalWidth - 9) / 7; CalWidth = 7*ColSpaces + 8; if (CalMonths) { FromJulian(JulianToday, &y, &m, &d); JulianToday = Julian(y, m, 1); while (CalMonths--) DoCalendarOneMonth(); return; } else { if (MondayFirst) JulianToday -= (JulianToday%7); else JulianToday -= ((JulianToday+1)%7); if (!DoSimpleCalendar) { WriteWeekHeaderLine(); WriteCalDays(); WriteIntermediateCalLine(); } while (CalWeeks--) DoCalendarOneWeek(CalWeeks); return; } }
void HuntPhase(int startdate, int starttim, int phas, int *date, int *time) { int utcd, utct; int y, m, d; int h, min, s; int d1, t1; double k1, k2, jd, jdorig; double nt1, nt2; /* Convert from local to UTC */ LocalToUTC(startdate, starttim, &utcd, &utct); /* Convert from Remind representation to year/mon/day */ FromJulian(utcd, &y, &m, &d); /* Convert to a true Julian date -- sorry for the name clashes! */ jdorig = jtime(y, m, d, (utct / 60), (utct % 60), 0); jd = jdorig - 45.0; nt1 = meanphase(jd, 0.0, &k1); while(1) { jd += synmonth; nt2 = meanphase(jd, 0.0, &k2); if (nt1 <= jdorig && nt2 > jdorig) break; nt1 = nt2; k1 = k2; } jd = truephase(k1, phas/4.0); if (jd < jdorig) jd = truephase(k2, phas/4.0); /* Convert back to Remind format */ jyear(jd, &y, &m, &d); jhms(jd, &h, &min, &s); d1 = Julian(y, m, d); t1 = h*60 + min; UTCToLocal(d1, t1, date, time); }
static int NextSimpleTrig(int startdate, Trigger *trig, int *err) { int typ = 0; int d, m, y, j, d2, m2, y2; *err = 0; FromJulian(startdate, &y, &m, &d); d2 = d; m2 = m; y2 = y; if (trig->d != NO_DAY) typ |= GOT_DAY; if (trig->m != NO_MON) typ |= GOT_MON; if (trig->y != NO_YR) typ |= GOT_YR; if (trig->wd != NO_WD) typ |= GOT_WD; switch(typ) { case 0: case GOT_WD: if (trig->wd != NO_WD) while(! (trig->wd & (1 << (startdate%7)))) startdate++; return startdate; case GOT_DAY: if (d > trig->d) { m++; if (m == 12) { m = 0; y++; } } while (trig->d > DaysInMonth(m, trig->y)) m++; j = Julian(y, m, trig->d); return j; case GOT_MON: if (m == trig->m) return startdate; else if (m > trig->m) return Julian(y+1, trig->m, 1); else return Julian(y, trig->m, 1); case GOT_YR: if (y == trig->y) return startdate; else if (y < trig->y) return Julian(trig->y, 0, 1); else return -1; case GOT_DAY+GOT_MON: if (m > trig->m || (m == trig->m && d > trig->d)) y++; if (trig->d > MonthDays[trig->m]) { *err = E_BAD_DATE; return -1; } /* Take care of Feb. 29 */ while (trig->d > DaysInMonth(trig->m, y)) y++; return Julian(y, trig->m, trig->d); case GOT_DAY+GOT_YR: if (y < trig->y) return Julian(trig->y, 0, trig->d); else if (y > trig->y) return -1; if (d > trig->d) { m++; if (m == 12) return -1; } while (trig->d > DaysInMonth(m, trig->y)) m++; return Julian(trig->y, m, trig->d); case GOT_MON+GOT_YR: if (y > trig->y || (y == trig->y && m > trig->m)) return -1; if (y < trig->y) return Julian(trig->y, trig->m, 1); if (m == trig->m) return startdate; return Julian(trig->y, trig->m, 1); case GOT_DAY+GOT_MON+GOT_YR: if (trig->d > DaysInMonth(trig->m, trig->y)) { *err = E_BAD_DATE; return -1; } return Julian(trig->y, trig->m, trig->d); case GOT_YR+GOT_WD: if (y > trig->y) return -1; if (y < trig->y) j = Julian(trig->y, 0, 1); else j = startdate; while(! (trig->wd & (1 << (j%7)))) j++; if (JYear(j) > trig->y) return -1; return j; case GOT_MON+GOT_WD: if (m == trig->m) { j = startdate; while(! (trig->wd & (1 << (j%7)))) j++; if (JMonth(j) == trig->m) return j; } if (m >= trig->m) j = Julian(y+1, trig->m, 1); else j = Julian(y, trig->m, 1); while(! (trig->wd & (1 << (j%7)))) j++; return j; /* Guaranteed to be within the month */ case GOT_DAY+GOT_WD: if (m !=0 || y > BASE) { m2 = m-1; if (m2 < 0) { y2 = y-1; m2 = 11; } /* If there are fewer days in previous month, no match */ if (trig->d <= DaysInMonth(m2, y2)) { j = Julian(y2, m2, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; if (j >= startdate) return j; } } /* Try this month */ if (trig->d <= DaysInMonth(m, y)) { j = Julian(y, m, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; if (j >= startdate) return j; } /* Argh! Try next avail. month */ m2 = m+1; if (m2 > 11) { m2 = 0; y++; } while (trig->d > DaysInMonth(m2, y)) m2++; j = Julian(y, m2, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; return j; case GOT_WD+GOT_YR+GOT_DAY: if (y > trig->y+1 || (y > trig->y && m>0)) return -1; if (y > trig->y) { j = Julian(trig->y, 11, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; if (j >= startdate) return j; } else if (y < trig->y) { j = Julian(trig->y, 0, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; return j; } else { /* Try last month */ if (m > 0) { m2 = m-1; while (trig->d > DaysInMonth(m2, trig->y)) m2--; j = Julian(trig->y, m2, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; if (j >= startdate) return j; } } /* Try this month */ if (trig->d <= DaysInMonth(m, trig->y)) { j = Julian(trig->y, m, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; if (j >= startdate) return j; } /* Must be next month */ if (m == 11) return -1; m++; while (trig->d > DaysInMonth(m, trig->d)) m++; j = Julian(trig->y, m, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; return j; case GOT_DAY+GOT_MON+GOT_WD: if (trig->d > MonthDays[trig->m]) { *err = E_BAD_DATE; return -1; } /* Back up a year in case we'll cross a year boundary*/ if (y > BASE) { y--; } /* Move up to the first valid year */ while (trig->d > DaysInMonth(trig->m, y)) y++; /* Try last year */ j = Julian(y, trig->m, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; if (j >= startdate) return j; /* Try this year */ y++; j = Julian(y, trig->m, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; if (j >= startdate) return j; /* Must be next year */ y++; while (trig->d > DaysInMonth(trig->m, y)) y++; j = Julian(y, trig->m, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; return j; case GOT_WD+GOT_MON+GOT_YR: if (y > trig->y || (y == trig->y && m > trig->m)) return -1; if (trig->y > y || (trig->y == y && trig->m > m)) { j = Julian(trig->y, trig->m, 1); while(! (trig->wd & (1 << (j%7)))) j++; return j; } else { j = startdate; while(! (trig->wd & (1 << (j%7)))) j++; FromJulian(j, &y2, &m2, &d2); if (m2 == trig->m) return j; else return -1; } case GOT_WD+GOT_DAY+GOT_MON+GOT_YR: if (trig->d > DaysInMonth(trig->m, trig->y)) { *err = E_BAD_DATE; return -1; } j = Julian(trig->y, trig->m, trig->d); while(! (trig->wd & (1 << (j%7)))) j++; return j; default: Eprint("NextSimpleTrig %s %d", ErrMsg[E_SWERR], typ); *err = E_SWERR; return -1; } }