Example usage for java.util Calendar toString

List of usage examples for java.util Calendar toString

Introduction

In this page you can find the example usage for java.util Calendar toString.

Prototype

@Override
public String toString() 

Source Link

Document

Return a string representation of this calendar.

Usage

From source file:com.marklogic.client.functionaltest.TestJacksonDateTimeFormat.java

public void validateSpArtifactDateTimeObjMapper(SpArtifactDateTimeObjMapper artifact, String artifactName,
        long longId, Calendar datetime) {
    System.out.println("Argumnt : " + datetime.toString());
    System.out.println("Jackson POJO : " + artifact.getExpiryDate().toString());

    assertNotNull("Artifact object should never be Null", artifact);
    assertNotNull("Id should never be Null", artifact.id);
    assertEquals("Id of the object is ", longId, artifact.getId());
    assertEquals("Name of the object is ", artifactName, artifact.getName());
    assertEquals("Inventory of the object is ", 1000, artifact.getInventory());
    assertEquals("Company name of the object is ", artifactName, artifact.getManufacturer().getName());
    assertEquals("Web site of the object is ", "http://www.acme.com", artifact.getManufacturer().getWebsite());
    //Validate the calendar object's field, instead of object or string comparisions.
    assertEquals("Expiry date: MONTH ", datetime.get(Calendar.MONTH),
            artifact.getExpiryDate().get(Calendar.MONTH));
    assertEquals("Expiry date: DAY_OF_MONTH ", datetime.get(Calendar.DAY_OF_MONTH),
            artifact.getExpiryDate().get(Calendar.DAY_OF_MONTH));
    assertEquals("Expiry date: YEAR ", datetime.get(Calendar.YEAR),
            artifact.getExpiryDate().get(Calendar.YEAR));
    assertEquals("Expiry date: HOUR ", datetime.get(Calendar.HOUR),
            artifact.getExpiryDate().get(Calendar.HOUR));
    assertEquals("Expiry date: MINUTE ", datetime.get(Calendar.MINUTE),
            artifact.getExpiryDate().get(Calendar.MINUTE));
    assertEquals("Expiry date: SECOND ", datetime.get(Calendar.SECOND),
            artifact.getExpiryDate().get(Calendar.SECOND));
    assertEquals(-87.966, artifact.getManufacturer().getLongitude(), 0.00);
    assertEquals(41.998, artifact.getManufacturer().getLatitude(), 0.00);
}

From source file:org.hl7.fhir.client.ResourceAddress.java

public URI resolveGetHistoryForAllResources(Calendar since) {
    if (since == null)
        return baseServiceUri.resolve("_history");
    else//w w  w. j  av  a 2  s . c om
        return appendHttpParameter(baseServiceUri.resolve("_history"), "_since", since.toString());
}

From source file:br.com.bluesoft.pronto.dao.TicketDao.java

@SuppressWarnings("unchecked")
public List<TicketComentario> listarPorDataComentario(Date dataComentario) {
    log.info("Entrou TicketDao.listarPorDataComentario");
    final long data = dataComentario.getTime();
    final Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(data);/*from w  w  w  . ja  v  a  2 s .  c om*/
    log.info("Data pesquisada ==>> " + cal.toString());
    final StringBuilder builder = new StringBuilder();
    builder.append(" select distinct tc from TicketComentario tc");

    //colocar hora, min, seg e milis com valor 0 para incio do dia.
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 1);
    cal.set(Calendar.MILLISECOND, 0);
    Date dataInicial = cal.getTime();
    log.info("Data inicial ==>> " + dataInicial);

    //coloca hora, min, seg e milis para fim do dia.
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Date dataFinal = cal.getTime();
    log.info("Data final ==>> " + dataFinal);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

    builder.append(" where tc.data between :dataInicial and :dataFinal order by tc.data desc");

    //      builder.append(" where tc.data between " + sdf.format(dataInicial) + " and " + sdf.format(dataFinal));
    final Query query = getSession().createQuery(builder.toString());
    query.setParameter("dataInicial", dataInicial);
    query.setParameter("dataFinal", dataFinal);
    List result = query.list();
    log.info("Executou TicketDao.listarPorDataComentario qtde comentario do dia ==>> " + result.size());
    return result;
}

From source file:fr.inria.ucn.Helpers.java

/**
 * @param c/*from  w w w  .j  a  v a2 s  .  com*/
 * @return <code>True</code> if user has enabled the night-time mode and current time is
 * within night, else <code>False</code>.
 */
public static boolean isNightTime(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    if (!prefs.getBoolean(Constants.PREF_STOP_NIGHT, false))
        return false;

    int nstart = prefs.getInt(Constants.PREF_NIGHT_START, 23 * 3600);
    int nstop = prefs.getInt(Constants.PREF_NIGHT_STOP, 6 * 3600);

    Calendar nightstart = Calendar.getInstance();
    nightstart.roll(Calendar.HOUR_OF_DAY, -1 * nightstart.get(Calendar.HOUR_OF_DAY));
    nightstart.roll(Calendar.MINUTE, -1 * nightstart.get(Calendar.MINUTE));
    nightstart.roll(Calendar.SECOND, -1 * nightstart.get(Calendar.SECOND));
    nightstart.roll(Calendar.MILLISECOND, -1 * nightstart.get(Calendar.MILLISECOND));
    nightstart.add(Calendar.SECOND, nstart);

    Calendar nightstop = Calendar.getInstance();
    nightstop.roll(Calendar.HOUR_OF_DAY, -1 * nightstop.get(Calendar.HOUR_OF_DAY));
    nightstop.roll(Calendar.MINUTE, -1 * nightstop.get(Calendar.MINUTE));
    nightstop.roll(Calendar.SECOND, -1 * nightstop.get(Calendar.SECOND));
    nightstop.roll(Calendar.MILLISECOND, -1 * nightstop.get(Calendar.MILLISECOND));
    nightstop.add(Calendar.SECOND, nstop);
    if (nightstop.before(nightstart))
        nightstop.add(Calendar.HOUR, 24);

    Log.d(Constants.LOGTAG, "nightstart " + nstart + " -> " + nightstart.toString());
    Log.d(Constants.LOGTAG, "nightstop " + nstop + " -> " + nightstop.toString());

    Calendar now = Calendar.getInstance();
    return (now.after(nightstart) && now.before(nightstop));
}

From source file:fr.inria.ucn.Helpers.java

/**
 * /*from w w  w. java2  s.  com*/
 * @param c
 * @return -1 if not at night-time (or feature disabled), else milliseconds until morning.
 */
public static long getNightEnd(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    if (!prefs.getBoolean(Constants.PREF_STOP_NIGHT, false))
        return -1;

    int nstart = prefs.getInt(Constants.PREF_NIGHT_START, 23 * 3600);
    int nstop = prefs.getInt(Constants.PREF_NIGHT_STOP, 6 * 3600);

    Calendar nightstart = Calendar.getInstance();
    nightstart.roll(Calendar.HOUR_OF_DAY, -1 * nightstart.get(Calendar.HOUR_OF_DAY));
    nightstart.roll(Calendar.MINUTE, -1 * nightstart.get(Calendar.MINUTE));
    nightstart.roll(Calendar.SECOND, -1 * nightstart.get(Calendar.SECOND));
    nightstart.roll(Calendar.MILLISECOND, -1 * nightstart.get(Calendar.MILLISECOND));
    nightstart.add(Calendar.SECOND, nstart);

    Calendar nightstop = Calendar.getInstance();
    nightstop.roll(Calendar.HOUR_OF_DAY, -1 * nightstop.get(Calendar.HOUR_OF_DAY));
    nightstop.roll(Calendar.MINUTE, -1 * nightstop.get(Calendar.MINUTE));
    nightstop.roll(Calendar.SECOND, -1 * nightstop.get(Calendar.SECOND));
    nightstop.roll(Calendar.MILLISECOND, -1 * nightstop.get(Calendar.MILLISECOND));
    nightstop.add(Calendar.SECOND, nstop);
    if (nightstop.before(nightstart))
        nightstop.add(Calendar.HOUR, 24);

    Log.d(Constants.LOGTAG, "nightstart " + nstart + " -> " + nightstart.toString());
    Log.d(Constants.LOGTAG, "nightstop " + nstop + " -> " + nightstop.toString());

    Calendar now = Calendar.getInstance();
    if (now.after(nightstart) && now.before(nightstop)) {
        return nightstop.getTimeInMillis();
    } else {
        return -1;
    }
}

From source file:ubic.pubmedgate.resolve.MakeLexiconRDFModel.java

public void addDatesToModel(String dataStore, boolean useUnseenCorp) throws Exception {
    List<ConnectionsDocument> docs = getDataStoreDocs(dataStore, useUnseenCorp);

    GateInterface gateInt = new GateInterface(dataStore);
    for (ConnectionsDocument doc : docs) {
        String PMID = doc.getPMID();
        // for ( String PMID : PMIDs ) {
        // ConnectionsDocument doc = gateInt.getByPMID( PMID );
        Date date = doc.getPubDate();
        // check if it's in the RDF?

        Resource docResource = model.createResource(Vocabulary.getpubmedURIPrefix() + PMID);
        Calendar pubCal = Calendar.getInstance();
        pubCal.setTime(date);/*www .j  av  a2  s . co m*/

        docResource.addLiteral(Vocabulary.publication_date, pubCal);

        log.info(docResource.getURI() + "->" + pubCal.toString());
    }
    log.info(docs.size() + " abstracts labelled for species");
}

From source file:com.inmobi.databus.purge.DataPurgerService.java

private void getStreamsPathToPurge(Map<String, Path> streamPathMap) throws Exception {
    Set<Map.Entry<String, Path>> streamsToProcess = streamPathMap.entrySet();
    Iterator it = streamsToProcess.iterator();
    while (it.hasNext()) {
        Map.Entry<String, Path> entry = (Map.Entry<String, Path>) it.next();
        String streamName = entry.getKey();
        Path streamRootPath = entry.getValue();
        LOG.debug(// w w  w  .  java2s . co  m
                "Find Paths to purge for stream [" + streamName + "] streamRootPath [" + streamRootPath + "]");
        // For each Stream, all years
        FileStatus[] years = getAllFilesInDir(streamRootPath, fs);
        if (years != null) {
            for (FileStatus year : years) {
                // For each month
                FileStatus[] months = getAllFilesInDir(year.getPath(), fs);
                if (months != null && months.length >= 1) {
                    for (FileStatus month : months) {
                        // For each day
                        FileStatus[] days = getAllFilesInDir(month.getPath(), fs);
                        if (days != null && days.length >= 1) {
                            for (FileStatus day : days) {
                                // For each day
                                FileStatus[] hours = getAllFilesInDir(day.getPath(), fs);
                                if (hours != null && hours.length >= 1) {
                                    for (FileStatus hour : hours) {
                                        LOG.debug("Working for hour [" + hour.getPath() + "]");
                                        Calendar streamDate = CalendarHelper.getDateHour(
                                                year.getPath().getName(), month.getPath().getName(),
                                                day.getPath().getName(), hour.getPath().getName());
                                        LOG.debug("Validate [" + streamDate.toString()
                                                + "] against retentionHours [" + getRetentionPeriod(streamName)
                                                + "]");
                                        if (isPurge(streamDate, getRetentionPeriod(streamName))) {
                                            LOG.debug("Adding stream to purge [" + hour.getPath() + "]");
                                            streamsToPurge.add(hour.getPath().makeQualified(fs));
                                        }
                                    }
                                } else {
                                    // No hour found in day. Purge day
                                    streamsToPurge.add(day.getPath().makeQualified(fs));
                                }
                            } // each day
                        } else {
                            // No day found in month. Purge month
                            streamsToPurge.add(month.getPath().makeQualified(fs));
                        }
                    } // each month
                } else {
                    // no months found in year. Purge Year.
                    streamsToPurge.add(year.getPath().makeQualified(fs));
                }
            } // each year
        }
    } // each stream
}

From source file:org.apache.camel.component.olingo2.api.Olingo2AppIntegrationTest.java

@Test
public void testReadUpdateProperties() throws Exception {
    // test simple property Manufacturer.Founded
    final TestOlingo2ResponseHandler<Map<String, Object>> propertyHandler = new TestOlingo2ResponseHandler<Map<String, Object>>();

    olingoApp.read(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY, null, propertyHandler);

    Calendar founded = (Calendar) propertyHandler.await().get(FOUNDED_PROPERTY);
    LOG.info("Founded property {}", founded.toString());

    final TestOlingo2ResponseHandler<Calendar> valueHandler = new TestOlingo2ResponseHandler<Calendar>();

    olingoApp.read(edm, TEST_MANUFACTURER_FOUNDED_VALUE, null, valueHandler);

    founded = valueHandler.await();//from  w  w  w .j a v a2  s. com
    LOG.info("Founded property {}", founded.toString());

    final TestOlingo2ResponseHandler<HttpStatusCodes> statusHandler = new TestOlingo2ResponseHandler<HttpStatusCodes>();
    final HashMap<String, Object> properties = new HashMap<String, Object>();
    properties.put(FOUNDED_PROPERTY, new Date());

    //        olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY, properties, statusHandler);
    // requires a plain Date for XML
    olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY, new Date(), statusHandler);

    LOG.info("Founded property updated with status {}", statusHandler.await().getStatusCode());

    statusHandler.reset();

    olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_VALUE, new Date(), statusHandler);

    LOG.info("Founded property updated with status {}", statusHandler.await().getStatusCode());

    // test complex property Manufacturer.Address
    propertyHandler.reset();

    olingoApp.read(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY, null, propertyHandler);

    final Map<String, Object> address = propertyHandler.await();
    LOG.info("Address property {}", prettyPrint(address, 0));

    statusHandler.reset();

    address.clear();
    // Olingo2 sample server MERGE/PATCH behaves like PUT!!!
    //        address.put("Street", "Main Street");
    address.put("Street", "Star Street 137");
    address.put("City", "Stuttgart");
    address.put("ZipCode", "70173");
    address.put("Country", "Germany");

    //        olingoApp.patch(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY, address, statusHandler);
    olingoApp.merge(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY, address, statusHandler);

    LOG.info("Address property updated with status {}", statusHandler.await().getStatusCode());
}

