⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lunarobj.pas

📁 Clock 桌面时钟 日历 阴历 看到的delphi程序 转发
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit LunarObj;

interface

uses SysUtils, DateUtils, Controls, SysConst;

type
  TLunarDate = record  //农历日期
    Year: integer;
    Month: integer;
    Day: integer;
    isLeap: Boolean;
  end;

  function Lunar(aYear, aMonth, aDay : Word): TLunarDate; overload;

  function Lunar(aDate: TDate): TLunarDate; overload;

  function Solar(aDate: TLunarDate): TDate; overload

  procedure Solar(aDate : TLunarDate ; var aYear, aMonth, aDay : Word); overload;

  function SolarTerm(aDate: TDate): string; overload;

  function SolarTerm(aYear, aMonth, aDay : Word): string; overload;

  procedure FormatLunarDay(iDay:Integer;var pBuffer:string); overload;

  function FormatLunarDay(iDay:Integer): string; overload;

  procedure FormatLunarYear(iYear:Integer;var pBuffer:string); overload;

  function FormatLunarYear(iYear:Integer): string; overload;

  procedure FormatLunarMonth(iMonth:Integer;var pBuffer:string; bLeapMonth : 
      boolean = false;bLunar:Boolean=True); overload;

  function FormatLunarMonth(iMonth:Integer; bLeapMonth : boolean = false; 
      bLunar:Boolean=True): string; overload;

  function lunarFestival(aYear, aMonth , aDay:  Integer): string;

  function solarFestival(aYear, aMonth , aDay:  Integer): string;

  function WeekEnName(aWeekDay : Integer ; l : boolean = false): string; overload;

  function MonthEnName(aMonth : Integer ; l : Boolean = false): string;

  function WeekCnName(aWeekDay : Integer ): string;

function MonthDays(aYear, aMonth : Word): Integer;

function WeekDay(aYear, aMonth , aDay:  Integer): Integer;

implementation

