1. Push the time backwards
Public StaticDate Getnextworkingday (intPeriodthrowsdbexception {codemgr codemgr=(Codemgr) bizmgrregistry.getinstance (). Getbizmgr ("Com.leapii.code.bm.CodeMgr"); Collection publicholidaycollection=codemgr. Getcodebytype (Dormconstants.public_holiday); Calendar Currentday=calendar.getinstance (TimeZone. getTimeZone ("Gmt+08")); Currentday.settime (Dateutil.getdate ()); for(inti = 0; i < period; i++) { BooleanIspublicholiday =false; Currentday.set (Calendar.date, Currentday.get (calendar.date)+ 1); String Currendaystr=Dateutil.format (Currentday.gettime (),"YyyyMMdd"); System.out.println (CURRENDAYSTR); Iterator ITR=Publicholidaycollection.iterator (); while(Itr.hasnext ()) {Code Code=(Code) itr.next (); if(Code.getvalue (). Equals (Currendaystr)) {Ispublicholiday=true; Break; } } intDayOfWeek =Currentday.get (Calendar.day_of_week); if(Calendar.saturday = = DayOfWeek | | Calendar.sunday = =DayOfWeek||ispublicholiday) {System.out.println ("Weekend Or public Holiday"); Period= period + 1; } } returnCurrentday.gettime (); }
2. Push forward Time
Public StaticDate Getlastworkingday (intPeriodthrowsdbexception {codemgr codemgr=(Codemgr) bizmgrregistry.getinstance (). Getbizmgr ("Com.leapii.code.bm.CodeMgr"); Collection publicholidaycollection=codemgr. Getcodebytype (Dormconstants.public_holiday); Calendar Currentday=calendar.getinstance (TimeZone. getTimeZone ("Gmt+08")); Currentday.settime (Dateutil.getdate ()); for(inti = 0; i < period; i++) { BooleanIspublicholiday =false; Currentday.set (Calendar.date, Currentday.get (calendar.date)-1); String Currendaystr=Dateutil.format (Currentday.gettime (),"YyyyMMdd"); System.out.println (CURRENDAYSTR); Iterator ITR=Publicholidaycollection.iterator (); while(Itr.hasnext ()) {Code Code=(Code) itr.next (); if(Code.getvalue (). Equals (Currendaystr)) {Ispublicholiday=true; Break; } } intDayOfWeek =Currentday.get (Calendar.day_of_week); if(Calendar.saturday = = DayOfWeek | | Calendar.sunday = =DayOfWeek||ispublicholiday) {System.out.println ("Weekend Or public Holiday"); Period= period + 1; } } returnCurrentday.gettime (); }
Push forward time (excluding weekdays and holidays)