Skip to content
Snippets Groups Projects
Commit 45ab4cec authored by Mirar (Pontus Hagland)'s avatar Mirar (Pontus Hagland)
Browse files

more then one day in a fixed date fix

Rev: lib/modules/Calendar.pmod/Event.pmod:1.2
parent e3894233
No related branches found
No related tags found
No related merge requests found
...@@ -155,18 +155,21 @@ class Day_Event ...@@ -155,18 +155,21 @@ class Day_Event
// find // find
TimeRange next(TimeRange from,void|int(0..1) including) TimeRange next(TimeRange from,void|int(0..1) including)
{ {
int jd=(int)(from->julian_day())+!including; int jd;
jd=scan_jd(from->calendar(),jd,1); if (including) jd=(int)(from->julian_day());
if (jd==NODAY) return 0; else jd=(int)(from->end()->julian_day());
jd=scan_jd(from->calendar(),jd-nd+1,1);
return (from->calendar()->Day)("julian_r",jd,from->ruleset())*nd; return (from->calendar()->Day)("julian_r",jd,from->ruleset())*nd;
} }
TimeRange previous(TimeRange from,void|int(0..1) including) TimeRange previous(TimeRange from,void|int(0..1) including)
{ {
float|int jd=from->julian_day(); int jd;
if (floatp(jd)) jd=(int)ceil(jd); if (including) jd=(int)(from->end()->julian_day());
if (!including) jd--; else jd=(floatp(from->julian_day())
jd=scan_jd(from->calendar(),jd,-1); ?(int)floor(from->julian_day())
:(from->julian_day()-1));
jd=scan_jd(from->calendar(),jd+nd-1,-1);
if (jd==NODAY) return 0; if (jd==NODAY) return 0;
return (from->calendar()->Day)("julian_r",jd,from->ruleset())*nd; return (from->calendar()->Day)("julian_r",jd,from->ruleset())*nd;
} }
...@@ -446,8 +449,7 @@ class Gregorian_Fixed ...@@ -446,8 +449,7 @@ class Gregorian_Fixed
mn=_mn; mn=_mn;
yd=M_YD[mn]+md; yd=M_YD[mn]+md;
// if (sizeof(_n)) nd=_n[0]; if (sizeof(_n)) nd=_n[0];
nd=1;
} }
int scan_jd(Calendar realm,int jd,int(-1..1) direction) int scan_jd(Calendar realm,int jd,int(-1..1) direction)
...@@ -455,6 +457,8 @@ class Gregorian_Fixed ...@@ -455,6 +457,8 @@ class Gregorian_Fixed
[int y,int yjd,int leap]=gregorian_yjd(jd); [int y,int yjd,int leap]=gregorian_yjd(jd);
int njd; int njd;
for (;;)
{
if (leap && yd>59) if (leap && yd>59)
njd=yjd+yd; njd=yjd+yd;
else else
...@@ -463,10 +467,14 @@ class Gregorian_Fixed ...@@ -463,10 +467,14 @@ class Gregorian_Fixed
if (direction==1) if (direction==1)
{ {
if (njd>=jd) return njd; if (njd>=jd) return njd;
return scan_jd(realm,yjd+365+leap,1); [y,yjd,leap]=gregorian_year(y+1);
} }
else
{
if (njd<=jd) return njd; if (njd<=jd) return njd;
return scan_jd(realm,yjd-1,-1); [y,yjd,leap]=gregorian_year(y-1);
}
}
} }
string describe() string describe()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment