Example usage for java.util GregorianCalendar clear

List of usage examples for java.util GregorianCalendar clear

Introduction

In this page you can find the example usage for java.util GregorianCalendar clear.

Prototype

public final void clear() 

Source Link

Document

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

From source file:oracle.retail.stores.pos.ado.utility.Utility.java

/**
 *   This method checks if the entered expiry date of ID is valid. Returns false
 *   if entered expiry date is before the current date. True otherwise.
 *   @param expirationDate//  w w w  .  j  a  v a 2s. c om
 *   @throws TenderException if not a valid expiration date
 */
public boolean isValidExpirationDate(String expirationDate) throws TenderException {
    boolean result = true;
    Date today = new Date();
    EYSDate todayEYS = new EYSDate(today);
    String format = EYSDate.ID_EXPIRATION_DATE_FORMAT;
    Locale locale = LocaleMap.getLocale(LocaleConstantsIfc.DEFAULT_LOCALE);
    DateFormat dateFormat = new SimpleDateFormat(format, locale);
    Date date = null;
    EYSDate dateEYS = null;
    try {
        date = dateFormat.parse(expirationDate);
        dateEYS = new EYSDate(date);
    } catch (ParseException e) {
        throw new TenderException("Invalid expiration date format", TenderErrorCodeEnum.INVALID_EXPIRATION_DATE,
                e);
    }
    GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
    gc.setTime(today);
    int thisMonth = gc.get(Calendar.MONTH);
    int thisYear = gc.get(Calendar.YEAR);
    gc.clear();
    Calendar c = dateEYS.calendarValue();
    gc.setTime(c.getTime());
    if (dateEYS.before(todayEYS)
            && !((thisMonth == gc.get(Calendar.MONTH)) && (thisYear == gc.get(Calendar.YEAR)))) {
        result = false;
    }
    return result;
}

From source file:ca.uhn.hl7v2.model.primitive.tests.CommonTSTest.java

@Test
public void testToHl7TMFormat() throws DataTypeException {
    GregorianCalendar cal = new GregorianCalendar();
    cal.clear();
    cal.setLenient(false);/*  w  ww. jav  a 2s .  c o m*/
    cal.set(Calendar.HOUR_OF_DAY, 20);
    cal.set(Calendar.MINUTE, 6);
    cal.set(Calendar.SECOND, 24);
    cal.set(Calendar.MILLISECOND, 528);
    String convertedDate = CommonTM.toHl7TMFormat(cal);
    assertEquals("Should get a HL7 formatted date back", "200624.528-0500", convertedDate);
}

From source file:ucar.unidata.data.storm.Diamond7StormDataSource.java

/**
 * _more_//from   w  w  w  .  j a v  a2s. c  o m
 *
 * @param year _more_
 * @param month _more_
 * @param day _more_
 * @param hour _more_
 *
 * @return _more_
 *
 * @throws Exception _more_
 */
private DateTime getDateTime(int year, int month, int day, int hour) throws Exception {
    GregorianCalendar convertCal = new GregorianCalendar(DateUtil.TIMEZONE_GMT);
    convertCal.clear();
    convertCal.set(Calendar.YEAR, year);
    //The MONTH is 0 based. The incoming month is 1 based
    convertCal.set(Calendar.MONTH, month - 1);
    convertCal.set(Calendar.DAY_OF_MONTH, day);
    convertCal.set(Calendar.HOUR_OF_DAY, hour);
    return new DateTime(convertCal.getTime());
}

From source file:oracle.retail.stores.pos.ado.utility.Utility.java

/**
This method validates the expiration date.
@param expirationDate/*from w  ww .  j a v  a  2  s  .c o  m*/
@throws TenderException if not a valid expiration date
**/
//----------------------------------------------------------------------
public synchronized void validateExpirationDate(String expDate) throws TenderException {
    GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
    // get today's date and from that get the current
    // Month and Year.
    Date today = new Date();
    gc.setTime(today);
    int thisMonth = gc.get(Calendar.MONTH);
    int thisYear = gc.get(Calendar.YEAR);
    gc.clear();
    EYSDate expirationDate = parseEncryptedExpirationDate(expDate);
    // reset the calendar with this tend;er's Exp. Date
    Calendar c = expirationDate.calendarValue();
    gc.setTime(c.getTime());

    // if expiration date is before today and
    // the month and year both do not match the
    // current month and year, the card must be expired.
    EYSDate todayEYS = new EYSDate(today);
    if (expirationDate.before(todayEYS)
            && !((thisMonth == gc.get(Calendar.MONTH)) && (thisYear == gc.get(Calendar.YEAR)))) {
        throw new TenderException("Expired", TenderErrorCodeEnum.EXPIRED);
    }
    // set the object to nul
    expirationDate = null;
}