const
  lunarInfo: array[0..200] of WORD =(
    $4bd8,$4ae0,$a570,$54d5,$d260,$d950,$5554,$56af,$9ad0,$55d2,//1909
    $4ae0,$a5b6,$a4d0,$d250,$d295,$b54f,$d6a0,$ada2,$95b0,$4977,//1919
    $497f,$a4b0,$b4b5,$6a50,$6d40,$ab54,$2b6f,$9570,$52f2,$4970,//1929
    $6566,$d4a0,$ea50,$6a95,$5adf,$2b60,$86e3,$92ef,$c8d7,$c95f,//1939
    $d4a0,$d8a6,$b55f,$56a0,$a5b4,$25df,$92d0,$d2b2,$a950,$b557,//1949
    $6ca0,$b550,$5355,$4daf,$a5b0,$4573,$52bf,$a9a8,$e950,$6aa0,//1959
    $aea6,$ab50,$4b60,$aae4,$a570,$5260,$f263,$d950,$5b57,$56a0,//1969
    $96d0,$4dd5,$4ad0,$a4d0,$d4d4,$d250,$d558,$b540,$b6a0,$95a6,//1979
    $95bf,$49b0,$a974,$a4b0,$b27a,$6a50,$6d40,$af46,$ab60,$9570,//1989
    $4af5,$4970,$64b0,$74a3,$ea50,$6b58,$5ac0,$ab60,$96d5,$92e0,//1999
    $c960,$d954,$d4a0,$da50,$7552,$56a0,$abb7,$25d0,$92d0,$cab5,//2009
    $a950,$b4a0,$baa4,$ad50,$55d9,$4ba0,$a5b0,$5176,$52bf,$a930,//2019
    $7954,$6aa0,$ad50,$5b52,$4b60,$a6e6,$a4e0,$d260,$ea65,$d530,//2029
    $5aa0,$76a3,$96d0,$4afb,$4ad0,$a4d0,$d0b6,$d25f,$d520,$dd45,//2039
    $b5a0,$56d0,$55b2,$49b0,$a577,$a4b0,$aa50,$b255,$6d2f,$ada0,//2049
    $4b63,$937f,$49f8,$4970,$64b0,$68a6,$ea5f,$6b20,$a6c4,$aaef,//2059
    $92e0,$d2e3,$c960,$d557,$d4a0,$da50,$5d55,$56a0,$a6d0,$55d4,//2069
    $52d0,$a9b8,$a950,$b4a0,$b6a6,$ad50,$55a0,$aba4,$a5b0,$52b0,//2079
    $b273,$6930,$7337,$6aa0,$ad50,$4b55,$4b6f,$a570,$54e4,$d260,//2089
    $e968,$d520,$daa0,$6aa6,$56df,$4ae0,$a9d4,$a4d0,$d150,$f252,//2099
    $d520);

  sTermInfo: Array[0..23] of integer =
    (0,21208,42467,63836
    ,85337,107014,128867,150921
    ,173149,195551,218072,240693
    ,263343,285989,308563,331033
    ,353350,375494,397447,419210
    ,440795,462224,483532,504758);

  sTermName: Array[0..23] of string =
    ('小寒','大寒','立春','雨水'
    ,'惊蛰','春分','清明','谷雨'
    ,'立夏','小满','芒种','夏至'
    ,'小暑','大暑','立秋','处暑'
    ,'白露','秋分','寒露','霜降'
    ,'立冬','小雪','大雪','冬至');
  sFtv: Array[0..95] of string =(
    '0101*新年元旦',
    '0202 世界湿地日',
    '0207 国际声援南非日',
    '0210 国际气象节',
    '0212 国际足球比赛日',
    '0214 西方情人节',
    '0301 国际海豹日',
    '0303 全国爱耳日',
    '0308 国际妇女节',
    '0312 植树节 孙中山逝世纪念日',
    '0314 国际警察日',
    '0315 国际消费者权益日',
    '0317 中国国医节 国际航海日',
    '0321 世界森林日 消除种族歧视国际日',
    '0321 世界儿歌日',
    '0322 世界水日',
    '0323 世界气象日',
    '0324 世界防治结核病日',
    '0325 全国中小学生安全教育日',
    '0330 巴勒斯坦国土日',
    '0401 愚人节 全国爱国卫生运动月(四月) 税收宣传月(四月)',
    '0407 世界卫生日',
    '0422 世界地球日',
    '0423 世界图书和版权日',
    '0424 亚非新闻工作者日',
    '0501*国际劳动节',
    '0504 中国五四青年节',
    '0505 碘缺乏病防治日',
    '0508 世界红十字日',
    '0512 国际护士节',
    '0515 国际家庭日',
    '0517 世界电信日',
    '0518 国际博物馆日',
    '0520 全国学生营养日',
    '0523 国际牛奶日',
    '0531 世界无烟日',
    '0601*国际儿童节',
    '0605 世界环境日',
    '0606 全国爱眼日',
    '0617 防治荒漠化和干旱日',
    '0623 国际奥林匹克日',
    '0625 全国土地日',
    '0626 国际反毒品日',
    '0701 中国共产党建党日 世界建筑日',
    '0702 国际体育记者日',
    '0707 中国人民抗日战争纪念日',
    '0711 世界人口日',
    '0730 非洲妇女日',
    '0801 中国建军节',
    '0808 中国男子节(爸爸节)',
    '0815 日本正式宣布无条件投降日',
    '0908 国际扫盲日 国际新闻工作者日',
    '0910*教师节',
    '0914 世界清洁地球日',
    '0916 国际臭氧层保护日',
    '0918 九·一八事变纪念日',
    '0920 国际爱牙日',
    '0927 世界旅游日',
    '1001*国庆节 世界音乐日 国际老人节',
    '1001 国际音乐日',
    '1002 国际和平与民主自由斗争日',
    '1004 世界动物日',
    '1008 全国高血压日',
    '1008 世界视觉日',
    '1009 世界邮政日 万国邮联日',
    '1010 辛亥革命纪念日 世界精神卫生日',
    '1013 世界保健日 国际教师节',
    '1014 世界标准日',
    '1015 国际盲人节(白手杖节)',
    '1016 世界粮食日',
    '1017 世界消除贫困日',
    '1022 世界传统医药日',
    '1024 联合国日 世界发展信息日',
    '1031 世界勤俭日',
    '1107 十月社会主义革命纪念日',
    '1108 中国记者日',
    '1109 全国消防安全宣传教育日',
    '1110 世界青年节',
    '1111 国际科学与和平周(本日所属的一周)',
    '1112 孙中山诞辰纪念日',
    '1114 世界糖尿病日',
    '1117 国际大学生节 世界学生节',
    '1121 世界问候日 世界电视日',
    '1129 国际声援巴勒斯坦人民国际日',
    '1201 世界艾滋病日',
    '1203 世界残疾人日',
    '1205 国际经济和社会发展志愿人员日',
    '1208 国际儿童电视日',
    '1209 世界足球日',
    '1210 世界人权日',
    '1212 西安事变纪念日',
    '1213 南京大屠杀(1937年)纪念日!紧记血泪史!',
    '1221 国际篮球日',
    '1224 平安夜',
    '1225*圣诞节',
    '1229 国际生物多样性日');

  //某月的第几个星期几。 5,6,7,8 表示到数第 1,2,3,4 个星期几
  wFtv: Array[0..11] of string = (
    '0110 黑人日',
    '0150 世界麻风日', //一月的最后一个星期日(月倒数第一个星期日)
    '0520 国际母亲节',
    '0530 全国助残日',
    '0630 父亲节',
    '0911 劳动节',
    '0932 国际和平日',
    '0940 国际聋人节 世界儿童日',
    '0950 世界海事日',
    '1011 国际住房日',
    '1013 国际减轻自然灾害日(减灾日)',
    '1144 感恩节');

  //农历节日
  lFtv: Array[0..10] of string = (
    '0101*春节',
    '0115*元宵节 中国情人节',
    '0202 龙抬头节',
    '0323 妈祖生辰 (天上圣母诞辰)',
    '0505*端午节',
    '0707 七七中国情人节',
    '0815*中秋节',
    '0909*重阳节',
    '1208 腊八节',
    '1223 灶君(祭灶)节',
    '0100*除夕');  

