Example usage for java.util Calendar clear

List of usage examples for java.util Calendar clear

Introduction

In this page you can find the example usage for java.util Calendar 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:com.microsoft.tfs.util.datetime.LenientDateTimeParser.java

private void computeFormats() {
    /*//from   w w w.  jav a2 s. co m
     * The expander takes pattern strings (and expands them) or takes
     * already created DateFormat instances and keeps them in the correct
     * order with the expanded strings.
     */
    final LenientDateTimeParserExpander expander = new LenientDateTimeParserExpander(false, locale);

    /*
     * Fill in the default locale date time formats. The indexes (0,1,2,3)
     * correspond to SimpleDateFormat.FULL, LONG, MEDIUM, and SHORT. We go
     * from FULL (0) to MEDIUM (2) with dates to prevent 2-digit date
     * matching (matches way too early). We go from FULL (0) to SHORT (3)
     * with times.
     *
     * Using the integers directly is a hack, but this whole parser is a
     * hack, so I don't feel too bad.
     */
    for (int i = 0; i <= 2; i++) {
        for (int j = 0; j <= 3; j++) {
            final DateFormat df = SimpleDateFormat.getDateTimeInstance(i, j, locale);
            df.setLenient(false);
            expander.add(df, true, true);
        }
    }

    /*
     * We can detect whether this parser's configured locale likes day
     * before month or month before day in its strings by instantiating a
     * short date formatter, passing a different month and day, and seeing
     * which appears first. We use the short date formatter so we don't get
     * (possibly localized) month names.
     */

    final Calendar c = new GregorianCalendar(timeZone, locale);
    c.clear();
    c.set(Calendar.MONTH, Calendar.JANUARY);
    c.set(Calendar.DATE, 5);
    c.set(Calendar.YEAR, 9999);
    final String defaultFormattedDate = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, locale)
            .format(c.getTime());

    final int monthIndex = defaultFormattedDate.indexOf("1"); //$NON-NLS-1$
    final int dateIndex = defaultFormattedDate.indexOf("5"); //$NON-NLS-1$

    // ISO goes next.
    expander.addExpanded(isoDateTimeFormats);

    if (dateIndex > monthIndex) {
        /*
         * Month-before-day. Use US before EU.
         */
        expander.addExpanded(usDateFormats);
        expander.addExpanded(euDateFormats);
    } else {
        /*
         * Day-before-month. Use EU before US.
         */
        expander.addExpanded(euDateFormats);
        expander.addExpanded(usDateFormats);
    }

    // Add just the default local date instances.
    for (int i = 0; i <= 2; i++) {
        final DateFormat df = SimpleDateFormat.getDateInstance(i, locale);
        df.setLenient(false);
        expander.add(df, true, false);
    }

    // Add just the default local time instances.
    for (int i = 0; i <= 3; i++) {
        final DateFormat df = SimpleDateFormat.getTimeInstance(i, locale);
        df.setLenient(false);
        expander.add(df, false, true);
    }

    // Generic time goes last.
    expander.addExpanded(genericTimeFormats);

    expandedFormats = expander.getSortedResults();
}

From source file:com.square.adherent.noyau.service.implementations.RelevePrestationServiceImpl.java

