329. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/11/2019 10:54:17 AM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

329.1 Files compared

# Location File Last Modified
1 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\fw\util DateUtils.java Wed May 29 15:26:00 2019 UTC
2 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\fw\util DateUtils.java Mon Jun 10 19:27:47 2019 UTC

329.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 1620
Changed 1 2
Inserted 0 0
Removed 0 0

329.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

329.4 Active regular expressions

No regular expressions were active.

329.5 Comparison detail

  1   /********* ********** ********** ********** ********** ********** ********** **********
  2    * Copyrii ght 2004 V HA. All ri ghts reser ved
  3    ********* ********** ********** ********** ********** ********** ********** *********/
  4   // Package
  5   package go v.va.med.f w.util;
  6  
  7   // Java cl asses
  8   import jav a.text.Dat eFormat;
  9   import jav a.text.Par seExceptio n;
  10   import jav a.text.Par sePosition ;
  11   import jav a.text.Sim pleDateFor mat;
  12   import jav a.util.Cal endar;
  13   import jav a.util.Dat e;
  14   import jav a.util.Gre gorianCale ndar;
  15   import jav a.util.Tim eZone;
  16  
  17   import org .apache.co mmons.lang .Validate;
  18  
  19   import gov .va.med.fw .model.loo kup.Abstra ctCode;
  20  
  21   // ESR cla sses
  22  
  23   /**
  24    * Project : Framewor k</br>
  25    * Created  on: 10:10 :37 AM </b r>
  26    * 
  27    * @author   DN S
  28    */
  29   public cla ss DateUti ls extends  org.apach e.commons. lang.time. DateUtils  {
  30  
  31           //  Various d ate format ting const ants
  32           pu blic final  static St ring MM =  "MM";
  33           pu blic final  static St ring MMDD  = "MM/dd";
  34           pu blic final  static St ring YYYY  = "yyyy";
  35           pu blic final  static St ring MMYYY Y = "MM/yy yy";
  36           pu blic final  static St ring MMDDY YYY = "MM/ dd/yyyy";
  37           pu blic final  static St ring MMDDY YYYHHMMSS  = "MM/dd/y yyy h:mm:s sa";
  38           pu blic final  static St ring MMDDY YYYHHMM_ED IT = "MM/d d/yyyy HH: mm";
  39           pu blic final  static St ring EEEEM MMMDYYYY =  "EEEE, MM MM d, yyyy ";
  40           pu blic final  static St ring MMMDY YYY = "MMM  d, yyyy";
  41  
  42           pu blic stati c final Co de FIRST_Q UARTER = n ew Code("1 ");
  43           pu blic stati c final Co de SECOND_ QUARTER =  new Code(" 2");
  44           pu blic stati c final Co de THIRD_Q UARTER = n ew Code("3 ");
  45           pu blic stati c final Co de FOURTH_ QUARTER =  new Code(" 4");
  46  
  47           pu blic stati c final St ring[] FIS CAL_QUARTE RS = new S tring[] {  FIRST_QUAR TER.getCod e(), SECON D_QUARTER. getCode(),
  48                             THIRD_ QUARTER.ge tCode(), F OURTH_QUAR TER.getCod e() };
  49  
  50           pu blic stati c final in t MILISECO NDSPERDAY  = 1000 * 6 0 * 60 * 2 4;
  51  
  52           pu blic stati c class Co de extends  AbstractC ode {
  53  
  54                    /**
  55                     * A n instance  of serial VersionUID
  56                     */
  57                    priv ate static  final lon g serialVe rsionUID =  1L;
  58  
  59                    priv ate Code(S tring code ) {
  60                             super( code);
  61                    }
  62  
  63                    publ ic static  Code getBy Code(Strin g code) {
  64                             return  (Code) ge tCode(Code .class, co de);
  65                    }
  66           }
  67  
  68           /* *
  69            *  A default  construct or
  70            * /
  71           pr ivate Date Utils() {
  72                    supe r();
  73           }
  74  
  75           /* *
  76            *  Parse the  given str ing into a  Date obje ct.
  77            *  
  78            *  @param da te
  79            *  @param pa ttern
  80            *  @return
  81            *  @throws P arseExcept ion
  82            * /
  83           pu blic stati c Date par seDate(Str ing date,  String pat tern) thro ws ParseEx ception {
  84                    Stri ng[] patte rns = new  String[1];
  85                    patt erns[0] =  pattern;
  86                    retu rn DateUti ls.parseDa te(date, p atterns);
  87           }
  88  
  89           pu blic stati c Date par seDate(Str ing date,  String pat tern, Stri ng timeZon e) throws  ParseExcep tion {
  90                    Stri ng[] patte rns = new  String[1];
  91                    patt erns[0] =  pattern +  "z";
  92                    retu rn DateUti ls.parseDa te(date +  " " + time Zone, patt erns);
  93           }
  94  
  95           pu blic stati c Date par seDate(Str ing str, S tring patt ern, TimeZ one timeZo ne) throws  ParseExce ption {
  96                    Stri ng[] parse Patterns =  new Strin g[1];
  97                    pars ePatterns[ 0] = patte rn;
  98  
  99                    if ( str == nul l || parse Patterns = = null)
  100                             throw  new Illega lArgumentE xception(" Date and P atterns mu st not be  null");
  101                    Simp leDateForm at parser  = new Simp leDateForm at();
  102                    Pars ePosition  pos = new  ParsePosit ion(0);
  103                    for  (int i = 0 ; i < pars ePatterns. length; i+ +) {
  104                             if (i  == 0) {
  105                                      parser =  new Simpl eDateForma t(parsePat terns[0]);
  106                                      parser.s etTimeZone (timeZone) ;
  107                             } else
  108                                      parser.a pplyPatter n(parsePat terns[i]);
  109                             pos.se tIndex(0);
  110                             Date d ate = pars er.parse(s tr, pos);
  111                             if (da te != null  && pos.ge tIndex() = = str.leng th())
  112                                      return d ate;
  113                    }
  114  
  115                    thro w new Pars eException ("Unable t o parse th e date: "  + str, -1) ;
  116           }
  117           
  118           /* *
  119            *  Parse the  given str ing strict ly into a  Date objec t.
  120            *  Only will  parse if  the patter n matches  exactly.
  121            *  
  122            *  @param da te
  123            *  @param pa ttern
  124            *  @return
  125            *  @throws P arseExcept ion
  126            * /
  127           pu blic stati c Date par seDateStri ctly(Strin g date, St ring patte rn) throws  ParseExce ption {
  128                    retu rn org.apa che.common s.lang3.ti me.DateUti ls.parseDa teStrictly (date, pat tern);
  129           }
  130  
  131           /* *
  132            *  Formats a  date with  the speci fied forma t or a def ault forma t if null  is
  133            *  passed in  for the f ormat. The  default f ormat does  not inclu de a time.
  134            *  
  135            *  @param da te
  136            *              The date  to format .
  137            *  @param fo rmat
  138            *              An optio nal format .
  139            *  
  140            *  @return T he formatt ed date.
  141            * /
  142           pu blic stati c String f ormat(Date  date, Str ing format ) {
  143                    if ( date == nu ll) {
  144                             return  null;
  145                    }
  146                    if ( StringUtil s.isBlank( format)) {
  147                             format  = MMDDYYY Y;
  148                    }
  149                    Simp leDateForm at sdf = n ew SimpleD ateFormat( format);
  150                    sdf. setLenient (false);
  151                    retu rn sdf.for mat(date);
  152           }
  153  
  154           /*
  155            *  had to co py this fr om commons -lang 2.4  DateUtils  (addDays,  addWeeks,  etc)
  156            *  due to We bLogic bei ng a POC a nd requiri ng 2.1
  157            * /
  158           pu blic stati c Date add (Date date , int cale ndarField,  int amoun t) {
  159                    if ( date == nu ll)
  160                             throw  new Illega lArgumentE xception(" The date m ust not be  null");
  161  
  162                    Cale ndar c = C alendar.ge tInstance( );
  163                    c.se tTime(date );
  164                    c.ad d(calendar Field, amo unt);
  165                    retu rn c.getTi me();
  166           }
  167  
  168           pu blic stati c Calendar  createCal endar(Date  date) {
  169                    Cale ndar calen dar = Cale ndar.getIn stance();
  170                    cale ndar.clear ();
  171                    cale ndar.setTi me(date);
  172                    retu rn calenda r;
  173           }
  174  
  175           pu blic stati c Calendar  createCal endar(int  year) {
  176                    Cale ndar calen dar = Cale ndar.getIn stance();
  177                    cale ndar.clear ();
  178                    cale ndar.set(C alendar.YE AR, year);
  179                    retu rn calenda r;
  180           }
  181  
  182           pu blic stati c Calendar  createCal endar(int  year, int  month) {
  183                    Cale ndar calen dar = crea teCalendar (year);
  184                    cale ndar.set(C alendar.MO NTH, month  - 1);
  185                    retu rn calenda r;
  186           }
  187  
  188           pu blic stati c Calendar  createCal endar(int  year, int  month, int  day) {
  189                    Cale ndar calen dar = crea teCalendar (year, mon th);
  190                    cale ndar.set(C alendar.DA Y_OF_MONTH , day);
  191                    retu rn calenda r;
  192           }
  193  
  194           pu blic stati c Calendar  createCal endar(int  year, int  month, int  day, int  hour) {
  195                    Cale ndar calen dar = crea teCalendar (year, mon th, day);
  196                    cale ndar.set(C alendar.HO UR_OF_DAY,  hour);
  197                    retu rn calenda r;
  198           }
  199  
  200           pu blic stati c Calendar  createCal endar(int  year, int  month, int  day, int  hour, int  minute) {
  201                    Cale ndar calen dar = crea teCalendar (year, mon th, day, h our);
  202                    cale ndar.set(C alendar.MI NUTE, minu te);
  203                    retu rn calenda r;
  204           }
  205  
  206           pu blic stati c Calendar  createCal endar(int  year, int  month, int  day, int  hour, int  minute, in t second)  {
  207                    Cale ndar calen dar = crea teCalendar (year, mon th, day, h our, minut e);
  208                    cale ndar.set(C alendar.SE COND, seco nd);
  209                    retu rn calenda r;
  210           }
  211  
  212           pu blic stati c Calendar  createCal endar(int  year, int  month, int  day, int  hour, int  minute, in t second,
  213                             int mi llisecond)  {
  214                    Cale ndar calen dar = crea teCalendar (year, mon th, day, h our, minut e, second) ;
  215                    cale ndar.set(C alendar.MI LLISECOND,  milliseco nd);
  216                    retu rn calenda r;
  217           }
  218  
  219           pu blic stati c Calendar  getFiscal YearFirstQ uarter(int  year, boo lean start Date) {
  220                    Cale ndar time  = createCa lendar(yea r);
  221                    Greg orianCalen dar calend ar = new G regorianCa lendar(tim e.get(Cale ndar.YEAR) , time.get (Calendar. MONTH),
  222                                      time.get (Calendar. DATE));
  223                    if ( startDate)  {
  224                             calend ar.roll(Ca lendar.MON TH, -3);
  225                             calend ar.roll(Ca lendar.YEA R, -1);
  226                             return  calendar;
  227                    } el se {
  228                             calend ar.roll(Ca lendar.DAT E, -1);
  229                             calend ar.roll(Ca lendar.MON TH, -1);
  230                             calend ar.roll(Ca lendar.YEA R, -1);
  231                             return  calendar;
  232                    }
  233           }
  234  
  235           pu blic stati c Calendar  getFiscal YearSecond Quarter(in t year, bo olean star tDate) {
  236                    Cale ndar time  = createCa lendar(yea r);
  237                    Greg orianCalen dar calend ar = new G regorianCa lendar(tim e.get(Cale ndar.YEAR) , time.get (Calendar. MONTH),
  238                                      time.get (Calendar. DATE));
  239                    if ( startDate)  {
  240                             return  calendar;
  241                    } el se {
  242                             calend ar.roll(Ca lendar.MON TH, 2);
  243                             calend ar.set(Cal endar.DATE , 31);
  244                             return  calendar;
  245                    }
  246           }
  247  
  248           pu blic stati c Calendar  getFiscal YearThirdQ uarter(int  year, boo lean start Date) {
  249                    Cale ndar time  = createCa lendar(yea r);
  250                    Greg orianCalen dar calend ar = new G regorianCa lendar(tim e.get(Cale ndar.YEAR) , time.get (Calendar. MONTH),
  251                                      time.get (Calendar. DATE));
  252                    if ( startDate)  {
  253                             calend ar.roll(Ca lendar.MON TH, 3);
  254                             return  calendar;
  255                    } el se {
  256                             calend ar.roll(Ca lendar.MON TH, 5);
  257                             calend ar.set(Cal endar.DATE , 30);
  258                             return  calendar;
  259                    }
  260           }
  261  
  262           pu blic stati c Calendar  getFiscal YearFourth Quarter(in t year, bo olean star tDate) {
  263                    Cale ndar time  = createCa lendar(yea r);
  264                    Greg orianCalen dar calend ar = new G regorianCa lendar(tim e.get(Cale ndar.YEAR) , time.get (Calendar. MONTH),
  265                                      time.get (Calendar. DATE));
  266                    if ( startDate)  {
  267                             calend ar.roll(Ca lendar.MON TH, 6);
  268                             return  calendar;
  269                    } el se {
  270                             calend ar.roll(Ca lendar.MON TH, 8);
  271                             calend ar.set(Cal endar.DATE , 30);
  272                             return  calendar;
  273                    }
  274           }
  275  
  276           pu blic stati c Calendar  getFiscal YearQuarte r(int year , boolean  startDate,  String qu arter) {
  277                    Cale ndar calen dar = null ;
  278                    if ( FIRST_QUAR TER.getCod e().equals (quarter))  {
  279                             calend ar = getFi scalYearFi rstQuarter (year, sta rtDate);
  280                    } el se if (SEC OND_QUARTE R.getCode( ).equals(q uarter)) {
  281                             calend ar = getFi scalYearSe condQuarte r(year, st artDate);
  282                    } el se if (THI RD_QUARTER .getCode() .equals(qu arter)) {
  283                             calend ar = getFi scalYearTh irdQuarter (year, sta rtDate);
  284                    } el se if (FOU RTH_QUARTE R.getCode( ).equals(q uarter)) {
  285                             calend ar = getFi scalYearFo urthQuarte r(year, st artDate);
  286                    }
  287                    retu rn calenda r;
  288           }
  289  
  290           pu blic stati c int getF iscalYear( Date date)  {
  291                    Cale ndar calen dar = Cale ndar.getIn stance();
  292                    cale ndar.setTi me(date);
  293  
  294                    retu rn getFisc alYear(cal endar);
  295           }
  296  
  297           pu blic stati c int getF iscalYear( Calendar c alendar) {
  298                    Vali date.notNu ll(calenda r, "A cale ndar must  not be nul l");
  299  
  300                    int  year = cal endar.get( Calendar.Y EAR);
  301                    Date  start = g etFiscalYe arFirstQua rter(year,  true).get Time();
  302                    Date  end = get FiscalYear FourthQuar ter(year,  false).get Time();
  303                    Date  date = ca lendar.get Time();
  304  
  305                    if ( !(start.eq uals(date)  || start. before(dat e)) || !(e nd.equals( date) || e nd.after(d ate))) {
  306                             year + = 1;
  307                    }
  308                    retu rn year;
  309           }
  310  
  311           pu blic stati c boolean  isDateInYe ar(Integer  year, Dat e date) {
  312                    Vali date.notNu ll(year, " A year cod e must not  be null") ;
  313                    Vali date.notNu ll(date, " A date mus t not be n ull");
  314  
  315                    Cale ndar start  = Calenda r.getInsta nce();
  316                    star t.set(year .intValue( ), Calenda r.JANUARY,  1, 0, 0,  0);
  317  
  318                    Cale ndar end =  Calendar. getInstanc e();
  319                    end. set(year.i ntValue(),  Calendar. DECEMBER,  31, 23, 59 , 59);
  320  
  321                    retu rn isDateB etween(dat e, start.g etTime(),  end.getTim e());
  322  
  323           }
  324  
  325           pu blic stati c boolean  isDateBetw een(Date d ate, Date  start, Dat e end) {
  326                    bool ean inBetw een = fals e;
  327                    if ( (start.equ als(date)  || start.b efore(date )) && (end .equals(da te) || end .after(dat e))) {
  328                             inBetw een = true ;
  329                    }
  330                    retu rn inBetwe en;
  331           }
  332  
  333           pu blic stati c boolean  isDateBetw eenIgnoreT ime(Date d ate, Date  start, Dat e end) {
  334                    bool ean inBetw een = fals e;
  335                    if ( isEqualOrA fterIgnore Time(date,  start) &&  isEqualOr BeforeIgno reTime(dat e, end)) {
  336                             inBetw een = true ;
  337                    }
  338                    retu rn inBetwe en;
  339           }
  340  
  341           pu blic stati c String g etQuarterA sString(Da te date) {
  342  
  343                    retu rn getQuar ter(date)  + " Quarte r";
  344           }
  345  
  346           pu blic stati c String g etQuarter( Date date)  {
  347                    Stri ng quarter  = null;
  348                    for  (int i = 0 ; i < FISC AL_QUARTER S.length;  i++) {
  349                             if (is InQuarter( FISCAL_QUA RTERS[i],  date)) {
  350                                      quarter  = String.v alueOf((i  + 1));
  351                             }
  352                    }
  353                    retu rn quarter ;
  354           }
  355  
  356           pu blic stati c String g etQuarterD ateRangeAs String(Dat e date) {
  357  
  358                    Date Format df  = DateForm at.getDate Instance(D ateFormat. MEDIUM);
  359                    Cale ndar[] cal endars = n ull;
  360                    for  (int i = 0 ; i < FISC AL_QUARTER S.length;  i++) {
  361                             if (is InQuarter( FISCAL_QUA RTERS[i],  date)) {
  362                                      calendar s = getSta rtEndDateF orQuarter( FISCAL_QUA RTERS[i],  date);
  363                                      break;
  364                             }
  365                    }
  366                    retu rn calenda rs != null  ? (df.for mat(calend ars[0].get Time()) +  " - " + df .format(ca lendars[1] .getTime() ))
  367                                      : null;
  368           }
  369  
  370           pu blic stati c boolean  isInQuarte r(String q uarter, Da te date) {
  371                    Vali date.notNu ll(date, " A date mus t not be n ull");
  372                    Vali date.notNu ll(quarter , "A quart er code mu st not be  null");
  373                    Cale ndar[] cal endars = g etStartEnd DateForQua rter(quart er, date);
  374  
  375                    Date  start = c alendars[0 ].getTime( );
  376                    Date  end = cal endars[1]. getTime();
  377  
  378                    retu rn isDateB etween(dat e, start,  end);
  379           }
  380  
  381           pu blic stati c Calendar [] getStar tEndDateFo rQuarter(S tring quar ter, Date  date) {
  382  
  383                    Cale ndar[] cal endars = n ew Calenda r[2];
  384                    int  year = get FiscalYear (date);
  385                    for  (int i = 0 ; i < FISC AL_QUARTER S.length;  i++) {
  386                             if (FI SCAL_QUART ERS[i].equ als(quarte r)) {
  387                                      calendar s[0] = get FiscalYear Quarter(ye ar, true,  FISCAL_QUA RTERS[i]);
  388                                      calendar s[1] = get FiscalYear Quarter(ye ar, false,  FISCAL_QU ARTERS[i]) ;
  389                                      break;
  390                             }
  391                    }
  392                    retu rn calenda rs;
  393           }
  394  
  395           pu blic stati c int getQ uarterNumb er(Date da te) {
  396                    int  quarter =  0;
  397                    if ( date != nu ll) {
  398                             for (i nt i = 0;  i < FISCAL _QUARTERS. length; i+ +) {
  399                                      if (isIn Quarter(FI SCAL_QUART ERS[i], da te)) {
  400                                               quarter =  i + 1;
  401                                      }
  402                             }
  403                    }
  404                    retu rn quarter ;
  405           }
  406  
  407           pu blic stati c Calendar [] getStar tEndDateFo rPreviousQ uarter(Dat e date) {
  408  
  409                    Cale ndar[] cal endars = n ew Calenda r[2];
  410                    if ( date != nu ll) {
  411                             int pr eviousQuar ter = 0;
  412                             int cu rrentQuart er = getQu arterNumbe r(date);
  413                             int ye ar = getFi scalYear(d ate);
  414                             if (St ring.value Of(current Quarter).e quals(FIRS T_QUARTER. getCode()) ) {
  415                                      year = y ear - 1;
  416                                      previous Quarter =  4;
  417                             } else  {
  418                                      previous Quarter =  currentQua rter - 1;
  419                             }
  420                             calend ars[0] = g etFiscalYe arQuarter( year, true , String.v alueOf(pre viousQuart er));
  421                             calend ars[1] = g etFiscalYe arQuarter( year, fals e, String. valueOf(pr eviousQuar ter));
  422                    }
  423                    retu rn calenda rs;
  424           }
  425  
  426           pu blic stati c Calendar [] getStar tEndDateFo rFiscalYea r(Date dat e) {
  427  
  428                    Cale ndar[] cal endars = n ew Calenda r[2];
  429                    if ( date != nu ll) {
  430                             int ye ar = getFi scalYear(d ate);
  431                             calend ars[0] = g etFiscalYe arQuarter( year, true , FIRST_QU ARTER.getC ode());
  432                             calend ars[1] = g etFiscalYe arQuarter( year, fals e, FOURTH_ QUARTER.ge tCode());
  433                    }
  434                    retu rn calenda rs;
  435           }
  436  
  437           pu blic stati c Calendar [] getStar tEndDateFo rPreviousF iscalYear( Date date)  {
  438  
  439                    Cale ndar[] cal endars = n ew Calenda r[2];
  440                    if ( date != nu ll) {
  441                             int ye ar = getFi scalYear(d ate);
  442                             calend ars[0] = g etFiscalYe arQuarter( year - 1,  true, FIRS T_QUARTER. getCode()) ;
  443                             calend ars[1] = g etFiscalYe arQuarter( year - 1,  false, FOU RTH_QUARTE R.getCode( ));
  444                    }
  445                    retu rn calenda rs;
  446           }
  447  
  448           //  public st atic Calen dar[] getS tartEndDat eForPrevio usMonth( D ate date )  {
  449           //
  450           //  Calendar[ ] calendar s = new Ca lendar[2];
  451           //  if(date!= null)
  452           //  {
  453           //  Calendar  calendar =  Calendar. getInstanc e();
  454           //  calendar. setTime( d ate );
  455           //  //IF mont h is Jan r oll year a lso.
  456           //  if(calend ar.get(Cal endar.MONT H)==0)
  457           //  calendar. roll( Cale ndar.YEAR,  -1 );
  458           //  calendar. roll( Cale ndar.MONTH , -1 );
  459           //  calendars [0]=create Calendar(c alendar.ge t(Calendar .YEAR),
  460           //  calendar. get(Calend ar.MONTH)+ 1, 1);
  461           //  calendars [1]=create Calendar(c alendar.ge t(Calendar .YEAR),
  462           //  calendar. get(Calend ar.MONTH)+ 1,
  463           //  calendar. getActualM aximum(Cal endar.DAY_ OF_MONTH)) ;
  464           //  }
  465           //
  466           //  return ca lendars;
  467           //  }
  468  
  469           pu blic stati c Calendar [] getStar tEndDateFo rPreviousM onth(Date  date) {
  470  
  471                    Cale ndar[] cal endars = n ew Calenda r[2];
  472                    if ( date != nu ll) {
  473                             Calend ar calenda r = Calend ar.getInst ance();
  474                             calend ar.setTime (date);
  475                             int mo nth = cale ndar.get(C alendar.MO NTH);
  476                             calend ar.set(Cal endar.MONT H, month -  1);
  477                             calend ars[0] = c reateCalen dar(calend ar.get(Cal endar.YEAR ), calenda r.get(Cale ndar.MONTH ) + 1, 1);
  478                             calend ars[1] = c reateCalen dar(calend ar.get(Cal endar.YEAR ), calenda r.get(Cale ndar.MONTH ) + 1,
  479                                               calendar.g etActualMa ximum(Cale ndar.DAY_O F_MONTH));
  480                    }
  481  
  482                    retu rn calenda rs;
  483           }
  484  
  485           pu blic stati c Calendar [] getStar tEndDateFo rPreviousW eek(Date d ate) {
  486                    Cale ndar[] cal endars = n ew Calenda r[2];
  487                    if ( date != nu ll) {
  488                             Calend ar calenda r = Calend ar.getInst ance();
  489                             calend ar.setTime (date);
  490                             calend ar.set(Cal endar.DAY_ OF_WEEK, C alendar.SU NDAY);
  491                             int we ekOfMonth  = calendar .get(Calen dar.WEEK_O F_MONTH);
  492                             calend ar.set(Cal endar.WEEK _OF_MONTH,  weekOfMon th - 1);
  493                             calend ars[0] = c reateCalen dar(calend ar.get(Cal endar.YEAR ), calenda r.get(Cale ndar.MONTH ) + 1,
  494                                               calendar.g et(Calenda r.DAY_OF_M ONTH));
  495                             calend ar.set(Cal endar.DAY_ OF_WEEK, C alendar.SA TURDAY);
  496                             calend ars[1] = c reateCalen dar(calend ar.get(Cal endar.YEAR ), calenda r.get(Cale ndar.MONTH ) + 1,
  497                                               calendar.g et(Calenda r.DAY_OF_M ONTH));
  498                    }
  499  
  500                    retu rn calenda rs;
  501           }
  502  
  503           pu blic stati c Date get CurrentDat e() {
  504                    Cale ndar calen dar = Cale ndar.getIn stance();
  505                    int  year = cal endar.get( Calendar.Y EAR);
  506                    int  month = ca lendar.get (Calendar. MONTH);
  507                    int  day = cale ndar.get(C alendar.DA TE);
  508                    cale ndar.clear ();
  509                    cale ndar.set(y ear, month , day);
  510                    retu rn calenda r.getTime( );
  511           }
  512  
  513           pu blic stati c Date get WeekDate()  {
  514                    Cale ndar calen dar = Cale ndar.getIn stance();
  515                    cale ndar.setTi me(getCurr entDate()) ;
  516  
  517                    swit ch (calend ar.get(Cal endar.DAY_ OF_WEEK))  {
  518                    case  Calendar. SATURDAY:
  519                             calend ar.roll(Ca lendar.DAT E, 2);
  520                    case  Calendar. SUNDAY:
  521                             calend ar.roll(Ca lendar.DAT E, 1);
  522                    }
  523                    retu rn calenda r.getTime( );
  524           }
  525  
  526           /* *
  527            *  Returns d ate with t he time pr esent
  528            *  
  529            *  @return t he current  date and  time
  530            * /
  531           pu blic stati c Date get CurrentDat eTime() {
  532                    Cale ndar calen dar = Cale ndar.getIn stance();
  533                    retu rn calenda r.getTime( );
  534           }
  535  
  536           pu blic stati c Date get YesterdayD ate() {
  537                    Cale ndar calen dar = Cale ndar.getIn stance();
  538                    cale ndar.add(C alendar.DA TE, -1);
  539                    int  year = cal endar.get( Calendar.Y EAR);
  540                    int  month = ca lendar.get (Calendar. MONTH);
  541                    int  day = cale ndar.get(C alendar.DA TE);
  542                    cale ndar.clear ();
  543                    cale ndar.set(y ear, month , day);
  544                    retu rn calenda r.getTime( );
  545           }
  546  
  547           pu blic stati c Date get TomorrowDa te() {
  548                    Cale ndar calen dar = Cale ndar.getIn stance();
  549                    cale ndar.add(C alendar.DA TE, 1);
  550                    int  year = cal endar.get( Calendar.Y EAR);
  551                    int  month = ca lendar.get (Calendar. MONTH);
  552                    int  day = cale ndar.get(C alendar.DA TE);
  553                    cale ndar.clear ();
  554                    cale ndar.set(y ear, month , day);
  555                    retu rn calenda r.getTime( );
  556           }
  557  
  558           /* *
  559            *  Compare i f the firs t date is  before the  second da te. In cas e of null
  560            *  value, no t-null dat e value wi ll get a p reference.  For examp le, if the
  561            *  first dat e is null,  false is  returned.  If the sec ond date i s null, fi rst
  562            *  is consid ered after  first, so  true is r eturned.
  563            *  
  564            *  @param da te1
  565            *              the firs t date
  566            *  @param da te2
  567            *              the seco nd date
  568            *  @return t rue if the  first dat e is after  second da te.
  569            * /
  570           pu blic stati c boolean  isBefore(D ate date1,  Date date 2) {
  571                    bool ean compar e = false;
  572                    if ( date1 != n ull && dat e2 != null ) {
  573                             compar e = date1. before(dat e2);
  574                    } el se if (dat e1 != null ) {
  575                             compar e = true;
  576                    } el se if (dat e2 != null ) {
  577                             compar e = false;
  578                    }
  579                    retu rn compare ;
  580           }
  581  
  582           pu blic stati c boolean  isBeforeIg noreTime(D ate date1,  Date date 2) {
  583                    // u se consist ent logic  as in isBe fore
  584                    if ( date1 == n ull && dat e2 == null )
  585                             return  false;
  586                    else  if (date2  == null)
  587                             return  true;
  588                    else  if (date1  == null)
  589                             return  false;
  590  
  591                    retu rn isBefor e(truncate (date1, Ca lendar.DAY _OF_MONTH) , truncate (date2, Ca lendar.DAY _OF_MONTH) );
  592           }
  593  
  594           pu blic stati c boolean  isEqualOrB eforeIgnor eTime(Date  date1, Da te date2)  {
  595                    // u se consist ent logic  as in isBe fore
  596                    if ( date1 == n ull && dat e2 == null )
  597                             return  true; //  true since  equals
  598                    else  if (date2  == null)
  599                             return  true;
  600                    else  if (date1  == null)
  601                             return  false;
  602  
  603                    retu rn isSameD ayIgnoreTi me(date1,  date2) ||  isBeforeIg noreTime(d ate1, date 2);
  604           }
  605  
  606           pu blic stati c boolean  isEqualOrB efore(Date  date1, Da te date2)  {
  607                    // u se consist ent logic  as in isBe fore
  608                    if ( date1 == n ull && dat e2 == null )
  609                             return  true; //  true since  equals
  610                    else  if (date2  == null)
  611                             return  true;
  612                    else  if (date1  == null)
  613                             return  false;
  614  
  615                    retu rn isSameD ay(date1,  date2) ||  isBefore(d ate1, date 2);
  616           }
  617  
  618           /* *
  619            *  Compare i f the firs t date is  after the  second dat e. In case  of null
  620            *  value, no t-null dat e value wi ll get a p reference.  For examp le, if the
  621            *  first dat e is null,  false is  returned.  If the sec ond date i s null, fi rst
  622            *  is consid ered after  first, so  true is r eturned.
  623            *  
  624            *  @param da te1
  625            *              the firs t date
  626            *  @param da te2
  627            *              the seco nd date
  628            *  @return t rue if the  first dat e is after  second da te.
  629            * /
  630           pu blic stati c boolean  isAfter(Da te date1,  Date date2 ) {
  631                    bool ean compar e = false;
  632                    if ( date1 != n ull && dat e2 != null ) {
  633                             compar e = date1. after(date 2);
  634                    } el se if (dat e1 != null ) {
  635                             compar e = true;
  636                    } el se if (dat e2 != null ) {
  637                             compar e = false;
  638                    }
  639                    retu rn compare ;
  640           }
  641  
  642           pu blic stati c boolean  isAfterIgn oreTime(Da te date1,  Date date2 ) {
  643                    // u se consist ent logic  as in isAf ter
  644                    if ( date1 == n ull && dat e2 == null )
  645                             return  false;
  646                    else  if (date2  == null)
  647                             return  true;
  648                    else  if (date1  == null)
  649                             return  false;
  650  
  651                    retu rn isAfter (truncate( date1, Cal endar.DAY_ OF_MONTH),  truncate( date2, Cal endar.DAY_ OF_MONTH)) ;
  652           }
  653  
  654           pu blic stati c boolean  isEqualOrA fterIgnore Time(Date  date1, Dat e date2) {
  655                    // u se consist ent logic  as in isAf ter
  656                    if ( date1 == n ull && dat e2 == null )
  657                             return  true; //  true since  equals
  658                    else  if (date2  == null)
  659                             return  true;
  660                    else  if (date1  == null)
  661                             return  false;
  662  
  663                    retu rn isSameD ayIgnoreTi me(date1,  date2) ||  isAfterIgn oreTime(da te1, date2 );
  664           }
  665  
  666           pu blic stati c boolean  isSameDayI gnoreTime( Date date1 , Date dat e2) {
  667                    retu rn isSameD ay(truncat e(date1, C alendar.DA Y_OF_MONTH ), truncat e(date2, C alendar.DA Y_OF_MONTH ));
  668           }
  669  
  670           pu blic stati c boolean  isEqualOrA fter(Date  date1, Dat e date2) {
  671                    // u se consist ent logic  as in isAf ter
  672                    if ( date1 == n ull && dat e2 == null )
  673                             return  true; //  true since  equals
  674                    else  if (date2  == null)
  675                             return  true;
  676                    else  if (date1  == null)
  677                             return  false;
  678  
  679                    retu rn isSameD ay(date1,  date2) ||  isAfter(da te1, date2 );
  680           }
  681  
  682           pu blic stati c Date get YearStartD ate(int ye ar) {
  683                    Cale ndar cal =  Calendar. getInstanc e();
  684                    cal. clear();
  685                    cal. set(year,  Calendar.J ANUARY, 1) ;
  686                    retu rn cal.get Time();
  687           }
  688  
  689           pu blic stati c Date get YearEndDat e(int year ) {
  690                    Cale ndar cal =  Calendar. getInstanc e();
  691                    cal. clear();
  692                    cal. set(year,  11, 31);
  693                    retu rn cal.get Time();
  694           }
  695  
  696           pu blic stati c Date get AddedDate( int field,  int amoun t) {
  697                    Cale ndar time  = Calendar .getInstan ce();
  698                    retu rn getAdde dDate(fiel d, amount,  time);
  699  
  700           }
  701  
  702           pu blic stati c Date get AddedDate( int field,  int amoun t, Calenda r time) {
  703                    Greg orianCalen dar calend ar = new G regorianCa lendar(tim e.get(Cale ndar.YEAR) , time.get (Calendar. MONTH),
  704                                      time.get (Calendar. DATE), tim e.get(Cale ndar.HOUR_ OF_DAY), t ime.get(Ca lendar.MIN UTE),
  705                                      time.get (Calendar. SECOND));
  706                    cale ndar.add(f ield, amou nt);
  707                    retu rn calenda r.getTime( );
  708  
  709           }
  710  
  711           pu blic stati c Date cle arTime(Dat e date) {
  712                    if ( date == nu ll)
  713                             return  null;
  714  
  715                    Cale ndar calen dar = Cale ndar.getIn stance();
  716                    cale ndar.clear ();
  717                    cale ndar.setTi me(date);
  718                    cale ndar.clear (Calendar. HOUR);
  719                    cale ndar.clear (Calendar. MINUTE);
  720                    cale ndar.clear (Calendar. SECOND);
  721                    cale ndar.clear (Calendar. MILLISECON D);
  722                    retu rn calenda r.getTime( );
  723           }
  724  
  725           pu blic stati c Date get DateTodayP lusDays(in t days) {
  726                    Cale ndar calen dar = Cale ndar.getIn stance();
  727                    int  year = cal endar.get( Calendar.Y EAR);
  728                    int  month = ca lendar.get (Calendar. MONTH);
  729                    int  day = cale ndar.get(C alendar.DA TE) + days ;
  730                    cale ndar.clear ();
  731                    cale ndar.set(y ear, month , day);
  732                    retu rn calenda r.getTime( );
  733           }
  734  
  735           pu blic stati c Date for wardBusine ssDays(Dat e start, i nt busines sDays) {
  736  
  737                    Cale ndar cld =  Calendar. getInstanc e();
  738                    cld. setTime(st art);
  739                    if ( start != n ull && bus inessDays  > 0) {
  740                             for (i nt i = 0;  i < busine ssDays; i+ +) {
  741                                      add(cld) ;
  742                             }
  743                    }
  744                    retu rn cld.get Time();
  745           }
  746  
  747           /* *
  748            *  Increment  calendar  date 
  749            *  If weekda y, increme nt by one
  750            *  If Saturd ay, increm ent by two
  751            *  If Sunday , incremen t by one
  752            *  @param cl d
  753            * /
  754           pu blic stati c void add (Calendar  cld) {
  755                    
  756                    cld. add(Calend ar.DATE, 1 );
  757                    // N ot Sunday  (0) and Sa turday (6)
  758                    if(c ld.get(Cal endar.DAY_ OF_WEEK) = = Calendar .SATURDAY)  {
  759                             cld.ad d(Calendar .DATE, 2);
  760                    }
  761                    else  if(cld.ge t(Calendar .DAY_OF_WE EK) == Cal endar.SUND AY) {
  762                             cld.ad d(Calendar .DATE, 1);
  763                    }                 
  764           }
  765           pu blic stati c int getE lapsedBusi nessDays(D ate start,  Date end)  {
  766  
  767                    int  numberOfDa ys = 0;
  768  
  769                    Cale ndar cld =  Calendar. getInstanc e();
  770                    cld. setTime(st art);
  771                    whil e (cld.get Time().bef ore(end) & & start !=  null && e nd != null ) {
  772  
  773                             // inc rement dat e by a day
  774                             cld.ad d(Calendar .DATE, 1);
  775  
  776                             // if  day is bet ween Monda y and Frid ay, add on e day
  777                             if (cl d.get(Cale ndar.DAY_O F_WEEK) >=  Calendar. MONDAY &&  cld.get(Ca lendar.DAY _OF_WEEK)  <= Calenda r.FRIDAY)  {
  778                                      numberOf Days++;
  779                             }
  780                    }
  781                    retu rn numberO fDays;
  782  
  783                    // i n the futu re conside r below wh ich doesn' t require  a loop - C PB
  784  
  785                    // s tatic long  days(Date  start, Da te end){
  786                    //
  787                    // C alendar c1  = Gregori anCalendar .getInstan ce();
  788                    // c 1.setTime( start);
  789                    // i nt w1 = c1 .get(Calen dar.DAY_OF _WEEK);
  790                    // c 1.add(Cale ndar.DAY_O F_WEEK, -w 1 + 1);
  791                    //
  792                    // C alendar c2  = Gregori anCalendar .getInstan ce();
  793                    // c 2.setTime( end);
  794                    // i nt w2 = c2 .get(Calen dar.DAY_OF _WEEK);
  795                    // c 2.add(Cale ndar.DAY_O F_WEEK, -w 2 + 1);
  796                    //
  797                    // / /end Satur day to sta rt Saturda y
  798                    // l ong days =
  799                    // ( c2.getTime InMillis() -c1.getTim eInMillis( ))/(1000*6 0*60*24);
  800                    // l ong daysWi thoutSunda y = days-( days*2/7);
  801                    //
  802                    // i f (w1 == C alendar.SU NDAY) {
  803                    // w 1 = Calend ar.MONDAY;
  804                    // }
  805                    // i f (w2 == C alendar.SU NDAY) {
  806                    // w 2 = Calend ar.MONDAY;
  807                    // }
  808                    // r eturn days WithoutSun day-w1+w2;
  809                    // }
  810           }
  811   }