Archive for June 25th, 2008

To get the last day of a month.

Wednesday, June 25th, 2008
Anybody who made a calendar in Flash may have written this code. You may use if or switch statements to get the last day of a month.
달력 같은 걸 만들면서 누구나 한번쯤 만들어 봤을 코드입니다. 지정된 달의 마지막 날을 구하기 위해서 if문이나 아래 코드처럼 switch문을 사용하게 되죠.
カレンダーみたいなものを作って見た方は、このコードを作成したことがあるんですね。普通、月の末日を得るために、if文とかswitch文を使うんです。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function getLastDayOld(day:Date):Date{
 
	var dd:uint = 31;
 
	var yyyy:uint = day.getFullYear();
	var mm:uint = day.getMonth() + 1;
 
	switch(mm){
 
		case 4:
		case 6:
		case 9:
		case 11:
			dd = 30;
		break;
 
		case 2:
			if((yyyy % 4) == 0 || (yyyy % 100) == 0){
				dd = 29;
			}else{
				dd = 28;
			}
		break;
 
	}
 
	var lastDay:Date = new Date(yyyy, (mm-1), dd);
	return lastDay;
 
}
I figured out a more simple solution. Date.setMonth() method simply gets the job done.
그런데 이 문제를 매우 간단히 해결할 수 있는 코드를 생각해 냈습니다. Date.setMonth() 메소드 하나로 쉽게 처리가 되네요.
これをもっと簡単に処理するコードを考えてみました。Date.setMonth()メソッドを使えば、オーケーです。
1
2
3
4
5
function getLastDay(day:Date):Date{
	var lastDay:Date = new Date(day);
	lastDay.setMonth(lastDay.getMonth() + 1, 0);
	return lastDay;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var day:Date = new Date(2008, 0, 15);
for(var i:uint=0; i<12; i++){
	day.setMonth(i);
	trace((day.getMonth() + 1), " - ", getLastDay(day).getDate(), " : ", getLastDayOld(day).getDate());
}
/* output
1  -  31  :  31
2  -  29  :  29
3  -  31  :  31
4  -  30  :  30
5  -  31  :  31
6  -  30  :  30
7  -  31  :  31
8  -  31  :  31
9  -  30  :  30
10  -  31  :  31
11  -  30  :  30
12  -  31  :  31*/

Ghost-Corps workshop.

Wednesday, June 25th, 2008
I attended a Ghost-Corps workshop, last weekend. You can see pictures on the followind links.
지난 주말에 고스트-코어에서 워크샵을 다녀왔습니다. 산정호수 근처 팬션을 잡아서 1박 2일로 다녀왔는데, 금요일 밤에 출발해서 토요일 오후에 돌아오는 일정이다 보니, 밥먹고 술먹고 고기 구워먹고 한것 밖에 생각나는게 없네요. ㅎㅎ
귀차니즘으로 사진 올리는 것은 포기하고 (사실 사진도 찍지 않았지만) 링크만 겁니다.
今度の週末、ごストーコアのワークショップに行って来たんです。下のリンクで写真を見ることが出来ます。

GhostCorps 1st Workshop - BK2008
고스트코어 워크샵을 다녀오다. - 세가지소원