Example usage for java.util GregorianCalendar setTime

List of usage examples for java.util GregorianCalendar setTime

Introduction

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

Prototype

public final void setTime(Date date) 

Source Link

Document

Sets this Calendar's time with the given Date.

Usage

From source file:org.obm.icalendar.Ical4jHelper.java

private GregorianCalendar getEventStartCalendar(Event event) {
    GregorianCalendar cal = new GregorianCalendar();

    cal.setTime(event.getStartDate());

    return cal;/*from w w  w  . j  a  v  a2s. c o  m*/
}

From source file:org.eclipse.ecr.opencmis.impl.server.NuxeoCmisService.java

@Override
public ObjectList getContentChanges(String repositoryId, Holder<String> changeLogTokenHolder,
        Boolean includeProperties, String filter, Boolean includePolicyIds, Boolean includeAcl,
        BigInteger maxItems, ExtensionsData extension) {
    if (changeLogTokenHolder == null) {
        throw new CmisInvalidArgumentException("Missing change log token holder");

    }/*from  ww  w  . j  a va  2  s.c  om*/
    String changeLogToken = changeLogTokenHolder.getValue();
    long minDate;
    if (changeLogToken == null) {
        minDate = 0;
    } else {
        try {
            minDate = Long.parseLong(changeLogToken);
        } catch (NumberFormatException e) {
            throw new CmisInvalidArgumentException("Invalid change log token");
        }
    }
    try {
        AuditReader reader = Framework.getService(AuditReader.class);
        if (reader == null) {
            throw new CmisRuntimeException("Cannot find audit service");
        }
        int max = maxItems == null ? -1 : maxItems.intValue();
        if (max < 0) {
            max = DEFAULT_CHANGE_LOG_SIZE;
        }
        // TODO XXX repositoryId as well
        Map<String, Object> params = new HashMap<String, Object>();
        String query = "FROM LogEntry log" //
                + " WHERE log.eventDate >= :minDate" //
                + "   AND log.eventId IN (:evCreated, :evModified, :evRemoved)" //
                + " ORDER BY log.eventDate";
        params.put("minDate", new Date(minDate));
        params.put("evCreated", DocumentEventTypes.DOCUMENT_CREATED);
        params.put("evModified", DocumentEventTypes.DOCUMENT_UPDATED);
        params.put("evRemoved", DocumentEventTypes.DOCUMENT_REMOVED);
        List<?> entries = reader.nativeQuery(query, params, 1, max + 1);
        ObjectListImpl ol = new ObjectListImpl();
        boolean hasMoreItems = entries.size() > max;
        ol.setHasMoreItems(Boolean.valueOf(hasMoreItems));
        if (hasMoreItems) {
            entries = entries.subList(0, max);
        }
        List<ObjectData> ods = new ArrayList<ObjectData>(entries.size());
        Date date = null;
        for (Object entry : entries) {
            LogEntry logEntry = (LogEntry) entry;
            ObjectDataImpl od = new ObjectDataImpl();
            ChangeEventInfoDataImpl cei = new ChangeEventInfoDataImpl();
            // change type
            String eventId = logEntry.getEventId();
            ChangeType changeType;
            if (DocumentEventTypes.DOCUMENT_CREATED.equals(eventId)) {
                changeType = ChangeType.CREATED;
            } else if (DocumentEventTypes.DOCUMENT_UPDATED.equals(eventId)) {
                changeType = ChangeType.UPDATED;
            } else if (DocumentEventTypes.DOCUMENT_REMOVED.equals(eventId)) {
                changeType = ChangeType.DELETED;
            } else {
                continue;
            }
            cei.setChangeType(changeType);
            // change time
            GregorianCalendar changeTime = (GregorianCalendar) Calendar.getInstance();
            date = logEntry.getEventDate();
            changeTime.setTime(date);
            cei.setChangeTime(changeTime);
            od.setChangeEventInfo(cei);
            // properties: id, doc type
            PropertiesImpl properties = new PropertiesImpl();
            properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_ID, logEntry.getDocUUID()));
            properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, logEntry.getDocType()));
            od.setProperties(properties);
            ods.add(od);
        }
        ol.setObjects(ods);
        ol.setNumItems(BigInteger.valueOf(-1));
        String latestChangeLogToken = date == null ? null : String.valueOf(date.getTime());
        changeLogTokenHolder.setValue(latestChangeLogToken);
        return ol;
    } catch (Exception e) {
        throw new CmisRuntimeException(e.toString(), e);
    }
}

