List of usage examples for java.util GregorianCalendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:org.squale.squalecommon.daolayer.component.AuditDAOImplTest.java
/** * @see junit.framework.TestCase#setUp() *//* ww w .j av a2 s . com*/ protected void setUp() throws Exception { super.setUp(); getSession().beginTransaction(); // On va crer 2 audits de suivis et un de jalon // dont la date sera la plus ancienne GregorianCalendar cal = new GregorianCalendar(); ApplicationBO ap1 = getComponentFactory().createApplicationWithSite(getSession(), "qvi"); ap1.setStatus(ApplicationBO.VALIDATED); QualityGridBO grid = getComponentFactory().createGrid(getSession()); p1 = getComponentFactory().createProject(getSession(), ap1, grid); a1 = getComponentFactory().createAudit(getSession(), p1); a1.setType(AuditBO.MILESTONE); a1.setStatus(AuditBO.TERMINATED); // date relle = aujourd'hui a1.setHistoricalDate(cal.getTime()); a2 = getComponentFactory().createAudit(getSession(), p1); a2.setStatus(AuditBO.TERMINATED); a3 = getComponentFactory().createAudit(getSession(), p1); a3.setStatus(AuditBO.TERMINATED); a4 = getComponentFactory().createAuditWithStatus(getSession(), p1, new Integer(AuditBO.RUNNING)); final int ten_days = 10; // date a2 = dans 10 jours cal.add(GregorianCalendar.DATE, ten_days); a2.setDate(cal.getTime()); // date de ralisation de a1 = dans 20 jours cal.add(GregorianCalendar.DATE, ten_days); a1.setDate(cal.getTime()); // date a3 = dans 30 jours cal.add(GregorianCalendar.DATE, ten_days); a3.setDate(cal.getTime()); // date a4 = dans 40 jours cal.add(GregorianCalendar.DATE, ten_days); a4.setDate(cal.getTime()); LOGGER.warn("Date de a1 = " + a1.getDate() + " date historique = " + a1.getHistoricalDate()); LOGGER.warn("Date de a2 = " + a2.getDate()); LOGGER.warn("Date de a3 = " + a3.getDate()); LOGGER.warn("Date de a4 = " + a4.getDate()); dao.save(getSession(), a1); dao.save(getSession(), a2); dao.save(getSession(), a3); dao.save(getSession(), a4); getSession().commitTransactionWithoutClose(); }
From source file:com.jpeterson.littles3.S3ObjectRequestTest.java
/** * Basically a utility test for creating an ISO 8601 date. *//* www . j a v a 2s .c om*/ public void test_isoDate() { SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); TimeZone utc = TimeZone.getTimeZone("UTC"); iso8601.setTimeZone(utc); GregorianCalendar cal = new GregorianCalendar(2007, 6, 19, 9, 50, 33); assertEquals("Unexpected formatted date", "2007-07-19T14:50:33.000Z", iso8601.format(cal.getTime())); }
From source file:com.adito.ldap.LdapUserDatabase.java
/** * Return a date equivalent to a timestamp ldap * In the case of timestamp is 2008123115959Z, the date is 2008,12(december),31,11:59:59 * * @param timestamp string that reprsent the timestamp like 2008123115959Z * @return a date of timestamp// www .j a va 2 s . c om */ private static Date getDate(String timestamp) { GregorianCalendar calendar = new GregorianCalendar(Integer.parseInt(timestamp.substring(0, 4)), Integer.parseInt(timestamp.substring(4, 6)) - 1, Integer.parseInt(timestamp.substring(6, 8)), Integer.parseInt(timestamp.substring(8, 10)), Integer.parseInt(timestamp.substring(10, 12)), Integer.parseInt(timestamp.substring(12, 14))); return calendar.getTime(); }
From source file:com.silverpeas.ical.ImportIcalManager.java
/** * IMPORT SilverpeasCalendar in Ical format * @param file//from w w w . j a va2 s . c om * @return * @throws Exception */ public String importIcalAgenda(File file) throws Exception { SilverTrace.debug("agenda", "ImportIcalManager.importIcalAgenda()", "root.MSG_GEN_ENTER_METHOD"); String returnCode = AgendaSessionController.IMPORT_FAILED; InputStreamReader inputStream = null; XmlReader xr = null; try { String charsetUsed = agendaSessionController.getSettings().getString("defaultCharset"); if (StringUtil.isDefined(charset)) { charsetUsed = charset; } // File Encoding detection xr = new XmlReader(file); SilverTrace.debug("agenda", "ImportIcalManager.importIcalAgenda()", "Encoding = " + xr.getEncoding()); if (StringUtil.isDefined(xr.getEncoding())) { charsetUsed = xr.getEncoding(); } inputStream = new InputStreamReader(new FileInputStream(file), charsetUsed); CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = builder.build(inputStream); // Get all EVENTS for (Object o : calendar.getComponents(Component.VEVENT)) { VEvent eventIcal = (VEvent) o; String name = getFieldEvent(eventIcal.getProperty(Property.SUMMARY)); String description = null; if (StringUtil.isDefined(getFieldEvent(eventIcal.getProperty(Property.DESCRIPTION)))) { description = getFieldEvent(eventIcal.getProperty(Property.DESCRIPTION)); } // Name is mandatory in the Silverpeas Agenda if (!StringUtil.isDefined(name)) { if (StringUtil.isDefined(description)) { name = description; } else { name = " "; } } String priority = getFieldEvent(eventIcal.getProperty(Property.PRIORITY)); if (!StringUtil.isDefined(priority)) { priority = Priority.UNDEFINED.getValue(); } String classification = getFieldEvent(eventIcal.getProperty(Property.CLASS)); String startDate = getFieldEvent(eventIcal.getProperty(Property.DTSTART)); String endDate = getFieldEvent(eventIcal.getProperty(Property.DTEND)); Date startDay = getDay(startDate); String startHour = getHour(startDate); Date endDay = getDay(endDate); String endHour = getHour(endDate); // Duration of the event long duration = endDay.getTime() - startDay.getTime(); boolean allDay = false; // All day case // I don't know why ?? if (("00:00".equals(startHour) && "00:00".equals(endHour)) || (!StringUtil.isDefined(startHour) && !StringUtil.isDefined(endHour))) { // For complete Day startHour = ""; endHour = ""; allDay = true; } // Get reccurrent dates Collection reccurenceDates = getRecurrenceDates(eventIcal); // No reccurent dates if (reccurenceDates == null) { String idEvent = isExist(eventIcal); // update if event already exists, create if does not exist if (StringUtil.isDefined(idEvent)) { agendaSessionController.updateJournal(idEvent, name, description, priority, classification, startDay, startHour, endDay, endHour); } else { idEvent = agendaSessionController.addJournal(name, description, priority, classification, startDay, startHour, endDay, endHour); } // Get Categories processCategories(eventIcal, idEvent); } else { for (Object reccurenceDate : reccurenceDates) { // Reccurent event startDate startDay = (DateTime) reccurenceDate; // Reccurent event endDate long newEndDay = startDay.getTime() + duration; endDay = new DateTime(newEndDay); if (allDay) { // So we have to convert this date to agenda format date GregorianCalendar gregCalendar = new GregorianCalendar(); gregCalendar.setTime(endDay); gregCalendar.add(GregorianCalendar.DATE, -1); endDay = new Date(gregCalendar.getTime()); } String idEvent = isExist(eventIcal, startDay, endDay, startHour); // update if event already exists, create if does not exist if (StringUtil.isDefined(idEvent)) { SilverTrace.debug("agenda", "ImportIcalManager.importIcalAgenda()", "root.MSG_GEN_PARAM_VALUE" + "Update event: " + DateUtil.date2SQLDate(startDay) + " " + startHour + " to " + DateUtil.date2SQLDate(endDay) + " " + endHour); agendaSessionController.updateJournal(idEvent, name, description, priority, classification, startDay, startHour, endDay, endHour); } else { SilverTrace.debug("agenda", "ImportIcalManager.importIcalAgenda()", "root.MSG_GEN_PARAM_VALUE" + "Create event: " + DateUtil.date2SQLDate(startDay) + " " + startHour + " to " + DateUtil.date2SQLDate(endDay) + " " + endHour); idEvent = agendaSessionController.addJournal(name, description, priority, classification, startDay, startHour, endDay, endHour); } // Get Categories processCategories(eventIcal, idEvent); } } } returnCode = AgendaSessionController.IMPORT_SUCCEEDED; } catch (Exception e) { SilverTrace.error("agenda", "ImportIcalManager.importIcalAgenda()", e.getCause().toString()); returnCode = AgendaSessionController.IMPORT_FAILED; } finally { IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(xr); } SilverTrace.debug("agenda", "ImportIcalManager.importIcalAgenda()", "root.MSG_GEN_EXIT_METHOD"); return returnCode; }
From source file:be.fedict.trust.xkms2.XKMSPortImpl.java
private Date getDate(XMLGregorianCalendar xmlCalendar) { GregorianCalendar calendar = new GregorianCalendar(xmlCalendar.getYear(), xmlCalendar.getMonth() - 1, xmlCalendar.getDay(), // xmlCalendar.getHour(), xmlCalendar.getMinute(), xmlCalendar.getSecond()); calendar.setTimeZone(xmlCalendar.getTimeZone(0)); return calendar.getTime(); }
From source file:org.silverpeas.core.web.calendar.ical.ImportIcalManager.java
/** * IMPORT SilverpeasCalendar in Ical format * @param file//w w w.j a va 2 s. c om * @return * @throws Exception */ public String importIcalAgenda(File file) throws Exception { String returnCode = AgendaSessionController.IMPORT_FAILED; InputStreamReader inputStream = null; XmlReader xr = null; try { String charsetUsed = agendaSessionController.getSettings().getString("defaultCharset"); if (isDefined(charset)) { charsetUsed = charset; } // File Encoding detection xr = new XmlReader(file); if (isDefined(xr.getEncoding())) { charsetUsed = xr.getEncoding(); } inputStream = new InputStreamReader(new FileInputStream(file), charsetUsed); CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = builder.build(inputStream); // Get all EVENTS for (Object o : calendar.getComponents(Component.VEVENT)) { VEvent eventIcal = (VEvent) o; String name = getFieldEvent(eventIcal.getProperty(Property.SUMMARY)); String description = null; if (isDefined(getFieldEvent(eventIcal.getProperty(Property.DESCRIPTION)))) { description = getFieldEvent(eventIcal.getProperty(Property.DESCRIPTION)); } // Name is mandatory in the Silverpeas Agenda if (!isDefined(name)) { if (isDefined(description)) { name = description; } else { name = " "; } } String priority = getFieldEvent(eventIcal.getProperty(Property.PRIORITY)); if (!isDefined(priority)) { priority = Priority.UNDEFINED.getValue(); } String classification = getFieldEvent(eventIcal.getProperty(Property.CLASS)); String startDate = getFieldEvent(eventIcal.getProperty(Property.DTSTART)); String endDate = getFieldEvent(eventIcal.getProperty(Property.DTEND)); Date startDay = getDay(startDate); String startHour = getHour(startDate); Date endDay = getDay(endDate); String endHour = getHour(endDate); // Duration of the event long duration = endDay.getTime() - startDay.getTime(); boolean allDay = false; // All day case // I don't know why ?? if (("00:00".equals(startHour) && "00:00".equals(endHour)) || (!isDefined(startHour) && !isDefined(endHour))) { // For complete Day startHour = ""; endHour = ""; allDay = true; } // Get reccurrent dates Collection reccurenceDates = getRecurrenceDates(eventIcal); // No reccurent dates if (reccurenceDates.isEmpty()) { String idEvent = isExist(eventIcal); // update if event already exists, create if does not exist if (isDefined(idEvent)) { agendaSessionController.updateJournal(idEvent, name, description, priority, classification, startDay, startHour, endDay, endHour); } else { idEvent = agendaSessionController.addJournal(name, description, priority, classification, startDay, startHour, endDay, endHour); } // Get Categories processCategories(eventIcal, idEvent); } else { for (Object reccurenceDate : reccurenceDates) { // Reccurent event startDate startDay = (DateTime) reccurenceDate; // Reccurent event endDate long newEndDay = startDay.getTime() + duration; endDay = new DateTime(newEndDay); if (allDay) { // So we have to convert this date to agenda format date GregorianCalendar gregCalendar = new GregorianCalendar(); gregCalendar.setTime(endDay); gregCalendar.add(GregorianCalendar.DATE, -1); endDay = new Date(gregCalendar.getTime()); } String idEvent = isExist(eventIcal, startDay, endDay, startHour); // update if event already exists, create if does not exist if (isDefined(idEvent)) { agendaSessionController.updateJournal(idEvent, name, description, priority, classification, startDay, startHour, endDay, endHour); } else { idEvent = agendaSessionController.addJournal(name, description, priority, classification, startDay, startHour, endDay, endHour); } // Get Categories processCategories(eventIcal, idEvent); } } } returnCode = AgendaSessionController.IMPORT_SUCCEEDED; } catch (Exception e) { SilverTrace.error("agenda", "ImportIcalManager.importIcalAgenda()", e.getCause().toString()); returnCode = AgendaSessionController.IMPORT_FAILED; } finally { IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(xr); } return returnCode; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ?2009-08-01/*from w w w . j av a2s.c o m*/ */ public static String addMonth(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(2, 1); // 2?1?(,) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:org.cesecore.util.PKIXCertRevocationStatusChecker.java
private boolean isCorrectCRL(final CRL crl, final String issuerDN) { if (!(crl instanceof X509CRL)) { return false; }//from w ww . ja v a2 s . c om X509CRL x509crl = (X509CRL) crl; if (!StringUtils.equals(issuerDN, CertTools.getIssuerDN(x509crl))) { return false; } final Date now = new Date(System.currentTimeMillis()); final Date nextUpdate = x509crl.getNextUpdate(); if (nextUpdate != null) { if (nextUpdate.after(now)) { return true; } if (log.isDebugEnabled()) { log.debug("CRL issued by " + issuerDN + " is out of date"); } return false; } final Date thisUpdate = x509crl.getThisUpdate(); if (thisUpdate != null) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(now); gc.add(Calendar.HOUR, 1); final Date expire = gc.getTime(); if (expire.before(now)) { if (log.isDebugEnabled()) { log.debug("Could not find when CRL issued by " + issuerDN + " should be updated and this CRL is over one hour old. Not using it"); } return false; } log.warn("Could not find when CRL issued by " + issuerDN + " should be updated, but this CRL was issued less than an hour ago, so we are using it"); return true; } if (log.isDebugEnabled()) { log.debug("Could not check issuance time for CRL issued by " + issuerDN); } return false; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ? ?2009-08-01/* w ww . j a v a2 s. c o m*/ */ public static String subMonth(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(2, -1); // 2?1?(,) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:org.eurekastreams.server.persistence.TabMapper.java
/** * Mark the input gadget as deleted so that it's no longer returned in queries but can be undeleted later on. The * gadget would have just been removed from the gadget, so we need to set the tabId back to the gadget so that it's * ignored by the collection./*w w w . java 2s. c o m*/ * * @param template * The TabTemplate that contains the gadget. * @param gadget * The gadget to mark as deleted. */ private void markGadgetAsDeleted(final TabTemplate template, final Gadget gadget) { GregorianCalendar currentDateTime = new GregorianCalendar(); entityManager .createQuery("update versioned Gadget set deleted = true, " + "dateDeleted = :deletedTimestamp, tabTemplateId = :tabTemplateId " + "where id = :gadgetId") .setParameter("deletedTimestamp", currentDateTime.getTime()) .setParameter("gadgetId", gadget.getId()).setParameter("tabTemplateId", template.getId()) .executeUpdate(); }