001 /*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016 package org.opengion.hayabusa.resource;
017
018 import org.opengion.hayabusa.common.HybsSystem;
019
020 import java.util.Calendar;
021
022 /**
023 * 事業æ‰?CDJGS) 毎ã?休日カレンãƒ?ƒ‡ータオブジェクトですã?
024 *
025 * カレンãƒ?ƒ‡ータは、指定ã?事業æ‰?�«関して、すべての休日æƒ??を持ってã�?�¾すã?
026 * å…??カレンãƒ?ƒ†ーブル(GE13)の ?‘日(DY1)?ž31日(DY31)までの日付けæ¬?�«対してã€?
027 * 休日日付けの 年月日 に対する、休日かどã�?�‹を判断できるã�?�‘のæƒ??を保持しますã?
028 * 具体的には、年月日に対する Set を持つことになりますã?
029 *
030 * @og.rev 3.6.0.0 (2004/09/17) 新規作æ?
031 * @og.group リソース管ç�?
032 *
033 * @version 4.0
034 * @author Hiroki Nakamura
035 * @since JDK5.0,
036 */
037 public abstract class AbstractCalendarPGData implements CalendarData {
038 // private final Calendar today = Calendar.getInstance(); // 3.8.8.6 (2007/04/20) å»?¢
039
040 /**
041 * こã?コンストラクタは、他ã?パッケージから呼び出せなã�?‚ˆã�?�«ã€?
042 * パッケージプライベã?トにしておきますã?
043 *
044 */
045 AbstractCalendarPGData() {
046 // ここでは処ç�?‚’行いませんã€?
047 }
048
049 /**
050 * æŒ?®šã?日付けがã?休日かどã�?�‹を返しますã?
051 *
052 * @param day æŒ?®šã?日付け
053 *
054 * @return 休日?štrue それ以外:false
055 *
056 */
057 // public abstract boolean isHoliday( final Calendar day );
058
059 /**
060 * æŒ?®šã?日付けから、ç¯?›²の間に、本日を含ã‚?�‹どã�?�‹を返しますã?
061 * æŒ?®šã?日付けがã?キャãƒ?‚·ュしてã�?‚‹ãƒ??タのæœ?¤§とæœ?°�ã?間に
062 * 存在しなã�??合ã?、常に false になりますã?
063 * 判定ã?、年月日のé ?›®のみで比è¼?�—、時åˆ?§’ã?無視しますã?
064 *
065 * @og.rev 3.7.1.1 (2005/05/31) 新規追åŠ?
066 * @og.rev 3.8.8.6 (2007/04/20) today を毎回求めますã?(キャãƒ?‚·ュ対ç?
067 *
068 * @param day æŒ?®šã?開始日付け
069 * @param scope ç¯?›²の日数
070 *
071 * @return 本日?štrue それ以外:false
072 */
073 public boolean isContainedToday( final Calendar day,final int scope ) {
074 final boolean rtnFlag;
075
076 Calendar today = Calendar.getInstance();
077 today.set( Calendar.HOUR_OF_DAY ,12 ); // 昼にセãƒ?ƒˆ
078 today.set( Calendar.MINUTE ,0 );
079 today.set( Calendar.SECOND ,0 );
080
081 if( scope == 1 ) {
082 // false の確çŽ??高い方から、比è¼?�—ますã?
083 rtnFlag = day.get( Calendar.DATE ) == today.get( Calendar.DATE ) &&
084 day.get( Calendar.MONTH ) == today.get( Calendar.MONTH ) &&
085 day.get( Calendar.YEAR ) == today.get( Calendar.YEAR ) ;
086 }
087 else {
088 Calendar next = (Calendar)day.clone();
089 next.add( Calendar.DATE,scope );
090 rtnFlag = day.before( today ) && next.after( today ) ;
091 }
092 return rtnFlag ;
093 }
094
095 /**
096 * æŒ?®šã?開始ã?終äº?—¥の期間に、平日(稼働日)が何日あるか求めますã?
097 * start と end がã?リストç¯?›²外ã?場合ã?、エラーとしますã?
098 * 開始と終äº?�Œ同じ日の場合ã?ã€?¼‘を返しますã?
099 *
100 * @param start 開始日付け(稼働日に含めまã�?
101 * @param end 終äº?—¥付け(稼働日に含めまã�?
102 *
103 * @return 稼働日数
104 *
105 */
106 public int getKadoubisu( final Calendar start,final Calendar end ) {
107 long diff = start.getTimeInMillis() - end.getTimeInMillis() ;
108 int dayCount = (int)(diff/(1000*60*60*24)) + 1; // end も含ã‚??で?‹1å¿?¦?
109
110 Calendar tempDay = (Calendar)(start.clone());
111 int su = 0 ;
112 while( ! isHoliday( tempDay ) ) {
113 su++ ;
114 tempDay.add(Calendar.DATE, 1); // 日にちをé?めるã€?
115 }
116
117 int count = (( dayCount - su ) / 7 ) + 1;
118
119 return dayCount - count ;
120 }
121
122 /**
123 * æŒ?®šã?開始日に平日のみ期間を加算して求められる日付けを返しますã?
124 * これは、実稼働日計算に使用しますã?
125 * 例えば、start=20040810 , span=5 で、休日がなければã€?0,11,12,13,14 となりã?
126 * 20040815 を返しますã?
127 * æŒ?®šã?日付けã‚??期間åŠ?®—後ã?日付けがã?キャãƒ?‚·ュしてã�?‚‹ãƒ??タの
128 * æœ?¤§とæœ?°�ã?間に存在しなã�??合ã?、エラーとしますã?
129 *
130 * @param start 開始日付け(YYYYMMDD 形å¼?
131 * @param span 稼動期é–?
132 *
133 * @return 開始日から稼動期間をåŠ?®—した日付け(当日を含ã‚?
134 *
135 */
136 public Calendar getAfterDay( final Calendar start,final int span ) {
137 Calendar tempDay = (Calendar)(start.clone());
138 int suSpan = span ;
139 while( suSpan > 0 ) {
140 if( ! isHoliday( tempDay ) ) { suSpan--; }
141 tempDay.add(Calendar.DATE, 1); // 日にちをé?めるã€?
142 }
143 return tempDay ;
144 }
145
146 /**
147 * オブジェクトã?識別子として?Œ詳細なカレンãƒ?ƒ…報を返しますã?
148 *
149 * @return 詳細なカレンãƒ?ƒ…報
150 */
151 @Override
152 public String toString() {
153 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
154 rtn.append( "CLASS : ").append( getClass().getName() ).append( HybsSystem.CR ); // クラスå�?
155
156 return rtn.toString();
157 }
158 }