From source file:com.inmobi.conduit.purge.DataPurgerService.java

private void getStreamsPathToPurge(Map<String, Path> streamPathMap, boolean isLocal) throws Exception {
    Set<Map.Entry<String, Path>> streamsToProcess = streamPathMap.entrySet();
    Iterator it = streamsToProcess.iterator();
    while (it.hasNext()) {
        Map.Entry<String, Path> entry = (Map.Entry<String, Path>) it.next();
        String streamName = entry.getKey();
        Path streamRootPath = entry.getValue();
        String tableName = null;//from  w  w  w  .jav  a  2 s.com
        if (isLocal) {
            tableName = LOCAL_TABLE_PREFIX + "_" + streamName;
        } else {
            tableName = TABLE_PREFIX + "_" + streamName;
        }
        LOG.debug(
                "Find Paths to purge for stream [" + streamName + "] streamRootPath [" + streamRootPath + "]");
        // For each Stream, all years
        FileStatus[] years = getAllFilesInDir(streamRootPath, fs);
        if (years != null) {
            for (FileStatus year : years) {
                String yearVal = year.getPath().getName();
                // For each month
                FileStatus[] months = getAllFilesInDir(year.getPath(), fs);
                if (months != null && months.length >= 1) {
                    for (FileStatus month : months) {
                        String monthVal = month.getPath().getName();
                        // For each day
                        FileStatus[] days = getAllFilesInDir(month.getPath(), fs);
                        if (days != null && days.length >= 1) {
                            for (FileStatus day : days) {
                                String dayVal = day.getPath().getName();
                                // For each day
                                FileStatus[] hours = getAllFilesInDir(day.getPath(), fs);
                                if (hours != null && hours.length >= 1) {
                                    for (FileStatus hour : hours) {
                                        LOG.debug("Working for hour [" + hour.getPath() + "]");

                                        String hourVal = hour.getPath().getName();
                                        Calendar streamDate = CalendarHelper.getDateHour(yearVal, monthVal,
                                                dayVal, hourVal);
                                        LOG.debug("Validate [" + streamDate.toString()
                                                + "] against retentionHours [" + getRetentionPeriod(streamName)
                                                + "]");
                                        if (isPurge(streamDate, getRetentionPeriod(streamName))) {
                                            LOG.debug("Adding stream to purge [" + hour.getPath() + "]");
                                            Path hourPath = hour.getPath().makeQualified(fs);
                                            addPartitionToList(streamName, tableName, hourPath, yearVal,
                                                    monthVal, dayVal, hourVal);
                                            streamsToPurge.add(hourPath);
                                        }
                                    }
                                } else {
                                    Path dayPath = day.getPath().makeQualified(fs);
                                    // No hour found in day. Purge day
                                    addPartitionToList(streamName, tableName, dayPath, yearVal, monthVal,
                                            dayVal);
                                    streamsToPurge.add(dayPath);
                                }
                            } // each day
                        } else {
                            // No day found in month. Purge month
                            Path monthPath = month.getPath().makeQualified(fs);
                            addPartitionToList(streamName, tableName, monthPath, yearVal, monthVal);
                            streamsToPurge.add(monthPath);
                        }
                    } // each month
                } else {
                    // no months found in year. Purge Year.
                    Path yearPath = year.getPath().makeQualified(fs);
                    addPartitionToList(streamName, tableName, yearPath, yearVal);
                    streamsToPurge.add(year.getPath().makeQualified(fs));
                }
            } // each year
        }
    } // each stream
}

From source file:fr.paris.lutece.plugins.workflow.modules.appointment.service.ICalService.java

