List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:com.projity.server.data.MPXConverter.java
public static void toMpxCalendar(WorkingCalendar workCalendar, ProjectCalendar mpx) { mpx.setName(workCalendar.getName()); // mpx.setUniqueID((int) workCalendar.getId()); // TODO watch out for int overrun WorkingCalendar wc = workCalendar;/*from w w w .jav a 2 s .co m*/ if (workCalendar.isBaseCalendar()) wc = (WorkingCalendar) workCalendar.getBaseCalendar(); for (int i = 0; i < 7; i++) {// MPX days go from SUNDAY=1 to SATURDAY=7 WorkDay day = workCalendar.isBaseCalendar() ? workCalendar.getDerivedWeekDay(i) : workCalendar.getWeekDay(i); ProjectCalendarHours mpxDay = null; Day d = Day.getInstance(i + 1); if (day == null) { mpx.setWorkingDay(d, ProjectCalendar.DEFAULT); } else { mpx.setWorkingDay(d, day.isWorking()); if (day.isWorking()) { mpxDay = mpx.addCalendarHours(Day.getInstance(i + 1)); toMpxCalendarDay(day, mpxDay); } } } WorkDay[] workDays = workCalendar.getExceptionDays(); if (workDays != null) for (int i = 0; i < workDays.length; i++) { if (workDays[i] == null || workDays[i].getStart() == 0L || workDays[i].getStart() == Long.MAX_VALUE) continue; ProjectCalendarException exception = mpx.addCalendarException(); Date start = new Date(workDays[i].getStart()); exception.setFromDate(start); GregorianCalendar cal = DateTime.calendarInstance(); // days go from 00:00 to 23:59 cal.setTime(start); cal.set(Calendar.HOUR, 23); cal.set(Calendar.MINUTE, 59); exception.setToDate(DateTime.fromGmt(cal.getTime())); toMpxExceptionDay(workDays[i], exception); exception.setWorking(workDays[i].isWorking()); } WorkCalendar baseCalendar = workCalendar.getBaseCalendar(); if (baseCalendar != null) { mpx.setBaseCalendar(ImportedCalendarService.getInstance().findExportedCalendar(baseCalendar)); } //mpx.setUniqueID((int)workCalendar.getUniqueId()); }
From source file:org.ow2.petals.cloud.vacation.web.services.VacationClient.java
public String create(final String enquirer, final PendingVacationRequest newRequest) { assert enquirer != null; assert newRequest != null; final VacationRequestType request = new VacationRequestType(); request.setDayNumber(newRequest.getDayNumber()); request.setEnquirer(enquirer);/* w ww.j av a2s . co m*/ request.setReason(newRequest.getReason()); final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(newRequest.getStartDate()); request.setStartDate(dtf.newXMLGregorianCalendar(cal)); return ((NewVacationResponse) getWebServiceTemplate().marshalSendAndReceive( requestOF.createVacationRequest(request), new SoapActionCallback("http://petals.ow2.org/samples/se-bpmn/vacationService/newVacationRequest"))) .getVacationRequestId(); }
From source file:uk.ac.diamond.scisoft.analysis.io.ADSCImageTest.java
@Test public void testMetaDataDate() throws Exception { DataHolder loader = new ADSCImageLoader(TestFileFolder + testfile1).loadFile(); Dataset data = loader.getDataset(0); IExtendedMetadata metadata = (IExtendedMetadata) data.getMetadata(); Date date = metadata.getCreation(); SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy"); try {/* w ww . j a v a2 s . c o m*/ Assert.assertTrue(sdf.parse((String) metadata.getMetaValue("DATE")).equals(date)); } catch (Exception e) { throw new Exception("Could not parse the date from the header", e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTime(date); String[] parsedTime = gc.getTime().toString().split(" "); String[] rawTime = ((String) metadata.getMetaValue("DATE")).split(" "); Assert.assertTrue(parsedTime[0].equalsIgnoreCase(rawTime[0])); Assert.assertTrue(parsedTime[1].equalsIgnoreCase(rawTime[1])); Assert.assertTrue(parsedTime[2].equalsIgnoreCase(rawTime[2])); Assert.assertTrue(parsedTime[3].equalsIgnoreCase(rawTime[3])); Assert.assertTrue(parsedTime[5].equalsIgnoreCase(rawTime[4])); // This is because the date in GregorianCalendar contains GMT and the ADSC doesn't }
From source file:sample.S3EmitterWithMetadata.java
@Override public List<byte[]> emit(final UnmodifiableBuffer<byte[]> buffer) throws IOException { List<byte[]> records = buffer.getRecords(); // Write all of the records to a compressed output stream ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (byte[] record : records) { try {/*w w w . ja va 2 s . c o m*/ baos.write(record); } catch (Exception e) { LOG.error("Error writing record to output stream. Failing this emit attempt. Record: " + Arrays.toString(record), e); return buffer.getRecords(); } } // Get the Amazon S3 filename String s3FileName = getS3FileName(buffer.getFirstSequenceNumber(), buffer.getLastSequenceNumber()); String s3URI = getS3URI(s3FileName); try { ByteArrayInputStream object = new ByteArrayInputStream(baos.toByteArray()); LOG.debug("Starting upload of file " + s3URI + " to Amazon S3 containing " + records.size() + " records."); ObjectMetadata meta = new ObjectMetadata(); Date date = new Date(); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(Calendar.DATE, 14); meta.setExpirationTime(calendar.getTime()); meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); meta.setContentLength(baos.size()); s3client.putObject(s3Bucket, s3FileName, object, meta); LOG.info("Successfully emitted " + buffer.getRecords().size() + " records to Amazon S3 in " + s3URI); return Collections.emptyList(); } catch (Exception e) { LOG.error("Caught exception when uploading file " + s3URI + "to Amazon S3. Failing this emit attempt.", e); return buffer.getRecords(); } }
From source file:org.mule.transport.http.HttpResponseTestCase.java
private void validateDate(Date date) { GregorianCalendar cookieDate = new GregorianCalendar(); cookieDate.setTime(date); assertEquals(2014, cookieDate.get(GregorianCalendar.YEAR)); assertEquals(12, cookieDate.get(GregorianCalendar.DAY_OF_MONTH)); assertEquals(11, cookieDate.get(GregorianCalendar.MONTH)); }
From source file:cz.cas.lib.proarc.common.export.mets.MetsUtils.java
/** * Retuns an XMLGregorianCalendar representation of current date * * @return//from ww w . j av a 2 s.co m * @throws MetsExportException */ public static XMLGregorianCalendar getCurrentDate() throws MetsExportException { GregorianCalendar gregory = new GregorianCalendar(); gregory.setTime(new Date()); XMLGregorianCalendar calendar; try { calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregory); } catch (DatatypeConfigurationException e1) { throw new MetsExportException("Unable to create XMLGregorianDate", false, e1); } return calendar; }
From source file:edu.jhuapl.openessence.web.util.Filters.java
private Date muckDate(Date date, int prepull, String resolution, int calWeekStartDay) { GregorianCalendar x = new GregorianCalendar(); x.setTime(date); if (resolution != null && resolution.equals("weekly")) { x.add(Calendar.DATE, (-7 * prepull)); // make sure week starts on week start day defined // in message.properties or datasource groovy file while (x.get(Calendar.DAY_OF_WEEK) != calWeekStartDay) { x.add(Calendar.DATE, -1); }// w w w . ja va 2 s. c o m } else if (resolution != null && resolution.equals("monthly")) { x.set(Calendar.DAY_OF_MONTH, 1); } else if (resolution != null && resolution.equals("daily")) { x.add(Calendar.DATE, -prepull); } return x.getTime(); }
From source file:org.openanzo.rdf.datatype.TypeMaps.java
/** * Create an XML Calendar for the time in millis * /*from www .ja v a2 s . c o m*/ * @param millis * @return XML Calendar */ public static XMLGregorianCalendar getXMLCaledar(Date date) { GregorianCalendar cal = new GregorianCalendar(DateUtils.UTC_TIME_ZONE); cal.clear(); cal.setGregorianChange(MIN_DATE); cal.setTime(date); return TypeMaps.datatypeFactory.newXMLGregorianCalendar(cal); }
From source file:de.extra.client.core.builder.impl.plugins.DataSourceSingleInputDataPluginsBuilder.java
/** * Erstellt die SenderInformationen im Kontext von Header (non-Javadoc) * /* w w w. j a v a 2 s. co m*/ * @see de.extra.client.core.builder.IXmlComplexTypeBuilder#buildXmlFragment(de.extra.client.core.model.SenderDataBean, * de.extra.client.core.model.ExtraProfileConfiguration) */ @Override public Object buildXmlFragment(final IInputDataContainer senderData, final IExtraProfileConfiguration config) { Assert.notNull(senderData, "InputDataContainer is null"); final List<ISingleInputData> content = senderData.getContent(); // Hier wird vorerst nur eine InputData erwartet Assert.notEmpty(content, "Keine InputDaten vorhanden"); Assert.isTrue(content.size() == 1, "InputDataContainer beinhaltet mehr als 1 Element. Erwartet ist nur 1 Element"); final ISingleInputData iSingleInputData = content.get(0); final DataSource dataSource = new DataSource(); if (ISingleContentInputData.class.isAssignableFrom(iSingleInputData.getClass())) { final ISingleContentInputData singleContentInputData = ISingleContentInputData.class .cast(iSingleInputData); final DataSourcePluginDescription dataSourcePluginDescriptor = getDataSourcePluginDescriptor( singleContentInputData); if (dataSourcePluginDescriptor != null) { final DataContainerType dataContainer = new DataContainerType(); dataContainer.setName(dataSourcePluginDescriptor.getName()); dataSourcePluginDescriptor.getType(); dataContainer.setType(dataSourcePluginDescriptor.getType().getDataContainerCode()); // 27.12.2012 Die Semantik des Feldes ist unklar. Ist das // Erstellungsdatum des Files? final GregorianCalendar calenderCreated = new GregorianCalendar(); calenderCreated.setTime(dataSourcePluginDescriptor.getCreated()); dataContainer.setCreated(calenderCreated); dataContainer.setEncoding(dataSourcePluginDescriptor.getEncoding()); dataSource.setDataContainer(dataContainer); } } LOG.debug("DataSourcePlugin created."); return dataSource; }
From source file:net.sourceforge.subsonic.controller.JAXBWriter.java
public XMLGregorianCalendar convertDate(Date date) { if (date == null) { return null; }// ww w . j a v a 2 s .c om GregorianCalendar c = new GregorianCalendar(); c.setTime(date); return datatypeFactory.newXMLGregorianCalendar(c).normalize(); }