From source file:de.tuttas.servlets.DokuServlet.java

private MyTableDataModel getModelAnwesenheit(Klasse kl, Date parsedFrom, Date parsedTo, int filter1Id,
        int filter2Id) {
    TypedQuery<AnwesenheitEintrag> query = em.createNamedQuery("findAnwesenheitbyKlasse",
            AnwesenheitEintrag.class);
    query.setParameter("paramKName", kl.getKNAME());
    query.setParameter("paramFromDate", new java.sql.Date(parsedFrom.getTime()));
    query.setParameter("paramToDate", new java.sql.Date(parsedTo.getTime()));
    Log.d("setze From auf " + new java.sql.Date(parsedFrom.getTime()));
    List<AnwesenheitObjekt> anwesenheit = getData(query);

    Query q = em.createNamedQuery("findSchuelerEinerBenanntenKlasse");
    q.setParameter("paramNameKlasse", kl.getKNAME());
    List<Schueler> schueler = q.getResultList();

    /**// w w w.ja  v  a  2 s .c om
     * Termindaten holen
     */
    Termine t1 = null;
    Termine t2 = null;
    if (filter1Id != -1) {
        t1 = em.find(Termine.class, filter1Id);

    }
    if (filter2Id != -1) {
        t2 = em.find(Termine.class, filter2Id);
    }
    List<Termin> termine = null;
    TypedQuery<Termin> tquery = null;
    if (filter1Id != 0) {
        // zwei Filter
        if (filter2Id != 0) {
            tquery = em.createNamedQuery("findAllTermineTwoFilters", Termin.class);
            tquery.setParameter("filter1", t1.getId());
            tquery.setParameter("filter2", t2.getId());
            tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime()));
            tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime()));
            termine = tquery.getResultList();
        } // nur Filter1
        else {
            tquery = em.createNamedQuery("findAllTermineOneFilter", Termin.class);
            tquery.setParameter("filter1", t1.getId());
            tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime()));
            tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime()));
            termine = tquery.getResultList();
        }
    } else {
        // nur Filter2
        if (filter2Id != 0) {
            tquery = em.createNamedQuery("findAllTermineOneFilter", Termin.class);
            tquery.setParameter("filter1", t2.getId());
            tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime()));
            tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime()));
            termine = tquery.getResultList();
        } // kein Filter, Termine so generieren
        else {
            termine = new ArrayList<>();
            Date current = new Date(parsedFrom.getTime());
            parsedTo.setTime(parsedTo.getTime() + 1000);
            while (current.before(parsedTo)) {
                termine.add(new Termin(new Timestamp(current.getTime())));
                Log.d("Erzeuge neuen Termin:" + new Termin(new Timestamp(current.getTime())));
                current.setTime(current.getTime() + 24 * 60 * 60 * 1000);
            }
        }
    }

    Log.d("Result List:" + anwesenheit);

    List<String> sb = new ArrayList<>();
    GregorianCalendar c = (GregorianCalendar) GregorianCalendar.getInstance();

    for (Termin t : termine) {
        c.setTime(new Date(t.getDate().getTime()));
        sb.add("" + DatumUtil.getWochentag(c.get(GregorianCalendar.DAY_OF_WEEK)) + ":"
                + c.get(GregorianCalendar.DATE) + "." + (c.get(GregorianCalendar.MONTH) + 1) + "."
                + c.get(GregorianCalendar.YEAR));
    }
    Log.d("Es werden " + sb.size() + " Tage dargestellt");
    sb.add(0, "Name");
    String[] cols = new String[sb.size()];
    for (int i = 0; i < cols.length; i++) {
        cols[i] = sb.get(i);
    }
    MyTableDataModel mo = new MyTableDataModel(schueler.size(), cols);
    Schueler s;
    for (int y = 0; y < schueler.size(); y++) {
        s = schueler.get(y);
        mo.setData(0, y, s.getVNAME() + " " + s.getNNAME());
        int x = 1;
        for (Termin t : termine) {
            mo.setData(x, y, findVermerk(s.getId(), t.getDate(), anwesenheit));
            x++;
        }
    }
    return mo;
}

