end;
idayleave := idayleave - wcount;
end;
wbigsmalldist := wbigsmalldist shr 1;
end;
end;
//返回值:
// 1位闰月标志 + 12位年份+4位月份+5位日期 (共22位)
end;
function iscnleap(cndate:tcndate):boolean;
begin
result := (cndate and $200000) <> 0;
end;
function getgregdatefromcn(cnyear,cnmonth,cnday:word;bleap:boolean=false):tdatetime;
var
i,j:integer;
daycount:integer;
wbigsmalldist,wleap,wleapshift:word;
begin
// 0101 010010101111 高四位是闰月位置,后12位表示大小月,大月30天,小月29天,
daycount := 0;
if (cnyear < 1990) or (cnyear >2050) then begin
result := 0;
exit;
end;
for i:= cstcnyearorg to cnyear-1 do begin
wbigsmalldist := cstcntable[i];
if (wbigsmalldist and $f000) <> 0 then daycount := daycount + 29;
daycount := daycount + 12 * 29;
for j:= 1 to 12 do begin
daycount := daycount + wbigsmalldist and 1;
wbigsmalldist := wbigsmalldist shr 1;
end;
end;
wbigsmalldist := cstcntable[cnyear];
wleap := wbigsmalldist shr 12;
if wleap > 12 then begin
wleap := wleap and 7;
wleapshift := 1; //大月在闰月.
end else
wleapshift := 0;
for j:= 1 to cnmonth-1 do begin
daycount:=daycount + (wbigsmalldist and 1) + 29;
if j=wleap then daycount := daycount + 29;
wbigsmalldist := wbigsmalldist shr 1;
end;
if bleap and (cnmonth = wleap) then //是要闰月的吗?
daycount := daycount + 30 - wleapshift;
result := cstdateorg + daycount + cnday - 1;
end;
//将日期显示成农历字符串.
function gregdatetocnstr(dtgreg:tdatetime):string;
const hznumber:array[0..10] of string=('零','一','二','三','四','五','六','七','八','九','十');
function convertymd(number:word;ymd:word):string;
var
wtmp:word;
begin
result := '';
if ymd = 1 then begin //年份
while number > 0 do begin
result := hznumber[number mod 10] + result;
number := number div 10;
end;
exit;
end;
if number<=10 then begin //可只用1位
if ymd = 2 then //月份
result := hznumber[number]
else //天
result := '初' + hznumber[number];
exit;
end;
wtmp := number mod 10; //个位
if wtmp <> 0 then result := hznumber[wtmp];
wtmp := number div 10; //十位
result:='十'+result;
if wtmp > 1 then result := hznumber[wtmp] + result;
end;
var
cnyear,cnmonth,cnday:word;
cndate:tcndate;
strleap:string;
begin
cndate:= decodegregtocndate(dtgreg);
if cndate = 0 then begin
result := '输入越界';
exit;
end;
cnday := cndate and $1f;
cnmonth := (cndate shr 5) and $f;
cnyear := (cndate shr 9) and $fff;
//测试第22位,为1表示闰月