edittime.java

来自「一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。」· Java 代码 · 共 219 行

JAVA
219
字号
package jp.co.sjts.gsession.timecard;

import java.util.StringTokenizer;
import java.text.DecimalFormat;

/**
 * <P>嬫愗傝帪娫偵曄姺偡傞娭悢  EditTime.java
 * <P>Copyright (C) 1999-2000 Japan Total System Co,LTD
 *
 * @author  Yuuichirou Ohba  &lt;ohba@sjts.co.jp&gt;
 */
public class EditTime{
	String First=null;
	String End=null;
	String time=null;
	
	/**
	 * <P>擇寘偵曄姺
	 *
	 * @param  one  曄姺慜偺int僨乕僞 
	 * @return two  曄姺屻偺僨乕僞(String)丅 
	 */
	static public String getHH(int one) {
		DecimalFormat df = new DecimalFormat("00");
		String two = df.format(one);
		return two;
	}

	/**
	 * <P>擇寘埲忋偵曄姺
	 *
	 * @param  one  曄姺慜偺int僨乕僞 
	 * @return two  曄姺屻偺僨乕僞(String)丅 
	 */
	static public String getKeta(int one) {
		DecimalFormat df = new DecimalFormat("00");
		String two = null;
		if(10>one){
			two = df.format(one);
		}else{
			two = Integer.toString(one);
		}
		return two;
	}
	
	/**
	 * <P>娗棟幰愝掕偺嬫愗傝帪娫偵懳墳偝偣偰奐巒帪娫傪曄姺(愗傝忋偘張棟)
	 *
	 * @param  First  曄姺偡傞奐巒帪娫 
	 * @param  time   娗棟幰愝掕偺嬫愗傝帪娫 
	 * @return  曄姺屻偺奐巒帪娫僨乕僞(String) 奩摉偡傞僨乕僞偑嬻偺帪偼"<BR>"傪偐偊偡丅 
	 */
	static public String editFirst(String First,String time){
		
		String fh = null;
		String fm = null;
		String fmin = null;
		boolean chk1 = false;
		
		if(!(First).equals("丂")){                /* 弌幮僨乕僞偼偁傞偐丠*/
			StringTokenizer st = new StringTokenizer(First,":");
			fh = st.nextToken();
			fm = st.nextToken();
		}else{
			fh = "丂";
			fm = "丂";
			chk1 = true;
		}
		
		switch(Integer.parseInt(time)) {
		case 60:{
			if(chk1==true)
				break;
			if(!(fm).equals("00")){
				fh = Integer.toString(Integer.parseInt(fh)+1);
				fm = "00";
			}
			fh = getHH(Integer.parseInt(fh));
			break;
		}
		case 30:{
			if(chk1==true) 
				break;
			if(0==Integer.parseInt(fm)){
				fmin = "00";
			}
			if(0<Integer.parseInt(fm))
				fmin = "30";
			if(30<Integer.parseInt(fm)){
				fh = Integer.toString(Integer.parseInt(fh)+1);	
				fmin = "00";
			}
			fh = getHH(Integer.parseInt(fh));
			fm = fmin;
			break;
		}
		case 15:{
			if(chk1==true)
				break;
			if(0 == Integer.parseInt(fm)){fmin = "00";}
			if(0 < Integer.parseInt(fm)){fmin = "15";}
			if(15 < Integer.parseInt(fm)){fmin = "30"; }
			if(30 < Integer.parseInt(fm)){fmin = "45";}
			if(45 < Integer.parseInt(fm)){
				fh = Integer.toString(Integer.parseInt(fh)+1);	
				fmin = "00";
			}
			fh = getHH(Integer.parseInt(fh));
			fm = fmin;
			break;
		}
		case 10:{
			if(chk1==true)
				break;
			if(0 == Integer.parseInt(fm)){fmin = "00";}
			if(0 < Integer.parseInt(fm)){fmin = "10";}
			if(10 < Integer.parseInt(fm)){fmin = "20";}
			if(20 < Integer.parseInt(fm)){fmin = "30";}
			if(30 < Integer.parseInt(fm)){fmin = "40";}
			if(40 < Integer.parseInt(fm)){fmin = "50";}
			if(50 < Integer.parseInt(fm)){
				fh = Integer.toString(Integer.parseInt(fh)+1);	
				fmin = "00";
			}
			fh = getHH(Integer.parseInt(fh));
			fm = fmin;
			break;
		}
		case 1:{break;}
		}

		String Start = "NULL";
		if(((fh).equals("丂")) || ((fm).equals("丂"))){
			Start = "<BR>";
		}else{
			Start = fh+":"+fm;
		}
		return Start;
	}

	/**
	 * <P>娗棟幰愝掕偺嬫愗傝帪娫偵懳墳偝偣偰廔椆帪娫傪曄姺(愗傝幪偰張棟)
	 *
	 * @param  End    曄姺偡傞廔椆帪娫     
	 * @param  time   娗棟幰愝掕偺嬫愗傝帪娫 
	 * @return  曄姺屻偺廔椆帪娫僨乕僞(String) 奩摉偡傞僨乕僞偑嬻偺帪偼"<BR>"傪偐偊偡丅 
	 */
	static public String editEnd(String End,String time){

		String eh = null;
		String em = null;
		String emin = null;
		boolean chk2 =false;

		if(!(End).equals("丂")){                  /* 戅幮僨乕僞偼偁傞偐丠*/
			StringTokenizer st = new StringTokenizer(End,":");
			eh = st.nextToken();
			em = st.nextToken();
		}else{
			eh = "丂";
			em = "丂";
			chk2 = true;
		}

		switch(Integer.parseInt(time)){
		case 60:{
			if(chk2!=true){
				if(!(em).equals("00"))
					em = "00";
			}
			break;
		}
		case 30:{
			if(chk2!=true){
				if(Integer.parseInt(em)<30){
					em = "00";
				}else{
					em = "30";
				}
			}
			break;
		}
		case 15:{
			if(chk2!=true){
				if(0 == Integer.parseInt(em)){emin = "00";}
				if(15 > Integer.parseInt(em)){emin = "00";}
				if(15 <= Integer.parseInt(em)){emin = "15";}
				if(30 <= Integer.parseInt(em)){emin = "30";}
				if(45 <= Integer.parseInt(em)){emin = "45";}
				em = emin;
			}
			break;
		}
		case 10:{
			if(chk2!=true){
				if(0 == Integer.parseInt(em)){emin = "00";}
				if(10 > Integer.parseInt(em)){emin = "00";}
				if(10 <= Integer.parseInt(em)){emin = "10";}
				if(20 <= Integer.parseInt(em)){emin = "20";}
				if(30 <= Integer.parseInt(em)){emin = "30";}
				if(40 <= Integer.parseInt(em)){emin = "40";}
				if(50 <= Integer.parseInt(em)){emin = "50";}
				em = emin;
			}
			break;
		}
		case 1:{break;}
		}
		
		String Stop = "NULL";
		if((eh).equals("丂") || (em).equals("丂")){
			Stop = "<BR>";
		}else{
			Stop = eh+":"+em;
		}
		return Stop;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?