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 */ 016package org.opengion.hayabusa.resource; 017 018import static org.opengion.fukurou.system.HybsConst.CR ; // 6.1.0.0 (2014/12/26) 019import static org.opengion.fukurou.system.HybsConst.BUFFER_MIDDLE; // 6.1.0.0 (2014/12/26) refactoring 020 021import java.util.Calendar; 022 023/** 024 * 事業所(CDJGS) 毎の休日カレンダデータオブジェクトです。 025 * 026 * カレンダデータは、指定の事業所に関して、すべての休日情報を持っています。 027 * 元のカレンダテーブル(GE13)の 1日(DY1)~31日(DY31)までの日付け欄に対して、 028 * 休日日付けの 年月日 に対する、休日かどうかを判断できるだけの情報を保持します。 029 * 具体的には、年月日に対する Set を持つことになります。 030 * 031 * @og.rev 3.6.0.0 (2004/09/17) 新規作成 032 * @og.group リソース管理 033 * 034 * @version 4.0 035 * @author Hiroki Nakamura 036 * @since JDK5.0, 037 */ 038public abstract class AbstractCalendarPGData implements CalendarData { 039 040 /** 041 * このコンストラクタは、他のパッケージから呼び出せないように、 042 * パッケージプライベートにしておきます。 043 * 044 */ 045 AbstractCalendarPGData() { 046 // ここでは処理を行いません。 047 } 048 049 /** 050 * 指定の日付けから、範囲の間に、本日を含むかどうかを返します。 051 * 指定の日付けが、キャッシュしているデータの最大と最小の間に 052 * 存在しない場合は、常に false になります。 053 * 判定は、年月日の項目のみで比較し、時分秒は無視します。 054 * 055 * @og.rev 3.7.1.1 (2005/05/31) 新規追加 056 * @og.rev 3.8.8.6 (2007/04/20) today を毎回求めます。(キャッシュ対策) 057 * 058 * @param day 指定の開始日付け 059 * @param scope 範囲の日数 060 * 061 * @return 本日:true それ以外:false 062 */ 063 public boolean isContainedToday( final Calendar day,final int scope ) { 064 final boolean rtnFlag; 065 066 final Calendar today = Calendar.getInstance(); 067 today.set( Calendar.HOUR_OF_DAY ,12 ); // 昼にセット 068 today.set( Calendar.MINUTE ,0 ); 069 today.set( Calendar.SECOND ,0 ); 070 071 if( scope == 1 ) { 072 // false の確率の高い方から、比較します。 073 rtnFlag = day.get( Calendar.DATE ) == today.get( Calendar.DATE ) && 074 day.get( Calendar.MONTH ) == today.get( Calendar.MONTH ) && 075 day.get( Calendar.YEAR ) == today.get( Calendar.YEAR ) ; 076 } 077 else { 078 final Calendar next = (Calendar)day.clone(); 079 next.add( Calendar.DATE,scope ); 080 rtnFlag = day.before( today ) && next.after( today ) ; 081 } 082 return rtnFlag ; 083 } 084 085 /** 086 * 指定の開始、終了日の期間に、平日(稼働日)が何日あるか求めます。 087 * start と end が、リスト範囲外の場合は、エラーとします。 088 * 開始と終了が同じ日の場合は、1を返します。 089 * 090 * @param start 開始日付け(稼働日に含めます) 091 * @param end 終了日付け(稼働日に含めます) 092 * 093 * @return 稼働日数 094 * 095 */ 096 public int getKadoubisu( final Calendar start,final Calendar end ) { 097 final long diff = start.getTimeInMillis() - end.getTimeInMillis() ; 098 final int dayCount = (int)(diff/(1000*60*60*24)) + 1; // end も含むので+1必要 099 100 final Calendar tempDay = (Calendar)(start.clone()); 101 int su = 0 ; 102 while( ! isHoliday( tempDay ) ) { 103 su++ ; 104 tempDay.add(Calendar.DATE, 1); // 日にちを進める。 105 } 106 107 final int count = ( dayCount - su ) / 7 + 1; 108 109 return dayCount - count ; 110 } 111 112 /** 113 * 指定の開始日に平日のみ期間を加算して求められる日付けを返します。 114 * これは、実稼働日計算に使用します。 115 * 例えば、start=20040810 , span=5 で、休日がなければ、10,11,12,13,14 となり、 116 * 20040815 を返します。 117 * 指定の日付けや、期間加算後の日付けが、キャッシュしているデータの 118 * 最大と最小の間に存在しない場合は、エラーとします。 119 * 120 * @param start 開始日付け(YYYYMMDD 形式) 121 * @param span 稼動期間 122 * 123 * @return 開始日から稼動期間を加算した日付け(当日を含む) 124 * 125 */ 126 public Calendar getAfterDay( final Calendar start,final int span ) { 127 final Calendar tempDay = (Calendar)(start.clone()); 128 int suSpan = span ; 129 while( suSpan > 0 ) { 130 if( ! isHoliday( tempDay ) ) { suSpan--; } 131 tempDay.add(Calendar.DATE, 1); // 日にちを進める。 132 } 133 return tempDay ; 134 } 135 136 /** 137 * オブジェクトの識別子として,詳細なカレンダ情報を返します。 138 * 139 * @return 詳細なカレンダ情報 140 * @og.rtnNotNull 141 */ 142 @Override 143 public String toString() { 144 final StringBuilder rtn = new StringBuilder( BUFFER_MIDDLE ); 145 rtn.append( "CLASS : ").append( getClass().getName() ).append( CR ); // クラス名 146 147 return rtn.toString(); 148 } 149}