From source file:org.obm.icalendar.Ical4jHelper.java

private Recur getRecurFrom(EventRecurrence eventRecurrence, String frequency) {
    if (eventRecurrence.getEnd() == null) {
        return new Recur(frequency, null);
    } else {//from   w ww.j a  v a  2s. c  o m
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(eventRecurrence.getEnd());
        cal.set(GregorianCalendar.SECOND, 0);
        return new Recur(frequency, new DateTime(cal.getTime()));
    }
}

From source file:org.obm.icalendar.Ical4jHelper.java

@Override
public List<Date> dateInInterval(EventRecurrence recurrence, Date eventDate, Date start, Date end,
        Set<Date> dateExce) {
    List<Date> ret = new LinkedList<Date>();
    Recur recur = getRecur(recurrence, eventDate);
    if (recur == null) {
        ret.add(eventDate);/*from  ww  w  .j a v a2  s  . co m*/
        return ret;
    }
    if (end == null) {
        if (start.before(eventDate)) {
            ret.add(eventDate);
            return ret;
        }
        return ImmutableList.of();
    }
    DateList dl = recur.getDates(new DateTime(eventDate), new DateTime(start), new DateTime(end),
            Value.DATE_TIME);
    for (Iterator<?> it = dl.iterator(); it.hasNext();) {
        Date evD = (Date) it.next();
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(evD);
        cal.set(GregorianCalendar.MILLISECOND, 0);
        if (!dateExce.contains(cal.getTime())) {
            ret.add(evD);
        }
    }
    return ret;
}

From source file:edu.stanford.muse.util.Util.java

public static List<Date> getYearlyIntervals(Date start, Date end) {
    List<Date> intervals = new ArrayList<Date>();
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(start);
    int startYear = c.get(Calendar.YEAR);
    int year = startYear;

    intervals.add(start);/*  www.  ja v a2s.  c  om*/
    while (true) {
        year++;
        c = new GregorianCalendar(year, 0, 1, 0, 0, 0);
        intervals.add(c.getTime());
        if (c.getTime().after(end))
            break;
    }
    return intervals;
}

From source file:edu.stanford.muse.util.Util.java

public static List<Date> getMonthlyIntervals(Date start, Date end) {
    List<Date> intervals = new ArrayList<Date>();
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(start);
    int startMonth = c.get(Calendar.MONTH);
    int year = c.get(Calendar.YEAR);
    int month = startMonth;

    intervals.add(start);//from  ww w . ja  va  2 s  .c  o m
    while (true) {
        month++;
        if (month == 12) {
            month = 0;
            year++;
        }

        c = new GregorianCalendar(year, month, 1, 0, 0, 0);
        intervals.add(c.getTime());
        if (c.getTime().after(end))
            break;
    }
    return intervals;
}

From source file:de.tuttas.servlets.DokuServlet.java

