procedure Tyun.tran ;
Type
lunTYPE = array[1..99,1..13] of integer ;
vvm = Array[1..6] of Integer;
yday = Array[1..10,1..2] of integer;
eday = Array[1..7,1..2] of integer;
um = Array[1..99,1..13] of Longint;
Days = set of 3..6;
Days1 = set of 3..4;
Days2 = set of 5..6;
{ky=LEFT(DTOC(ddd),4)}
year := 1900;
month := 12;
Day := 31;
Stdate := encodeDate( Year, Month, Day);
tt :=ddd-Stdate-49 ;
yy1 :=1;
WHILE tt>eum[yy1,1] do begin
tt := tt-eum[yy1,1];
yy1 := yy1+1 ;
END;
mm1 := 2;
WHILE tt>vm[eum[yy1,mm1]] do begin
tt := tt-vm[eum[yy1,mm1]] ;
mm1 := mm1+1 ;
END;
dd1 := tt;
IF eum[yy1,mm1] in dyn then begin
IF (eum[yy1,mm1] in dyn1) AND (tt > 29) then
dd1 :=tt-29;
IF (eum[yy1,mm1] in dyn2) AND (tt > 30) then
dd1 := tt-30;
END;
year := yy1+1900;
month := mm1-1;
Day := Trunc(dd1);
yymmdd.caption := IntTOStr(year)+ '년' +IntTOStr(month) + '월' + IntTOStr(Day)+ '일';
end;
procedure Tyun.okClick(Sender: TObject);
begin
tran;
end;
procedure Tyun.chkmaxday ;
var
myym : integer;
begin
myym := yy.value mod 4;
case mm.value of
1 : begin
dd.MaxValue := 31;
end;
2 : begin
if myym = 0 then begin
if dd.value > 29 then
dd.value := 29;
dd.MaxValue := 29;
end
else begin
if dd.value > 28 then
dd.value := 28;
dd.MaxValue := 28;
end;
end;
3 : begin
dd.MaxValue := 31;
end;
4 : begin
if dd.value > 30 then
dd.value := 30;
dd.MaxValue := 30;
end;
5 : begin
dd.MaxValue := 31;
end;
6 : begin
if dd.value > 30 then
dd.value := 30;
dd.MaxValue := 30;
end;
7 : begin
dd.MaxValue := 31;
end;
8 : begin
dd.MaxValue := 31;
end;
9 : begin
if dd.value > 30 then
dd.value := 30;
dd.MaxValue := 30;
end;
10 : begin
dd.MaxValue := 31;
end;
11 : begin
if dd.value > 30 then
dd.value := 30;
dd.MaxValue := 30;
end;
12 : begin
dd.MaxValue := 31;
end;
else
mm.value := 1;
end;
end;
procedure Tyun.yyChange(Sender: TObject);
begin
chkmaxday;
end;
procedure Tyun.mmChange(Sender: TObject);
begin
chkmaxday;
end;
데이터에 의해 바꿀수 있습니다.
예전에 어디선가 다운받은 소스입니다. (저자는 최경원으로 되어있습니다.)
다음은 소스의 내용입니다.
참고 : 1901년부터 1999년까지 처리할 수 있습니다.
unit sunlun;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Spin, StdCtrls, Buttons;
type
Tyun = class(TForm)
yy: TSpinEdit;
mm: TSpinEdit;
dd: TSpinEdit;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
yymmdd: TPanel;
Panel8: TPanel;
ok: TBitBtn;
Panel6: TPanel;
procedure okClick(Sender: TObject);
procedure yyChange(Sender: TObject);
procedure mmChange(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
procedure tran;
procedure chkmaxday ;
public
{ Public declarations }
end;
var
yun: Tyun;
implementation
{$R *.DFM}
procedure Tyun.tran ;
Type
lunTYPE = array[1..99,1..13] of integer ;
vvm = Array[1..6] of Integer;
yday = Array[1..10,1..2] of integer;
eday = Array[1..7,1..2] of integer;
um = Array[1..99,1..13] of Longint;
Days = set of 3..6;
Days1 = set of 3..4;
Days2 = set of 5..6;
const
eum : lunTYPE = ((354, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1),
(355, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2),
(383, 1, 2, 1, 2, 3, 2, 1, 1, 2, 2, 1, 2),
(354, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1),
(355, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 1, 2),
(384, 1, 2, 2, 4, 1, 2, 1, 2, 1, 2, 1, 2),
(354, 1, 2, 1, 2, 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, 2, 2, 1, 1, 2, 1, 1, 5, 2, 2),
(354, 1, 2, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2),
(354, 1, 2, 2, 1, 2, 2, 1, 2, 1, 2, 1, 1),
(385, 2, 1, 2, 2, 1, 5, 2, 2, 1, 2, 1, 2),
(354, 1, 1, 2, 1, 2, 1, 2, 2, 1, 2, 2, 1),
(355, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 2),
(384, 1, 2, 1, 1, 5, 1, 2, 2, 1, 2, 2, 2),
(354, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 2),
(354, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2),
(383, 1, 2, 5, 2, 1, 2, 1, 1, 2, 1, 2, 1),
(355, 2, 2, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2),
(384, 1, 2, 2, 1, 2, 2, 1, 5, 2, 1, 1, 2),
(354, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 1),
(355, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 2, 1),
(384, 2, 1, 1, 2, 3, 2, 2, 1, 2, 2, 1, 2),
(354, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 2, 1));
var
i,yy1,mm1,j : integer;
ddd,tt,pv_odate,Stdate : TdateTime;
dg,dd1 : real;
yhday : yday;
ehday :eday;
vm : vvm;
dyn : days;
dyn1 : days1;
dyn2 : days2;
tmp1,tmp2,tmp3 : string;
Year, Month, Day,Year1, Month1, Day1: word;
begin
year := yy.value;
month := mm.value;
Day := dd.value;
ddd := encodeDate( Year, Month, Day);
vm[1] := 29 ;
vm[2] := 30 ;
vm[3] := 29 + 29 ;
vm[4] := 29 + 30 ;
vm[5] := 30 + 29 ;
vm[6] := 30 + 30 ;
{ky=LEFT(DTOC(ddd),4)}
year := 1900;
month := 12;
Day := 31;
Stdate := encodeDate( Year, Month, Day);
tt :=ddd-Stdate-49 ;
yy1 :=1;
WHILE tt>eum[yy1,1] do begin
tt := tt-eum[yy1,1];
yy1 := yy1+1 ;
END;
mm1 := 2;
WHILE tt>vm[eum[yy1,mm1]] do begin
tt := tt-vm[eum[yy1,mm1]] ;
mm1 := mm1+1 ;
END;
dd1 := tt;
IF eum[yy1,mm1] in dyn then begin
IF (eum[yy1,mm1] in dyn1) AND (tt > 29) then
dd1 :=tt-29;
IF (eum[yy1,mm1] in dyn2) AND (tt > 30) then
dd1 := tt-30;
END;
year := yy1+1900;
month := mm1-1;
Day := Trunc(dd1);
yymmdd.caption := IntTOStr(year)+ '년' +IntTOStr(month) + '월' + IntTOStr(Day)+ '일';
end;
procedure Tyun.okClick(Sender: TObject);
begin
tran;
end;
procedure Tyun.chkmaxday ;
var
myym : integer;
begin
myym := yy.value mod 4;
case mm.value of
1 : begin
dd.MaxValue := 31;
end;
2 : begin
if myym = 0 then begin
if dd.value > 29 then
dd.value := 29;
dd.MaxValue := 29;
end
else begin
if dd.value > 28 then
dd.value := 28;
dd.MaxValue := 28;
end;
end;
3 : begin
dd.MaxValue := 31;
end;
4 : begin
if dd.value > 30 then
dd.value := 30;
dd.MaxValue := 30;
end;
5 : begin
dd.MaxValue := 31;
end;
6 : begin
if dd.value > 30 then
dd.value := 30;
dd.MaxValue := 30;
end;
7 : begin
dd.MaxValue := 31;
end;
8 : begin
dd.MaxValue := 31;
end;
9 : begin
if dd.value > 30 then
dd.value := 30;
dd.MaxValue := 30;
end;
10 : begin
dd.MaxValue := 31;
end;
11 : begin
if dd.value > 30 then
dd.value := 30;
dd.MaxValue := 30;
end;
12 : begin
dd.MaxValue := 31;
end;
else
mm.value := 1;
end;
end;
procedure Tyun.yyChange(Sender: TObject);
begin
chkmaxday;
end;
procedure Tyun.mmChange(Sender: TObject);
begin
chkmaxday;
end;
procedure Tyun.FormShow(Sender: TObject);
var
year,month,day : word;
begin
DecodeDate(Now,year,month,day);
yy.value := year;
mm.value := month;
dd.value := day;
chkmaxday;
tran;
end;
end.