From source file:edu.wisc.ssec.mcidasv.data.cyclone.AtcfStormDataSource.java

/**
 * _more_//from  w  w  w.  j a v a 2s.  co  m
 * 
 * @param stormInfo
 *            _more_
 * @param tracks
 *            _more_
 * @param trackFile
 *            _more_
 * @param waysToUse
 *            _more_
 * @param throwError
 *            _more_
 * 
 * 
 * @return _more_
 * @throws Exception
 *             _more_
 */
private boolean readTracks(StormInfo stormInfo, StormTrackCollection tracks, String trackFile,
        Hashtable<String, Boolean> waysToUse, boolean throwError) throws Exception {

    long t1 = System.currentTimeMillis();
    byte[] bytes = readFile(trackFile, true);
    long t2 = System.currentTimeMillis();
    // System.err.println("read time:" + (t2 - t1));
    boolean isZip = trackFile.endsWith(".gz");
    if ((bytes == null) && isZip) {
        String withoutGZ = trackFile.substring(0, trackFile.length() - 3);
        bytes = readFile(withoutGZ, true);
        isZip = false;
    }

    if (bytes == null) {
        if (throwError) {
            throw new BadDataException("Unable to read track file:" + trackFile);
        }
        return false;
    }

    if (isZip) {
        GZIPInputStream zin = new GZIPInputStream(new ByteArrayInputStream(bytes));
        bytes = IOUtil.readBytes(zin);
        zin.close();
    }
    GregorianCalendar convertCal = new GregorianCalendar(DateUtil.TIMEZONE_GMT);
    convertCal.clear();

    String trackData = new String(bytes);
    List lines = StringUtil.split(trackData, "\n", true, true);
    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHH");
    fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
    Hashtable trackMap = new Hashtable();
    Real altReal = new Real(RealType.Altitude, 0);
    // System.err.println("obs:" + lines.size());
    /*
     * Hashtable okWays = new Hashtable(); okWays.put(WAY_CARQ, "");
     * okWays.put(WAY_WRNG, ""); okWays.put(WAY_BEST, ""); okWays.put("ETA",
     * ""); okWays.put("NGX", ""); okWays.put("BAMS", "");
     */
    Hashtable seenDate = new Hashtable();
    initParams();
    int xcnt = 0;
    for (int i = 0; i < lines.size(); i++) {
        String line = (String) lines.get(i);
        if (i == 0) {
            // System.err.println(line);
        }
        List toks = StringUtil.split(line, ",", true);
        /*
         * System.err.println(toks.size() + " " + BASEIDX);
         * if(toks.size()<BASEIDX-1) { System.err.println("bad line:" +
         * line); continue; } else { System.err.println("good line:" +
         * line); }
         */

        // BASIN,CY,YYYYMMDDHH,TECHNUM,TECH,TAU,LatN/S,LonE/W,VMAX,MSLP,TY,RAD,WINDCODE,RAD1,RAD2,RAD3,RAD4,RADP,RRP,MRD,GUSTS,EYE,SUBREGION,MAXSEAS,INITIALS,DIR,SPEED,STORMNAME,DEPTH,SEAS,SEASCODE,SEAS1,SEAS2,SEAS3,SEAS4
        // AL, 01, 2007050612, , BEST, 0, 355N, 740W, 35, 1012, EX, 34, NEQ,
        // 0, 0, 0, 120,
        // AL, 01, 2007050812, 01, CARQ, -24, 316N, 723W, 55, 0, DB, 34,
        // AAA, 0, 0, 0, 0,

        String dateString = (String) toks.get(IDX_YYYYMMDDHH);
        String wayString = (String) toks.get(IDX_TECH);
        // if (okWays.get(wayString) == null) {
        // continue;
        // }
        boolean isBest = wayString.equals(WAY_BEST);
        boolean isWarning = wayString.equals(WAY_WRNG);
        boolean isCarq = wayString.equals(WAY_CARQ);

        int category = ((IDX_TY < toks.size()) ? getCategory((String) toks.get(IDX_TY)) : CATEGORY_XX);
        if (category != CATEGORY_XX) {
            // System.err.println("cat:" + category);
        }

        String fhour = (String) toks.get(IDX_TAU);
        int forecastHour = new Integer(fhour).intValue();
        // A hack - we've seen some atfc files that have a 5 character
        // forecast hour
        // right padded with "00", eg., 01200
        if ((fhour.length() == 5) && (forecastHour > 100)) {
            forecastHour = forecastHour / 100;
        }

        if (isWarning || isCarq) {
            forecastHour = -forecastHour;
        }

        // Check for unique dates for this way
        String dttmkey = wayString + "_" + dateString + "_" + forecastHour;
        if (seenDate.get(dttmkey) != null) {
            continue;
        }
        seenDate.put(dttmkey, dttmkey);

        Date dttm = fmt.parse(dateString);
        convertCal.setTime(dttm);
        String key;
        Way way = getWay(wayString, null);
        if (!isBest && (waysToUse != null) && (waysToUse.size() > 0) && (waysToUse.get(wayString) == null)) {
            continue;
        }

        if (isBest) {
            key = wayString;
        } else {
            key = wayString + "_" + dateString;
            convertCal.add(Calendar.HOUR_OF_DAY, forecastHour);
        }
        dttm = convertCal.getTime();
        StormTrack track = (StormTrack) trackMap.get(key);
        if (track == null) {
            way = (isBest ? Way.OBSERVATION : way);
            track = new StormTrack(stormInfo, addWay(way), new DateTime(dttm), obsParams);
            trackMap.put(key, track);
            tracks.addTrack(track);
        }
        String latString = (String) toks.get(IDX_LAT);
        String lonString = (String) toks.get(IDX_LON);
        String t = latString + " " + lonString;

        boolean south = latString.endsWith("S");
        boolean west = lonString.endsWith("W");
        double latitude = Double.parseDouble(latString.substring(0, latString.length() - 1)) / 10.0;
        double longitude = Double.parseDouble(lonString.substring(0, lonString.length() - 1)) / 10.0;
        if (south) {
            latitude = -latitude;
        }
        if (west) {
            longitude = -longitude;
        }

        EarthLocation elt = new EarthLocationLite(new Real(RealType.Latitude, latitude),
                new Real(RealType.Longitude, longitude), altReal);

        List<Real> attributes = new ArrayList<Real>();

        double windspeed = ((IDX_VMAX < toks.size()) ? getDouble((String) toks.get(IDX_VMAX)) : Double.NaN);
        double pressure = ((IDX_MSLP < toks.size()) ? getDouble((String) toks.get(IDX_MSLP)) : Double.NaN);
        attributes.add(PARAM_STORMCATEGORY.getReal((double) category));
        attributes.add(PARAM_MINPRESSURE.getReal(pressure));
        attributes.add(PARAM_MAXWINDSPEED_KTS.getReal(windspeed));

        StormTrackPoint stp = new StormTrackPoint(elt, new DateTime(dttm), forecastHour, attributes);

        track.addPoint(stp);
    }
    return true;
}