@Override
public void ajouterRelevePrestation(String nomFichier) {
    logger.debug(messageSourceUtil.get(MessageKeyUtil.LOGGER_DEBUG_AJOUT_RELEVE_PRESTATION,
            new String[] { nomFichier }));

    final SimpleDateFormat sdf = new SimpleDateFormat(
            messageSourceUtil.get(MessageKeyUtil.FORMAT_DATE_YYYYMMDD));
    final String nomFichierDossier = sdf.format(Calendar.getInstance().getTime()) + File.separator + nomFichier;
    // nomFichier = N adhrent + "_" + Date au format AAAAMMJJ + "_" + Mutuelle + "_" + Mode de paiement.pdf
    if (!relevePrestationDao.existe(nomFichierDossier)) {
        final String[] datas = nomFichier.toLowerCase().split("_");
        if (datas.length == 4) {
            final String numeroAdherent = datas[0];
            // Rcupration de l'identifiant de la personne  partir du numro d'adhrent.
            final PersonneCriteresRechercheDto criterias = new PersonneCriteresRechercheDto();
            criterias.setNumeroClient(numeroAdherent);
            final RemotePagingCriteriasDto<PersonneCriteresRechercheDto> criteres = new RemotePagingCriteriasDto<PersonneCriteresRechercheDto>(
                    criterias, 0, Integer.MAX_VALUE);
            final RemotePagingResultsDto<PersonneSimpleDto> resultats = personnePhysiqueService
                    .rechercherPersonneFullTextParCriteres(criteres);
            if (resultats == null || resultats.getTotalResults() != 1) {
                if (resultats == null) {
                    logger.debug(messageSourceUtil.get(
                            MessageKeyUtil.LOGGER_DEBUG_IMPOSSIBLE_AJOUTER_RELEVE_PRESTATION_RESULTAT_NULL));
                } else {
                    logger.debug(messageSourceUtil.get(
                            MessageKeyUtil.LOGGER_DEBUG_IMPOSSIBLE_AJOUTER_RELEVE_PRESTATION_NB_RESULTAT,
                            new String[] { String.valueOf(resultats.getTotalResults()),
                                    String.valueOf(resultats.getListResults().size()) }));
                }//from w w  w  .  j a va 2  s . c  o  m
                throw new BusinessException(messageSourceUtil.get(
                        MessageKeyUtil.LOGGER_DEBUG_IMPOSSIBLE_AJOUTER_RELEVE_PRESTATION_ABSCENCE_PERSONNE,
                        new String[] { String.valueOf(numeroAdherent) }));
            }
            final PersonneSimpleDto personne = resultats.getListResults().get(0);
            final RelevePrestation relevePresta = new RelevePrestation();
            relevePresta.setUidPersonne(personne.getId());
            relevePresta.setNomFichier(nomFichierDossier);
            relevePresta.setNomFichierCommercial(
                    messageSourceUtil.get(MessageKeyUtil.MESSAGE_NOM_FICHIER) + datas[1] + ".pdf");
            final char[] annee = new char[4];
            datas[1].getChars(0, 4, annee, 0);
            final int anneeInt = Integer.parseInt(String.copyValueOf(annee));
            final char[] mois = new char[2];
            datas[1].getChars(4, 6, mois, 0);
            final int moisInt = Integer.parseInt(String.copyValueOf(mois));
            final char[] jour = new char[2];
            datas[1].getChars(6, 8, jour, 0);
            final int jourInt = Integer.parseInt(String.copyValueOf(jour));
            final Calendar dateImpression = Calendar.getInstance();
            dateImpression.clear();
            dateImpression.set(anneeInt, moisInt - 1, jourInt);
            relevePresta.setDateImpression(dateImpression);
            relevePresta.setEnvoyeMail(false);
            final String paiementEid = datas[3].split(".pdf")[0];
            final RelevePrestationMoyenPaiement paiement = relevePrestationDao
                    .getMoyenPaiementByEid(paiementEid);
            if (paiement == null) {
                throw new BusinessException(messageSourceUtil.get(MessageKeyUtil.ERROR_MOYEN_PAIEMENT_INCONNU,
                        new String[] { String.valueOf(paiementEid) }));
            } else {
                relevePresta.setMoyenPaiement(paiement);
            }

            // On rcupre la liste des relevs d'un adhrent.
            final CritereSelectionRelevePrestationDto critere = new CritereSelectionRelevePrestationDto();
            critere.setIdPersonne(personne.getId());
            final List<RelevePrestation> releves = relevePrestationDao.getListeReleveParCriteres(critere, true);
            if (releves.size() >= NB_RELEVE_MAX) {
                // On supprime le relev le plus ancien.
                relevePrestationDao.deleteRelevePresta(releves.get(NB_RELEVE_MAX - 1));
            }
            relevePrestationDao.createRelevePresta(relevePresta);
        }
    } else {
        throw new BusinessException(messageSourceUtil.get(MessageKeyUtil.ERROR_CREATION_FICHIER_EXISTE_BASE,
                new String[] { nomFichier }));
    }
}

From source file:com.clustercontrol.calendar.composite.CalendarMonthComposite.java

@Override
public void update() {
    if (m_calendarId == null || m_summaryInfo == null) {
        return;//from   w  ww .ja va  2s. c om
    }

    yearMonth.setText(String.format("%04d/%02d", nowYear, nowMonth));
    //?
    /**  */
    Calendar calendar = null;
    calendar = Calendar.getInstance(TimezoneUtil.getTimeZone());
    calendar.clear();
    calendar.set(nowYear, nowMonth - 1, 1);
    //??????????
    /** ????? */
    int startDate = calendar.get(Calendar.DAY_OF_WEEK);
    /** ???? */
    int lastDate = (m_summaryInfo.size() + 1);

    /***************************************************
     * 
     *           j=0  j=1  j=2  j=3  j=4  j=5  j=6
     *       | Sun| Mon| Thu| Wed| Thu| Fri| Sat|
     *       ------------------------------------
     *   i=1                               | 1  |
     *   i=2 | 2  | 3  | 4  | 5  | 6  | 7  | 8  |
     *   i=3 | 9  | 10 | 11 | 12 | 13 | 14 | 15 |
     *   i=4 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
     *   i=5 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
     *   i=6 | 30 | 31 |
     *
     ***************************************************/
    calTable.removeAll();
    //??
    int day = 1;

    //??
    for (int i = 0; i < 6; i++) { // 6(1????6?)
        //???????????
        int j = startDate;
        //?2????
        startDate = GetCalendarMonthTableDefine.SUNDAY;

        //??
        String[] days = new String[8];
        //1????
        TableItem weekTableItem = new TableItem(calTable, SWT.NONE);
        WidgetTestUtil.setTestId(this, null, weekTableItem);
        //weekTableItem.setData(ClusterControlPlugin.CUSTOM_WIDGET_ID, "calendarMonthCompositeWeekTableItem");

        //??????
        while (j < days.length && day < lastDate) {
            //???
            String sign = "";
            boolean selectedFlag = false;
            if (selectedDay <= day && day < selectedDay + 7) {
                selectedFlag = true;
            }
            switch (m_summaryInfo.get(day - 1)) {
            case 0:
                //
                sign = Messages.getString("view.calendar.month.all");
                weekTableItem.setBackground(j, ColorConstantsWrapper.green());
                break;
            case 1:
                //
                sign = Messages.getString("view.calendar.month.part");
                weekTableItem.setBackground(j, ColorConstantsWrapper.yellow());
                break;
            case 2:
                //
                sign = Messages.getString("view.calendar.month.none");
                weekTableItem.setBackground(j, ColorConstantsWrapper.red());
                break;
            default: // ???
                break;
            }
            if (selectedFlag) {
                weekTableItem.setFont(j, boldFont);
            } else {
                weekTableItem.setFont(j, normalFont);
            }
            weekTableItem.setForeground(j, ColorConstantsWrapper.black());
            //?????
            days[j] = String.format("%02d", day) + sign;
            j++;
            day++;

            WidgetTestUtil.setTestId(this, "weektableitem" + j, weekTableItem);
        }
        weekTableItem.setText(days);
    }
}

