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)?žï¼“1日(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 ã‚‚å«ã‚??ã§?‹ï¼‘å¿?¦?
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 }