/**
 * Send an appointment to a user by email.
 * @param strEmailAttendee Comma separated list of users that will attend
 *            the appointment/*from   w w  w. ja v  a  2  s  .  c om*/
 * @param strEmailOptionnal Comma separated list of users that will be
 *            invited to the appointment, but who are not required.
 * @param strSubject The subject of the appointment.
 * @param strBodyContent The body content that describes the appointment
 * @param strLocation The location of the appointment
 * @param strSenderName The name of the sender
 * @param strSenderEmail The email of the sender
 * @param appointment The appointment
 * @param bCreate True to notify the creation of the appointment, false to
 *            notify its removal
 */
public void sendAppointment(String strEmailAttendee, String strEmailOptionnal, String strSubject,
        String strBodyContent, String strLocation, String strSenderName, String strSenderEmail,
        Appointment appointment, boolean bCreate) {

    AppointmentSlot slot = AppointmentSlotHome.findByPrimaryKey(appointment.getIdSlot());
    Calendar calendarStart = new GregorianCalendar(Locale.FRENCH);

    calendarStart.setTime(appointment.getDateAppointment());
    calendarStart.add(Calendar.HOUR, slot.getStartingHour());
    calendarStart.add(Calendar.MINUTE, slot.getStartingMinute());

    int nAppDurationMinutes = ((slot.getEndingHour() - slot.getStartingHour()) * 60)
            + (slot.getEndingMinute() - slot.getStartingMinute());
    int nDurationAppointmentHours = nAppDurationMinutes / 60;
    int nDurationAppointmentMinutes = nAppDurationMinutes % 60;

    int nDurationAppointmentDays = nDurationAppointmentHours / 24;
    nDurationAppointmentHours %= 24;

    //       Dur duration = new Dur( nDurationAppointmentDays, nDurationAppointmentHours, nDurationAppointmentMinutes, 0 );

    //        TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    //        TimeZone timezone = registry.getTimeZone("Europe/Paris");

    DateTime beginningDateTime = new DateTime(calendarStart.getTimeInMillis());
    beginningDateTime.setTimeZone(getParisZone());

    Calendar endCal = new GregorianCalendar();
    endCal.setTimeInMillis(calendarStart.getTimeInMillis());
    endCal.add(Calendar.MINUTE, nAppDurationMinutes);

    DateTime endingDateTime = new DateTime(endCal.getTimeInMillis());
    endingDateTime.setTimeZone(getParisZone());

    VEvent event = new VEvent(beginningDateTime, endingDateTime,
            (strSubject != null) ? strSubject : StringUtils.EMPTY);

    calendarStart.add(Calendar.MINUTE, nAppDurationMinutes);

    //  event.getProperties(  ).add( new DtEnd( endingDateTime ) );

    try {
        event.getProperties()
                .add(new Uid(Appointment.APPOINTMENT_RESOURCE_TYPE + appointment.getIdAppointment()));

        String strEmailSeparator = AppPropertiesService.getProperty(PROPERTY_MAIL_LIST_SEPARATOR, ";");
        if (StringUtils.isNotEmpty(strEmailAttendee)) {
            StringTokenizer st = new StringTokenizer(strEmailAttendee, strEmailSeparator);

            while (st.hasMoreTokens()) {
                addAttendee(event, st.nextToken(), true);
            }
        }

        if (StringUtils.isNotEmpty(strEmailOptionnal)) {
            StringTokenizer st = new StringTokenizer(strEmailOptionnal, strEmailSeparator);

            while (st.hasMoreTokens()) {
                addAttendee(event, st.nextToken(), false);
            }
        }

        Organizer organizer = new Organizer(strSenderEmail);
        organizer.getParameters().add(new Cn(strSenderName));
        event.getProperties().add(organizer);
        event.getProperties().add(new Location(strLocation));
        event.getProperties().add(new Description(strBodyContent));
    } catch (URISyntaxException e) {
        AppLogService.error(e.getMessage(), e);
    }

    net.fortuna.ical4j.model.Calendar iCalendar = new net.fortuna.ical4j.model.Calendar();
    iCalendar.getProperties().add(bCreate ? Method.REQUEST : Method.CANCEL);
    iCalendar.getProperties().add(new ProdId(AppPropertiesService.getProperty(PROPERTY_ICAL_PRODID)));
    iCalendar.getProperties().add(Version.VERSION_2_0);
    iCalendar.getProperties().add(CalScale.GREGORIAN);

    iCalendar.getComponents().add(event);

    MailService.sendMailCalendar(strEmailAttendee, strEmailOptionnal, null, strSenderName, strSenderEmail,
            (strSubject != null) ? strSubject : StringUtils.EMPTY, strBodyContent, iCalendar.toString(),
            bCreate);
}