From source file:ucar.unidata.data.storm.AtcfStormDataSource.java

/**
 * _more_//from w w w.  j a va 2 s. c o  m
 *
 * @param stormInfo _more_
 * @param tracks _more_
 * @param trackFile _more_
 * @param waysToUse _more_
 * @param throwError _more_
 *
 *
 * @return _more_
 * @throws Exception _more_
 */
private boolean readTracks(StormInfo stormInfo, StormTrackCollection tracks, String trackFile,
        Hashtable<String, Boolean> waysToUse, boolean throwError) throws Exception {

    long t1 = System.currentTimeMillis();
    byte[] bytes = readFile(trackFile, true);
    long t2 = System.currentTimeMillis();
    //        System.err.println("read time:" + (t2 - t1));
    boolean isZip = trackFile.endsWith(".gz");
    if ((bytes == null) && isZip) {
        String withoutGZ = trackFile.substring(0, trackFile.length() - 3);
        bytes = readFile(withoutGZ, true);
        isZip = false;
    }

    if (bytes == null) {
        if (throwError) {
            throw new BadDataException("Unable to read track file:" + trackFile);
        }
        return false;
    }

    if (isZip) {
        GZIPInputStream zin = new GZIPInputStream(new ByteArrayInputStream(bytes));
        bytes = IOUtil.readBytes(zin);
        zin.close();
    }
    GregorianCalendar convertCal = new GregorianCalendar(DateUtil.TIMEZONE_GMT);
    convertCal.clear();

    String trackData = new String(bytes);
    List lines = StringUtil.split(trackData, "\n", true, true);
    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHH");
    fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
    Hashtable trackMap = new Hashtable();
    Real altReal = new Real(RealType.Altitude, 0);
    //        System.err.println("obs:" + lines.size());
    /*        Hashtable okWays = new Hashtable();
    okWays.put(WAY_CARQ, "");
    okWays.put(WAY_WRNG, "");
    okWays.put(WAY_BEST, "");
    okWays.put("ETA", "");
    okWays.put("NGX", "");
    okWays.put("BAMS", "");*/
    Hashtable seenDate = new Hashtable();
    initParams();
    int xcnt = 0;
    // check if the tech num is included
    // some actf files do not have tech num for some reasom.
    List toks1 = StringUtil.split(lines.get(1), ",", true);
    String techNum = (String) toks1.get(IDX_TECHNUM);
    if (techNum.length() > 0 && !techNum.matches("\\d+")) {
        IDX_TECH = IDX_TECH - 1;
        IDX_TAU = IDX_TAU - 1;
        IDX_LAT = IDX_LAT - 1;
        IDX_LON = IDX_LON - 1;
        IDX_VMAX = IDX_VMAX - 1;
        IDX_MSLP = IDX_MSLP - 1;
        IDX_TY = IDX_TY - 1;
    }
    for (int i = 0; i < lines.size(); i++) {
        String line = (String) lines.get(i);
        if (i == 0) {
            //                System.err.println(line);
        }
        List toks = StringUtil.split(line, ",", true);
        /*            System.err.println(toks.size() + " " + BASEIDX);
        if(toks.size()<BASEIDX-1) {
        System.err.println("bad line:" + line);
        continue;
        } else {
        System.err.println("good line:" + line);
        }
        */

        //BASIN,CY,YYYYMMDDHH,TECHNUM,TECH,TAU,LatN/S,LonE/W,VMAX,MSLP,TY,RAD,WINDCODE,RAD1,RAD2,RAD3,RAD4,RADP,RRP,MRD,GUSTS,EYE,SUBREGION,MAXSEAS,INITIALS,DIR,SPEED,STORMNAME,DEPTH,SEAS,SEASCODE,SEAS1,SEAS2,SEAS3,SEAS4
        //AL, 01, 2007050612,   , BEST,   0, 355N,  740W,  35, 1012, EX,  34, NEQ,    0,    0,    0,  120, 
        //AL, 01, 2007050812, 01, CARQ, -24, 316N,  723W,  55,    0, DB,  34, AAA,    0,    0,    0,    0, 

        String dateString = (String) toks.get(IDX_YYYYMMDDHH);
        String wayString = (String) toks.get(IDX_TECH);
        //            if (okWays.get(wayString) == null) {
        //                continue;
        //            }
        boolean isBest = wayString.equals(WAY_BEST);
        boolean isWarning = wayString.equals(WAY_WRNG);
        boolean isCarq = wayString.equals(WAY_CARQ);

        int category = ((IDX_TY < toks.size()) ? getCategory((String) toks.get(IDX_TY)) : CATEGORY_XX);
        if (category != CATEGORY_XX) {
            //                System.err.println("cat:" + category);
        }

        String fhour = (String) toks.get(IDX_TAU);
        int forecastHour = new Integer(fhour).intValue();
        //A hack - we've seen some atfc files that have a 5 character forecast hour
        //right padded with "00", eg., 01200
        if ((fhour.length() == 5) && (forecastHour > 100)) {
            forecastHour = forecastHour / 100;
        }

        if (isWarning || isCarq) {
            forecastHour = -forecastHour;
        }

        //Check for unique dates for this way
        String dttmkey = wayString + "_" + dateString + "_" + forecastHour;
        if (seenDate.get(dttmkey) != null) {
            continue;
        }
        seenDate.put(dttmkey, dttmkey);

        Date dttm = fmt.parse(dateString);
        convertCal.setTime(dttm);
        String key;
        Way way = getWay(wayString, null);
        if (!isBest && (waysToUse != null) && (waysToUse.size() > 0) && (waysToUse.get(wayString) == null)) {
            continue;
        }

        if (isBest) {
            key = wayString;
        } else {
            key = wayString + "_" + dateString;
            convertCal.add(Calendar.HOUR_OF_DAY, forecastHour);
        }
        dttm = convertCal.getTime();
        StormTrack track = (StormTrack) trackMap.get(key);
        if (track == null) {
            way = (isBest ? Way.OBSERVATION : way);
            track = new StormTrack(stormInfo, addWay(way), new DateTime(dttm), obsParams);
            trackMap.put(key, track);
            tracks.addTrack(track);
        }
        String latString = (String) toks.get(IDX_LAT);
        String lonString = (String) toks.get(IDX_LON);
        String t = latString + " " + lonString;

        boolean south = latString.endsWith("S");
        boolean west = lonString.endsWith("W");
        double latitude = Double.parseDouble(latString.substring(0, latString.length() - 1)) / 10.0;
        double longitude = Double.parseDouble(lonString.substring(0, lonString.length() - 1)) / 10.0;
        if (south) {
            latitude = -latitude;
        }
        if (west) {
            longitude = -longitude;
        }

        EarthLocation elt = new EarthLocationLite(new Real(RealType.Latitude, latitude),
                new Real(RealType.Longitude, longitude), altReal);

        List<Real> attributes = new ArrayList<Real>();

        double windspeed = ((IDX_VMAX < toks.size()) ? getDouble((String) toks.get(IDX_VMAX)) : Double.NaN);
        double pressure = ((IDX_MSLP < toks.size()) ? getDouble((String) toks.get(IDX_MSLP)) : Double.NaN);
        attributes.add(PARAM_STORMCATEGORY.getReal((double) category));
        attributes.add(PARAM_MINPRESSURE.getReal(pressure));
        attributes.add(PARAM_MAXWINDSPEED_KTS.getReal(windspeed));

        StormTrackPoint stp = new StormTrackPoint(elt, new DateTime(dttm), forecastHour, attributes);

        track.addPoint(stp);
    }
    return true;
}

From source file:com.sapienter.jbilling.common.GatewayBL.java

private CreditCardDTO parseCreditCard() throws ValidatorException {
    CreditCardDTO creditCard = new CreditCardDTO();
    creditCard.setNumber(getStringPar("s_number"));
    creditCard.setName(getStringPar("s_name"));
    validate("CreditCard", creditCard);

    // get the expiry date
    Integer month = getIntPar("s_expiry_month", true);
    Integer year = getIntPar("s_expiry_year", true);
    vRange("s_expiry_month", 1, 12);
    vRange("s_expiry_year", 4, 99);
    if (code != RES_CODE_OK) {
        return null;
    }/*from   w w w .ja  v  a 2 s.  c  om*/
    GregorianCalendar cal = new GregorianCalendar();
    cal.clear();
    cal.set(year.intValue() + 2000, month.intValue() - 1, 1);
    creditCard.setCcExpiry(cal.getTime());

    return creditCard;
}

From source file:org.eclipse.uomo.util.impl.Iso8601Date.java

/**
 * get the date specified as a Date./*from   w  w w  .ja v  a 2 s .c o m*/
 * 
 * @param timezone
 *            - REQUIRED, IF_PRESENT or IGNORE
 * @throws OHFException
 */
public Date getAsDate(int timezone) throws UOMoException {
    GregorianCalendar cal = new GregorianCalendar();
    cal.clear();
    if (year != -1)
        cal.set(Calendar.YEAR, year);
    if (month != -1)
        cal.set(Calendar.MONTH, month - 1); // Calendar month start with 0
    if (day != -1)
        cal.set(Calendar.DAY_OF_MONTH, day);
    if (hour != -1)
        cal.set(Calendar.HOUR_OF_DAY, hour);
    if (minute != -1)
        cal.set(Calendar.MINUTE, minute);
    if (second != -1)
        cal.set(Calendar.SECOND, second);
    if (milli != -1)
        cal.set(Calendar.MILLISECOND, milli);

    if (timezone == REQUIRED || timezone == IF_PRESENT || timezone == OPTIONAL) {
        if (timezone == REQUIRED && tzNegative == null)
            throw new UOMoException(Messages.Iso8601Date_TZ_NOT_DEFINED);
        if (tzNegative != null) {
            TimeZone tzMsg = TimeZone.getTimeZone(Messages.Iso8601Date_GMT + prepTimezone());
            cal.setTimeZone(tzMsg);
        }
    }
    return cal.getTime();
}

From source file:stg.utils.immutable.Day.java

private GregorianCalendar getCalendarInstance(TimeZone zone) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.clear();
    calendar.setLenient(false);/*w  w  w .j a  v  a 2 s. c om*/
    calendar.setTimeZone(zone);
    return calendar;
}