//====== 返回农历 y年闰哪个月 1-12 , 没闰返回 0
function leapMonth(y: integer): integer;
var
  lm: Word;
begin
  lm:= lunarInfo[y - 1900] and $f;
  if lm = $f then
    Result:= 0
  else
    Result:= lm;
end;

//====== 返回农历 y年闰月的天数
function leapDays(y: integer): integer;
begin
 if Boolean(leapMonth(y)) then begin
   if (lunarInfo[y - 1899] and $f) = $f then
     Result := 30
   else
     Result := 29;
 end else
   Result := 0;
end;

//======== 返回农历 y年m月的总天数
function lMonthDays(aYear, aMonth: integer): integer;
var
  temp1, temp2: Word;
begin
  temp1:= lunarInfo[aYear - 1900];
  temp2:= $8000;

  if aMonth > 1 then
    temp2:= $8000 shr (aMonth - 1);

  if temp1 and temp2 > 0 then
    Result:= 30
  else
    Result:= 29;
end;

//====== 返回农历 y年的总天数
function lYearDays(aYear: integer): integer;
var
  i, sum: integer;
begin
  sum:= 348;  i:= $8000;
  while i > $8 do begin
    if (lunarInfo[aYear - 1900] and i) > 0 then
  	  Inc(sum);
    i:= i shr 1;
  end;
  Result:= sum + leapDays(aYear);
end;
function Lunar(aDate: TDate): TLunarDate;
var
  i, leap, temp, offset: integer;
begin
  FillChar(Result, SizeOf(TLunarDate), 0);

  temp:= YearOf(aDate);

  if(temp < 1901) or (temp > 2100) then
    exit;

  offset:= DaysBetween(EncodeDate(1900,1,31), aDate);

  i:= 1900;
  while (i < 2100) and (offset > 0) do begin
    temp:= lYearDays(i);
    offset:= offset - temp;
    Inc(i);
  end;

  if (offset < 0) then begin
    offset:= offset + temp;
    i:= i - 1;
  end;

  Result.Year:= i;

  leap:= leapMonth(i); //闰哪个月
  Result.isLeap:= False;

  i:=1;
  while (i < 13) and (offset > 0) do begin
    if (leap > 0) and (i = leap + 1) and (Result.isLeap = False) then begin
      i:= i - 1;
      Result.isLeap:= True;
      temp:= leapDays(Result.Year);
    end else
      temp:= lMonthDays(Result.Year, i);

    if (Result.isLeap = True) and (i = leap + 1) then
      Result.isLeap:= False;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -