SamadYousefi
دوشنبه 08 آبان 1385, 10:56 صبح
//شمسی = solar و میلادی = Christian
uses SysUtils, DateUtils;
type
TSolarDate = String[10];
TDateType= (dtChristian, dtSolar);
TIsLeap= type Boolean;
const
MonthDays: array[TDateType, TIsLeap, 1..12]of Word =
(((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)),
((31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29),
(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30)));
function DayOf(Value: TSolarDate): Word;
begin
Result:= StrToIntDef(Copy(Value, 9, 2), 0);
end;
function MonthOf(Value: TSolarDate): Word;
begin
Result:= StrToIntDef(Copy(Value, 6, 2), 0);
end;
function YearOf(Value: TSolarDate): Word;
begin
Result:= StrToIntDef(Copy(Value, 1, 4), 0);
end;
procedure DecodeDate(Value: TSolarDate; var Year, Month, Day: Word);
begin
Year:= YearOf(Value);
Month:= MonthOf(Value);
Day:= DayOf(Value);
end;
function EncodeDate(Year, Month, Day: Word): TSolarDate;
begin
Result:= IntToStr(Year)+'/'+ FormatFloat('00', Month)+'/'+ FormatFloat('00', Day);
end;
function ToChristian(Value: TSolarDate): TDate;
var
I: Word;
Days : Integer;
YY, MM, DD: Word;
begin
DecodeDate(Value, YY, MM, DD);
Days:=0;
for I:=1 to MM-1 do
Days:= Days + MonthDays[dtSolar, False, I] ;
Days:= Days + DD + 78;
YY := YY + 621;
Result:= SysUtils.EncodeDate(YY, 1, 1)+ Days;
end;
برای نوشتن کد از تگ [ CODE] استفاده کنید تا کد نوشته شده خواناتر شود. با تشکر
uses SysUtils, DateUtils;
type
TSolarDate = String[10];
TDateType= (dtChristian, dtSolar);
TIsLeap= type Boolean;
const
MonthDays: array[TDateType, TIsLeap, 1..12]of Word =
(((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)),
((31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29),
(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30)));
function DayOf(Value: TSolarDate): Word;
begin
Result:= StrToIntDef(Copy(Value, 9, 2), 0);
end;
function MonthOf(Value: TSolarDate): Word;
begin
Result:= StrToIntDef(Copy(Value, 6, 2), 0);
end;
function YearOf(Value: TSolarDate): Word;
begin
Result:= StrToIntDef(Copy(Value, 1, 4), 0);
end;
procedure DecodeDate(Value: TSolarDate; var Year, Month, Day: Word);
begin
Year:= YearOf(Value);
Month:= MonthOf(Value);
Day:= DayOf(Value);
end;
function EncodeDate(Year, Month, Day: Word): TSolarDate;
begin
Result:= IntToStr(Year)+'/'+ FormatFloat('00', Month)+'/'+ FormatFloat('00', Day);
end;
function ToChristian(Value: TSolarDate): TDate;
var
I: Word;
Days : Integer;
YY, MM, DD: Word;
begin
DecodeDate(Value, YY, MM, DD);
Days:=0;
for I:=1 to MM-1 do
Days:= Days + MonthDays[dtSolar, False, I] ;
Days:= Days + DD + 78;
YY := YY + 621;
Result:= SysUtils.EncodeDate(YY, 1, 1)+ Days;
end;
برای نوشتن کد از تگ [ CODE] استفاده کنید تا کد نوشته شده خواناتر شود. با تشکر