MCPcopy Create free account
hub / github.com/CruiserOne/Astrolog / AddTime

Function AddTime

general.cpp:802–881  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

800// check for overflows, e.g. Dec 30 + 3 days = Jan 2 of next year.
801
802void AddTime(CI *pci, int mode, int toadd)
803{
804 int d, h;
805 real m;
806
807 if (mode < 1 || mode == iAnimNow)
808 mode = iAnimDay;
809
810 h = (int)RFloor(pci->tim);
811 m = RFract(pci->tim)*60.0;
812 if (m < 60.0 && m + 1.0/rLarge >= 60.0) // Avoid roundoff error.
813 m = 60.0;
814 if (mode == 13)
815 m += 1.0/60000.0*(real)toadd; // Add milliseconds.
816 else if (mode == 12)
817 m += 1.0/6000.0*(real)toadd; // Add 1/100th seconds.
818 else if (mode == 11)
819 m += 1.0/600.0*(real)toadd; // Add 1/10th seconds.
820 else if (mode == 1)
821 m += 1.0/60.0*(real)toadd; // Add seconds.
822 else if (mode == 2)
823 m += (real)toadd; // Add minutes.
824
825 // Add hours, either naturally or if minute value overflowed.
826
827 if (m >= 60.0 || m < 0.0 || mode == 3) {
828 if (m >= 60.0) {
829 m -= 60.0; toadd = NSgn2(toadd);
830 } else if (m < 0.0) {
831 m += 60.0; toadd = -NSgn2(-toadd);
832 }
833 h += toadd;
834 }
835
836 // Add days, either naturally or if hour value overflowed.
837
838 if (h >= 24 || h < 0 || mode == 4) {
839 if (h >= 24) {
840 h -= 24; toadd = NSgn2(toadd);
841 } else if (h < 0) {
842 h += 24; toadd = -NSgn2(-toadd);
843 }
844 pci->day = AddDay(pci->mon, pci->day, pci->yea, toadd);
845 }
846
847 // Add months, either naturally or if day value overflowed.
848
849 d = DayInMonth(pci->mon, pci->yea);
850 if (pci->day > d || pci->day < 1 || mode == 5) {
851 if (pci->day > d) {
852 pci->day -= d; toadd = NSgn2(toadd);
853 } else if (pci->day < 1) {
854 pci->day += DayInMonth(Mod12(pci->mon - 1), pci->yea);
855 toadd = -NSgn2(-toadd);
856 }
857 pci->mon += toadd;
858 }
859

Callers 5

FProcessSwitchesFunction · 0.85
GetJPLHorizonsFunction · 0.85
AnimateFunction · 0.85
ChartExoplanetFunction · 0.85
XChartRisingFunction · 0.85

Calls 3

AddDayFunction · 0.85
DayInMonthFunction · 0.85
Mod12Function · 0.85

Tested by

no test coverage detected