private Document createAnwesenheit(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out,
        int filter1Id, int filter2Id) throws ParseException, IOException, DocumentException {
    Document document = new Document();
    /* Basic PDF Creation inside servlet */
    PdfWriter writer = PdfWriter.getInstance(document, out);
    StringBuilder htmlString = new StringBuilder();
    htmlString.append(kopf);/*from   ww w.  j a v a2 s.  c  o m*/
    /* Anwesenheit einfgen */
    TypedQuery<AnwesenheitEintrag> query = em.createNamedQuery("findAnwesenheitbyKlasse",
            AnwesenheitEintrag.class);
    query.setParameter("paramKName", kl.getKNAME());
    query.setParameter("paramFromDate", new java.sql.Date(parsedFrom.getTime()));
    query.setParameter("paramToDate", new java.sql.Date(parsedTo.getTime()));

    Log.d("setze From auf " + new java.sql.Date(parsedFrom.getTime()));
    List<AnwesenheitObjekt> anwesenheit = getData(query);

    /**
     * Termindaten holen
     */
    Termine t1 = null;
    Termine t2 = null;
    if (filter1Id != -1) {
        t1 = em.find(Termine.class, filter1Id);

    }
    if (filter2Id != -1) {
        t2 = em.find(Termine.class, filter2Id);
    }
    List<Termin> termine = null;
    TypedQuery<Termin> tquery = null;
    if (filter1Id != 0) {
        // zwei Filter
        if (filter2Id != 0) {
            tquery = em.createNamedQuery("findAllTermineTwoFilters", Termin.class);
            tquery.setParameter("filter1", t1.getId());
            tquery.setParameter("filter2", t2.getId());
            tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime()));
            tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime()));
            termine = tquery.getResultList();
        } // nur Filter1
        else {
            tquery = em.createNamedQuery("findAllTermineOneFilter", Termin.class);
            tquery.setParameter("filter1", t1.getId());
            tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime()));
            tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime()));
            termine = tquery.getResultList();
        }
    } else {
        // nur Filter2
        if (filter2Id != 0) {
            tquery = em.createNamedQuery("findAllTermineOneFilter", Termin.class);
            tquery.setParameter("filter1", t2.getId());
            tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime()));
            tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime()));
            termine = tquery.getResultList();
        } // kein Filter, Termine so generieren
        else {
            termine = new ArrayList<>();
            Date current = new Date(parsedFrom.getTime());
            parsedTo.setTime(parsedTo.getTime() + 1000);
            while (current.before(parsedTo)) {
                termine.add(new Termin(new Timestamp(current.getTime())));
                Log.d("Erzeuge neuen Termin:" + new Termin(new Timestamp(current.getTime())));
                current.setTime(current.getTime() + 24 * 60 * 60 * 1000);
            }
        }
    }

    Log.d("Result List:" + anwesenheit);
    GregorianCalendar c = (GregorianCalendar) GregorianCalendar.getInstance();
    c.setTime(parsedFrom);

    String tagZeile = "";
    document.open();
    Query q = em.createNamedQuery("findSchuelerEinerBenanntenKlasse");
    q.setParameter("paramNameKlasse", kl.getKNAME());
    List<Schueler> schueler = q.getResultList();
    Date current = new Date(parsedFrom.getTime());
    Log.d("Current=" + current + " TO=" + parsedTo + " From=" + parsedFrom + " Termine=" + termine.size());
    int spalte = 0;

    for (spalte = 0; spalte < termine.size(); spalte++) {
        tagZeile += "<table  align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">\n";
        tagZeile += ("<tr >\n");
        tagZeile += ("<td width='25%' style=\"font-size: 14;border: 1px solid black;\"><b>Name</b></td>\n");
        // Zeile f.  Tage (Headline)
        Log.d("Spalte ist nun " + spalte);
        int i = 0;
        for (i = 0; i < 7 && spalte + i < termine.size(); i++) {
            current = new Date(termine.get(spalte + i).getDate().getTime());
            c.setTime(current);
            if (c.get(GregorianCalendar.DAY_OF_WEEK) == 1 || c.get(GregorianCalendar.DAY_OF_WEEK) == 7) {
                tagZeile += ("<td align=\"center\" style=\"padding:5px; background-color: #cccccc; font-size: 12;border: 1px solid black;\">"
                        + DatumUtil.getWochentag(c.get(GregorianCalendar.DAY_OF_WEEK)) + "<br></br>"
                        + c.get(GregorianCalendar.DATE) + "." + (c.get(GregorianCalendar.MONTH) + 1) + "."
                        + c.get(GregorianCalendar.YEAR) + "</td>\n");
            } else {
                tagZeile += ("<td align=\"center\" style=\"padding: 5px; font-size: 12;border: 1px solid black;\">"
                        + DatumUtil.getWochentag(c.get(GregorianCalendar.DAY_OF_WEEK)) + "<br></br>"
                        + c.get(GregorianCalendar.DATE) + "." + (c.get(GregorianCalendar.MONTH) + 1) + "."
                        + c.get(GregorianCalendar.YEAR) + "</td>\n");
            }
            Log.d("Spalte " + (i + spalte) + " Datum=" + current);
        }
        Log.d("Head aufgebaut");
        tagZeile += "</tr>\n";

        // Zeile pro Name
        for (Schueler s : schueler) {
            tagZeile += "<tr>\n";
            tagZeile += ("<td width='20%' style=\"padding: 5px;font-size: 12;border: 1px solid black;\"><b>"
                    + s.getVNAME() + " " + s.getNNAME() + "</b></td>\n");
            // Zeile f.  Tage
            //Log.d("Zeile f. Schler " + s.getNNAME());
            for (i = 0; i < 7 && spalte + i < termine.size(); i++) {
                current = new Date(termine.get(spalte + i).getDate().getTime());
                c.setTime(current);
                if (c.get(GregorianCalendar.DAY_OF_WEEK) == 1 || c.get(GregorianCalendar.DAY_OF_WEEK) == 7) {
                    tagZeile += ("<td style=\"background-color:#cccccc;font-size: 11;border: 1px solid black;\">"
                            + findVermerk(s.getId(), current, anwesenheit) + "</td>\n");
                } else {
                    tagZeile += ("<td style=\"font-size: 11;border: 1px solid black;\">"
                            + findVermerk(s.getId(), current, anwesenheit) + "</td>\n");
                }
                Log.d("Zeile f. Schler " + s.getNNAME() + " Datum " + current);
            }
            tagZeile += "</tr>\n";
        }
        Log.d("Rumpf aufgebaut");

        spalte = spalte + i - 1;

        // neue Seite bei 7 Terminen
        if (i == 7) {
            tagZeile += "</table>\n";
            htmlString.append(tagZeile);
            InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes());
            // Bild einfgen
            String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif";
            Image image = Image.getInstance(url);
            image.setAbsolutePosition(45f, 720f);
            image.scalePercent(50f);
            document.add(image);
            XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
            document.newPage();
            Log.d("neue Seite");
            htmlString = new StringBuilder();
            tagZeile = "";
            htmlString.append(kopf);
        }
        Log.d("SPalte ist " + spalte + " Termine=" + termine.size());

    }
    Log.d("Ende der ForSchleife spalte=" + spalte);
    // den Rest der Seite noch drucken
    if (spalte % 7 != 0) {
        tagZeile += "</table>\n";
        htmlString.append(tagZeile);
        Log.d("Rest Seite erzeugen");
        //Log.d("html String =" + htmlString.toString());
        //document.add(new Paragraph("Tutorial to Generate PDF using Servlet"));

        InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes());
        // Bild einfgen
        String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif";
        Image image = Image.getInstance(url);
        image.setAbsolutePosition(45f, 720f);
        image.scalePercent(50f);
        document.add(image);
        Log.d("writer=" + writer + " document=" + document + " is=" + is);
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);

    }

    document.close();
    return document;
}

From source file:PVGraph.java

public java.util.List<PeriodData> getMonthData(int year, int month) {
    Statement stmt = null;/* w  w  w  .j  a va2 s  .c  om*/
    String query = "select * from DayData where year(DateTime) = " + year + " and month(DateTime) = " + month
            + " and CurrentPower != 0 order by DateTime";
    Map<String, PeriodData> result = new HashMap<String, PeriodData>();
    GregorianCalendar gc = new GregorianCalendar();
    try {
        getDatabaseConnection();
        stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            String serial = rs.getString("serial");
            PeriodData pd = result.get(serial);
            if (pd == null) {
                pd = new PeriodData();
                pd.serial = serial;
                pd.inverter = rs.getString("inverter");
                pd.startTotalPower = rs.getDouble("ETotalToday");
                gc.setTime(rs.getTimestamp("DateTime"));
                gc.set(Calendar.DAY_OF_MONTH, 1);
                gc.add(Calendar.MONTH, 1);
                gc.add(Calendar.DAY_OF_MONTH, -1);
                pd.numPowers = gc.get(Calendar.DAY_OF_MONTH);
                result.put(serial, pd);
            }
            double power = rs.getDouble("ETotalToday");
            gc.setTime(rs.getTimestamp("DateTime"));
            pd.powers[gc.get(Calendar.DAY_OF_MONTH) - 1] = power;
            pd.endTotalPower = power;
        }
    } catch (SQLException e) {
        System.err.println("Query failed: " + e.getMessage());
    } finally {
        try {
            stmt.close();
        } catch (SQLException e) {
            // relax
        }
    }
    return new java.util.ArrayList<PeriodData>(result.values());
}

From source file:de.tuttas.servlets.DokuServlet.java

private MyTableDataModel getModelVerlauf(Klasse kl, Date parsedFrom, Date parsedTo, String filter1,
        String filter2, String me) {
    Query query = em.createNamedQuery("findVerlaufbyKlasse");
    query.setParameter("paramKName", kl.getKNAME());
    query.setParameter("paramFromDate", new java.sql.Date(parsedFrom.getTime()));
    query.setParameter("paramToDate", new java.sql.Date(parsedTo.getTime()));
    List<Verlauf> overlauf = query.getResultList();
    List<Verlauf> verlauf = new ArrayList<>();
    /**//from www . java2  s. c o m
     * Filtern der oVerlauf Liste
     */
    for (Verlauf v : overlauf) {
        if (filter1.equals("eigeneEintraege")) {
            if (v.getID_LEHRER().equals(me)) {
                if (filter2.equals("alle") || filter2.equals(v.getID_LERNFELD())) {
                    verlauf.add(v);
                }
            }
        } else {
            if (filter2.equals("alle") || filter2.equals(v.getID_LERNFELD())) {
                verlauf.add(v);
            }
        }
    }

    MyTableDataModel mo = new MyTableDataModel(verlauf.size(),
            new String[] { "Datum", "Stunde", "LF", "LK", "Inhalt", "Bemerkung", "Lernsituation" });
    Verlauf v;
    GregorianCalendar c = (GregorianCalendar) GregorianCalendar.getInstance();
    Log.d("Verlaufsmodel erzeugen filter1=(" + filter1 + ") filter2=(" + filter2 + ")");
    for (int y = 0; y < verlauf.size(); y++) {
        v = verlauf.get(y);
        c.setTime(v.getDATUM());
        mo.setData(0, y,
                DatumUtil.getWochentag(c.get(GregorianCalendar.DAY_OF_WEEK)) + ":"
                        + c.get(GregorianCalendar.DATE) + "." + (c.get(GregorianCalendar.MONTH) + 1) + "."
                        + c.get(GregorianCalendar.YEAR));
        mo.setData(1, y, v.getSTUNDE());
        mo.setData(2, y, v.getID_LERNFELD());
        mo.setData(3, y, v.getID_LEHRER());
        mo.setData(4, y, v.getINHALT());
        mo.setData(5, y, v.getBEMERKUNG());
        mo.setData(6, y, v.getAUFGABE());
    }
    return mo;
}