commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevencasw...@apache.org
Subject cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang/time DateUtils.java
Date Sun, 11 Jul 2004 18:40:04 GMT
stevencaswell    2004/07/11 11:40:04

  Modified:    lang/src/java/org/apache/commons/lang/time DateUtils.java
  Log:
  moved parseCVS to sandbox DateFormatter.java
  
  Revision  Changes    Path
  1.22      +1 -121    jakarta-commons/lang/src/java/org/apache/commons/lang/time/DateUtils.java
  
  Index: DateUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/time/DateUtils.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- DateUtils.java	5 Jul 2004 18:07:44 -0000	1.21
  +++ DateUtils.java	11 Jul 2004 18:40:04 -0000	1.22
  @@ -394,126 +394,6 @@
   
       }
   
  -    // TODO: Decide whether this code is removed or goes into 2.1
  -    //-----------------------------------------------------------------------
  -    /*
  -     * <p>Parses a date string formatted in CVS format.</p>
  -     * 
  -     * @param dateStr  the date to parse
  -     * @return the parsed date
  -     * @throws IllegalArgumentException if the date cannot be parsed
  -    public static Calendar parseCVS(String dateStr) {
  -        if (dateStr == null) {
  -            throw new IllegalArgumentException("The date must not be null");
  -        }
  -        //Get the symbol names
  -        DateFormatSymbols symbols = new DateFormatSymbols(Locale.ENGLISH);
  -
  -        //Prep the string to parse
  -        String value = dateStr.toLowerCase().trim();
  -
  -        //Get the current date/time
  -        Calendar now = Calendar.getInstance();
  -        if (value.endsWith(" ago")) {
  -            //If this was a date that was "ago" the current time...
  -            //Strip out the ' ago' part
  -            value = value.substring(0, value.length() - 4);
  -
  -            //Split the value and unit
  -            int start = value.indexOf(" ");
  -            if (start < 0) {
  -                throw new IllegalArgumentException("Could not find space in between value
and unit");
  -            }
  -            String unit = value.substring(start + 1);
  -            value = value.substring(0, start);
  -            //We support "a week", so we need to parse the value as "a"
  -            int val = 0;
  -            if (value.equals("a") || value.equals("an")) {
  -                val = 1;
  -            } else {
  -                val = Integer.parseInt(value);
  -            }
  -
  -            //Determine the unit
  -            if (unit.equals("milliseconds") || unit.equals("millisecond")) {
  -                now.add(Calendar.MILLISECOND, -val);
  -            } else if (unit.equals("seconds") || unit.equals("second")) {
  -                now.add(Calendar.SECOND, -val);
  -            } else if (unit.equals("minutes") || unit.equals("minute")) {
  -                now.add(Calendar.MINUTE, -val);
  -            } else if (unit.equals("hours") || unit.equals("hour")) {
  -                now.add(Calendar.HOUR, -val);
  -            } else if (unit.equals("days") || unit.equals("day")) {
  -                now.add(Calendar.DATE, -val);
  -            } else if (unit.equals("weeks") || unit.equals("week")) {
  -                now.add(Calendar.DATE, -val * 7);
  -            } else if (unit.equals("fortnights") || unit.equals("fortnight")) {
  -                now.add(Calendar.DATE, -val * 14);
  -            } else if (unit.equals("months") || unit.equals("month")) {
  -                now.add(Calendar.MONTH, -val);
  -            } else if (unit.equals("years") || unit.equals("year")) {
  -                now.add(Calendar.YEAR, -val);
  -            } else {
  -                throw new IllegalArgumentException("We do not understand that many units
ago");
  -            }
  -            return now;
  -        } else if (value.startsWith("last ")) {
  -            //If this was the last time a certain field was met
  -            //Strip out the 'last ' part
  -            value = value.substring(5);
  -            //Get the current date/time
  -            String[] strings = symbols.getWeekdays();
  -            for (int i = 0; i < strings.length; i++) {
  -                if (value.equalsIgnoreCase(strings[i])) {
  -                    //How many days after Sunday
  -                    int daysAgo = now.get(Calendar.DAY_OF_WEEK) - i;
  -                    if (daysAgo <= 0) {
  -                        daysAgo += 7;
  -                    }
  -                    now.add(Calendar.DATE, -daysAgo);
  -                    return now;
  -                }
  -            }
  -            strings = symbols.getMonths();
  -            for (int i = 0; i < strings.length; i++) {
  -                if (value.equalsIgnoreCase(strings[i])) {
  -                    //How many days after January
  -                    int monthsAgo = now.get(Calendar.MONTH) - i;
  -                    if (monthsAgo <= 0) {
  -                        monthsAgo += 12;
  -                    }
  -                    now.add(Calendar.MONTH, -monthsAgo);
  -                    return now;
  -                }
  -            }
  -            if (value.equals("week")) {
  -                now.add(Calendar.DATE, -7);
  -                return now;
  -            }
  -            throw new IllegalArgumentException("We do not understand that last units");
  -        } else if (value.equals("yesterday")) {
  -            now.add(Calendar.DATE, -1);
  -            return now;
  -        } else if (value.equals("tomorrow")) {
  -            now.add(Calendar.DATE, 1);
  -            return now;
  -        }
  -        //Try to parse the date a number of different ways
  -        for (int i = 0; i < dateFormats.length; i++) {
  -            try {
  -                Date datetime = dateFormats[i].parse(dateStr);
  -                Calendar cal = Calendar.getInstance();
  -                cal.setTime(datetime);
  -                return cal;
  -            } catch (ParseException pe) {
  -                //we ignore this and just keep trying
  -            }
  -        }
  -
  -        throw new IllegalArgumentException("Unable to parse '" + dateStr + "'.");
  -    }
  -     */
  -
       //-----------------------------------------------------------------------
       /**
        * <p>This constructs an <code>Iterator</code> that will
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message