日历函数单元

2008-04-09 04:20:41来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

//原始版权宣告:

/***************************************************************************
致看到这些源代码的兄弟:
你好!
这本来是我为一个商业PDA产品开发的日历程序,最近移植于PC机上, 所以算法
和数据部分是用纯C 写的,不涉及MFC,所有的代码都是以短节省存储空间为主要目
的.
很高兴你对这些代码有兴趣,你可以随意复制和使用些代码,唯一有一点小小的
愿望:在你使用和复制给别人时,别忘注明这些代码作者:-)。程序代码也就罢了,后
面的数据可是我辛辛苦苦从万年历上找出来输进去的。
如果你有什么好的意见不妨Mail给我。

wangfei@hanwang.com.cn

wangfei@engineer.com.cn
2000年3月
****************************************************************************/

//Translated and modified by Icebird from C to Delphi 5 on 2001.1

unit Calendar;

interface

uses SysUtils, Windows;

const
START_YEAR = 1901;
END_YEAR = 2050;

// ==> function IsLeapYear(Year: Word): Boolean;

//计算iYear,iMonth,iDay对应是星期几 1年1月1日 --- 65535年12月31日
function WeekDay(iYear, iMonth, iDay: Word): Integer;
// ==> function DayOfWeek(Date: TDateTime): Integer;

//计算指定日期的周数,周0为新年开始后第一个星期天开始的周
function WeekNum(const TDT: TDateTime): Word; overload;
function WeekNum(const iYear, iMonth, iDay: Word): Word; overload;

//返回iYear年iMonth月的天数 1年1月 --- 65535年12月
function MonthDays(iYear, iMonth: Word): Word;

//返回阴历iLunarYer年阴历iLunarMonth月的天数,如果iLunarMonth为闰月,
//高字为第二个iLunarMonth月的天数,否则高字为0
// 1901年1月---2050年12月
function LunarMonthDays(iLunarYear, iLunarMonth: Word): Longword;

//返回阴历iLunarYear年的总天数
// 1901年1月---2050年12月
function LunarYearDays(iLunarYear: Word): Word;

//返回阴历iLunarYear年的闰月月份,如没有返回0
// 1901年1月---2050年12月
function GetLeapMonth(iLunarYear: Word): Word;

//把iYear年格式化成天干记年法表示的字符串
procedure FormatLunarYear(iYear: Word; var pBuffer: string); overload;
function FormatLunarYear(iYear: Word): string; overload;

//把iMonth格式化成中文字符串
procedure FormatMonth(iMonth: Word; var pBuffer: string; bLunar: Boolean = True); overload;
function FormatMonth(iMonth: Word; bLunar: Boolean = True): string; overload;

//把iDay格式化成中文字符串
procedure FormatLunarDay(iDay: Word; var pBuffer: string); overload;
function FormatLunarDay(iDay: Word): string; overload;

//计算公历两个日期间相差的天数 1年1月1日 --- 65535年12月31日
function CalcDateDiff(iEndYear, iEndMonth, iEndDay: Word; iStartYear: Word = START_YEAR; iStartMonth: Word = 1; iStartDay: Word = 1): Longword; overload;
function CalcDateDiff(EndDate, StartDate: TDateTime): Longword; overload;

//计算公历iYear年iMonth月iDay日对应的阴历日期,返回对应的阴历节气 0-24
//1901年1月1日---2050年12月31日
function GetLunarDate(iYear, iMonth, iDay: Word; var iLunarYear, iLunarMonth, iLunarDay: Word): Word; overload;
procedure GetLunarDate(InDate: TDateTime; var iLunarYear, iLunarMonth, iLunarDay: Word); overload;

function GetLunarHolDay(InDate: TDateTime): string; overload;
function GetLunarHolDay(iYear, iMonth, iDay: Word): string; overload;

//private function--------------------------------------

//计算从1901年1月1日过iSpanDays天后的阴历日期
procedure l_CalcLunarDate(var iYear, iMonth, iDay: Word; iSpanDays: Longword);

//计算公历iYear年iMonth月iDay日对应的节气 0-24,0表不是节气
function l_GetLunarHolDay(iYear, iMonth, iDay: Word): Word;

//计算指定日期所对应的星座
function GetConstellation(const DateTime: TDateTime): Integer;
function GetConstellationName(const Constellation: Integer): string; overload;
function GetConstellationName(const DateTime: TDateTime): string; overload;

implementation

var
//数组gLunarDay存入阴历1901年到2100年每年中的月天数信息,
//阴历每月只能是29或30天,一年用12(或13)个二进制位表示,对应位为1表30天,否则为29天
gLunarMonthDay: array[0..149] of Word = (
//测试数据只有1901.1.1 --2050.12.31
$4AE0, $A570, $5268, $D260, $D950, $6AA8, $56A0, $9AD0, $4AE8, $4AE0, //1910
$A4D8, $A4D0, $D250, $D548, $B550, $56A0, $96D0, $95B0, $49B8, $49B0, //1920
$A4B0, $B258, $6A50, $6D40, $ADA8, $2B60, $9570, $4978, $4970, $64B0, //1930
$D4A0, $EA50, $6D48, $5AD0, $2B60, $9370, $92E0, $C968, $C950, $D4A0, //1940
$DA50, $B550, $56A0, $AAD8, $25D0, $92D0, $C958, $A950, $B4A8, $6CA0, //1950
$B550, $55A8, $4DA0, $A5B0, $52B8, $52B0, $A950, $E950, $6AA0, $AD50, //1960
$AB50, $4B60, $A570, $A570, $5260, $E930, $D950, $5AA8, $56A0, $96D0, //1970
$4AE8, $4AD0, $A4D0, $D268, $D250, $D528, $B540, $B6A0, $96D0, $95B0, //1980
$49B0, $A4B8, $A4B0, $B258, $6A50, $6D40, $ADA0, $AB60, $9370, $4978, //1990
$4970, $64B0, $6A50, $EA50, $6B28, $5AC0, $AB60, $9368, $92E0, $C960, //2000

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:在Delphi中如何控制其它应用程序窗口

下一篇:使用 COM 参数化对象结构编程技术