From source file:org.seasar.cubby.internal.controller.impl.RequestParameterBinderImplTest.java

private static long fromDateToMillis(final int year, final int month, final int date) {
    final Calendar c = Calendar.getInstance();
    c.clear();
    c.set(Calendar.YEAR, year);//from  w  ww  .  ja v  a2  s .  co  m
    c.set(Calendar.MONTH, MONTHS.get(month));
    c.set(Calendar.DATE, date);
    return c.getTimeInMillis();
}

From source file:org.seasar.cubby.internal.controller.impl.RequestParameterBinderImplTest.java

private static long fromTimeToMillis(final int hour, final int minute, final int second) {
    final Calendar c = Calendar.getInstance();
    c.clear();
    c.set(Calendar.HOUR, hour);//from   w ww.  j  ava  2 s .c  o  m
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, second);
    return c.getTimeInMillis();
}

From source file:org.seasar.cubby.internal.controller.impl.RequestParameterBinderImplTest.java

private static long fromTimestampToMillis(final int year, final int month, final int date, final int hour,
        final int minute, final int second) {
    final Calendar c = Calendar.getInstance();
    c.clear();
    c.set(Calendar.YEAR, year);/*from  w  w  w.  j  av  a2s  . c om*/
    c.set(Calendar.MONTH, MONTHS.get(month));
    c.set(Calendar.DATE, date);
    c.set(Calendar.HOUR, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, second);
    return c.getTimeInMillis();
}

From source file:org.jfree.data.time.Week.java

/**
 * Returns the first millisecond of the week, evaluated using the supplied
 * calendar (which determines the time zone).
 *
 * @param calendar  the calendar (<code>null</code> not permitted).
 *
 * @return The first millisecond of the week.
 *
 * @throws NullPointerException if <code>calendar</code> is
 *     <code>null</code>./*from   w w w .jav  a 2s  . co  m*/
 */
@Override
public long getFirstMillisecond(Calendar calendar) {
    Calendar c = (Calendar) calendar.clone();
    c.clear();
    c.set(Calendar.YEAR, this.year);
    c.set(Calendar.WEEK_OF_YEAR, this.week);
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
    c.set(Calendar.HOUR, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}

From source file:org.jfree.data.time.Week.java

/**
 * Returns the last millisecond of the week, evaluated using the supplied
 * calendar (which determines the time zone).
 *
 * @param calendar  the calendar (<code>null</code> not permitted).
 *
 * @return The last millisecond of the week.
 *
 * @throws NullPointerException if <code>calendar</code> is
 *     <code>null</code>./*w  ww .j  av a  2  s.c o  m*/
 */
@Override
public long getLastMillisecond(Calendar calendar) {
    Calendar c = (Calendar) calendar.clone();
    c.clear();
    c.set(Calendar.YEAR, this.year);
    c.set(Calendar.WEEK_OF_YEAR, this.week + 1);
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
    c.set(Calendar.HOUR, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis() - 1;
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

public static String convertToString(Date value) {

    if (isCustomClassPresent) {
        // this means user has define a seperate converter util class
        return invokeToStringMethod(value, Date.class);
    } else {/*from ww  w . j  a  v  a 2  s. c om*/
        // lexical form of the date is '-'? yyyy '-' mm '-' dd zzzzzz?
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(value);
        if (!calendar.isSet(Calendar.ZONE_OFFSET)) {
            calendar.setTimeZone(TimeZone.getDefault());
        }
        StringBuffer dateString = new StringBuffer(16);
        appendDate(dateString, calendar);
        appendTimeZone(calendar, dateString);
        return dateString.toString();
    }
}

From source file:org.apache.gobblin.salesforce.SalesforceSource.java

private String getDateString(int year) {
    Calendar calendar = new GregorianCalendar();
    calendar.clear();
    calendar.set(Calendar.YEAR, year);
    return Utils.dateToString(calendar.getTime(), SalesforceExtractor.SALESFORCE_TIMESTAMP_FORMAT);
}