List of usage examples for java.util GregorianCalendar from
public static GregorianCalendar from(ZonedDateTime zdt)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime gregorianCalendarDateTime = new GregorianCalendar().toZonedDateTime(); GregorianCalendar gc = GregorianCalendar.from(gregorianCalendarDateTime); System.out.println(gc);/*from ww w . ja va 2s.c om*/ }
From source file:Main.java
public static void main(String[] argv) { Date dateFromInstant = Date.from(Instant.now()); System.out.println(dateFromInstant); java.util.TimeZone timeZone = java.util.TimeZone.getTimeZone(ZoneId.of("America/Los_Angeles")); System.out.println(timeZone); GregorianCalendar gregorianCalendar = GregorianCalendar.from(ZonedDateTime.now()); }
From source file:Main.java
public static void main(String[] args) { GregorianCalendar gc = new GregorianCalendar(2014, 1, 11, 15, 45, 50); LocalDate ld = gc.toZonedDateTime().toLocalDate(); System.out.println("Local Date: " + ld); LocalTime lt = gc.toZonedDateTime().toLocalTime(); System.out.println("Local Time: " + lt); LocalDateTime ldt = gc.toZonedDateTime().toLocalDateTime(); System.out.println("Local DateTime: " + ldt); OffsetDateTime od = gc.toZonedDateTime().toOffsetDateTime(); System.out.println("Offset Date: " + od); OffsetTime ot = gc.toZonedDateTime().toOffsetDateTime().toOffsetTime(); System.out.println("Offset Time: " + ot); ZonedDateTime zdt = gc.toZonedDateTime(); System.out.println("Zoned DateTime: " + zdt); ZoneId zoneId = zdt.getZone(); TimeZone timeZone = TimeZone.getTimeZone(zoneId); System.out.println("Zone ID: " + zoneId); System.out.println("Time Zone ID: " + timeZone.getID()); GregorianCalendar gc2 = GregorianCalendar.from(zdt); System.out.println("Gregorian Calendar: " + gc2.getTime()); }
From source file:com.bofa.sstradingreport.managementreport.TradeReportControllerTest.java
@Test public void shouldgetTradeReports() throws Exception { final List<TradeReportEntity> allbikes = Arrays.asList( Reflect.on(TradeReportEntity.class).create().set("id", 4711).set("name", "Bike 1") .set("tradeDate", GregorianCalendar.from( LocalDate.of(2015, Month.JANUARY, 1).atStartOfDay(ZoneId.systemDefault()))) .call("getTradeReport").get(), Reflect.on(TradeReportEntity.class).create().set("id", 23) .set("tradeDate", GregorianCalendar.from( LocalDate.of(2014, Month.JANUARY, 1).atStartOfDay(ZoneId.systemDefault()))) .call("getTradeReport").get()); final List<TradeReportEntity> activeBikes = Arrays.asList(allbikes.get(0)); final TradeReportRepository repository = mock(TradeReportRepository.class); stub(repository.findAll(any(Sort.class))).toReturn(allbikes); // stub(repository.findByDecaommissionedOnIsNull(any(Sort.class))).toReturn(activeBikes); final TradeReportController controller = new TradeReportController(repository); final MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller) .setControllerAdvice(new ExceptionHandlerAdvice()) .apply(documentationConfiguration(this.restDocumentation)).build(); mockMvc.perform(get("http://localhost:8088/sstradingreport/api/bikes").param("all", "true")) .andExpect(status().isOk()).andExpect(content().string(objectMapper.writeValueAsString(allbikes))) .andDo(document("api/bikes/get", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), requestParameters(parameterWithName("all").description( "Flag, if all bikes, including decommissioned bikes, should be returned.")), responseFields(fieldWithPath("[]").description("An array of bikes"), fieldWithPath("[].id").description("The unique Id of the bike"), fieldWithPath("[].name").description("The name of the bike"), fieldWithPath("[].tradeDate").description("The date the bike was bought")))); mockMvc.perform(get("http://biking.michael-simons.eu/api/bikes")).andExpect(status().isOk()) .andExpect(content().string(objectMapper.writeValueAsString(activeBikes))); Mockito.verify(repository).findAll(Mockito.any(Sort.class)); // Mockito.verify(repository).findByDecommissionedOnIsNull(Mockito.any(Sort.class)); verifyNoMoreInteractions(repository); }
From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java
public static Date toDate(LocalDateTime ldt) { ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault()); GregorianCalendar cal = GregorianCalendar.from(zdt); return cal.getTime(); }
From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java
/** * Create a new jaxb version of the session * /*from w w w . ja va2s.co m*/ * @param session * @return an version of the session use-able by jaxb */ private JAXBElement<SessionType> toSessionType(Session session) throws IOException { final ObjectFactory factory = new ObjectFactory(); final SessionType retVal = factory.createSessionType(); // header data retVal.setVersion("PB1.2"); retVal.setId(session.getName()); retVal.setCorpus(session.getCorpus()); final HeaderType headerData = factory.createHeaderType(); if (session.getMediaLocation() != null && session.getMediaLocation().length() > 0) { headerData.setMedia(session.getMediaLocation()); } final LocalDate date = (session.getDate() == null ? LocalDate.now() : session.getDate()); try { final DatatypeFactory df = DatatypeFactory.newInstance(); final XMLGregorianCalendar cal = df .newXMLGregorianCalendar(GregorianCalendar.from(date.atStartOfDay(ZoneId.systemDefault()))); cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED); headerData.setDate(cal); } catch (DatatypeConfigurationException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } final String lang = session.getLanguage(); if (lang != null && lang.length() > 0) { final String langs[] = lang.split("\\p{Space}"); for (String l : langs) { headerData.getLanguage().add(l); } } retVal.setHeader(headerData); final TranscriptType transcript = factory.createTranscriptType(); // commets for (int i = 0; i < session.getMetadata().getNumberOfComments(); i++) { final Comment c = session.getMetadata().getComment(i); final CommentType ct = copyComment(factory, c); transcript.getUOrComment().add(ct); } // participants final ParticipantsType parts = factory.createParticipantsType(); for (int i = 0; i < session.getParticipantCount(); i++) { final Participant part = session.getParticipant(i); final ParticipantType pt = copyParticipant(factory, part); parts.getParticipant().add(pt); } retVal.setParticipants(parts); // transcribers final TranscribersType tt = factory.createTranscribersType(); for (int i = 0; i < session.getTranscriberCount(); i++) { final Transcriber tr = session.getTranscriber(i); final TranscriberType trt = copyTranscriber(factory, tr); tt.getTranscriber().add(trt); } retVal.setTranscribers(tt); // tier info/ordering final UserTiersType utt = factory.createUserTiersType(); for (int i = 0; i < session.getUserTierCount(); i++) { final TierDescription td = session.getUserTier(i); final UserTierType tierType = copyTierDescription(factory, td); utt.getUserTier().add(tierType); } retVal.setUserTiers(utt); final TierOrderType tot = factory.createTierOrderType(); for (TierViewItem tvi : session.getTierView()) { final TvType tvt = copyTierViewItem(factory, tvi); tot.getTier().add(tvt); } retVal.setTierOrder(tot); // session data for (int i = 0; i < session.getRecordCount(); i++) { final Record record = session.getRecord(i); // insert comments first for (int j = 0; j < record.getNumberOfComments(); j++) { final Comment com = record.getComment(j); final CommentType ct = copyComment(factory, com); transcript.getUOrComment().add(ct); } // copy record data final RecordType rt = copyRecord(factory, retVal, record); rt.setId(record.getUuid().toString()); if (record.isExcludeFromSearches()) rt.setExcludeFromSearches(record.isExcludeFromSearches()); // setup participant if (record.getSpeaker() != null) { for (ParticipantType pt : parts.getParticipant()) { if (pt.getId().equals(record.getSpeaker().getId())) { rt.setSpeaker(pt); break; } } } transcript.getUOrComment().add(rt); } retVal.setTranscript(transcript); return factory.createSession(retVal); }
From source file:fi.vrk.xroad.catalog.lister.JaxbConverter.java
protected XMLGregorianCalendar toXmlGregorianCalendar(LocalDateTime localDateTime) { if (localDateTime == null) { return null; } else {/*from w w w.ja va 2 s .co m*/ GregorianCalendar cal = GregorianCalendar.from(localDateTime.atZone(ZoneId.systemDefault())); XMLGregorianCalendar xc = null; try { xc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); } catch (DatatypeConfigurationException e) { throw new CatalogListerRuntimeException("Cannot instantiate DatatypeFactory", e); } return xc; } }
From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java
/** * copy participant info//from w ww . j av a2s. c o m */ private ParticipantType copyParticipant(ObjectFactory factory, Participant part) { final ParticipantType retVal = factory.createParticipantType(); if (part.getId() != null) retVal.setId(part.getId()); retVal.setName(part.getName()); final LocalDate bday = part.getBirthDate(); if (bday != null) { try { final DatatypeFactory df = DatatypeFactory.newInstance(); final XMLGregorianCalendar cal = df .newXMLGregorianCalendar(GregorianCalendar.from(bday.atStartOfDay(ZoneId.systemDefault()))); cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED); retVal.setBirthday(cal); } catch (DatatypeConfigurationException e) { LOGGER.log(Level.WARNING, e.toString(), e); } } final Period age = part.getAge(null); if (age != null) { try { final DatatypeFactory df = DatatypeFactory.newInstance(); final Duration ageDuration = df.newDuration(true, age.getYears(), age.getMonths(), age.getDays(), 0, 0, 0); retVal.setAge(ageDuration); } catch (DatatypeConfigurationException e) { LOGGER.log(Level.WARNING, e.toString(), e); } } retVal.setEducation(part.getEducation()); retVal.setGroup(part.getGroup()); final String lang = part.getLanguage(); final String langs[] = (lang != null ? lang.split(",") : new String[0]); for (String l : langs) { retVal.getLanguage().add(StringUtils.strip(l)); } if (part.getSex() == Sex.MALE) retVal.setSex(SexType.MALE); else if (part.getSex() == Sex.FEMALE) retVal.setSex(SexType.FEMALE); ParticipantRole prole = part.getRole(); if (prole == null) prole = ParticipantRole.TARGET_CHILD; retVal.setRole(prole.toString()); // create ID based on role if possible if (retVal.getId() == null && prole != null) { if (prole == ParticipantRole.TARGET_CHILD) { retVal.setId("CHI"); } else if (prole == ParticipantRole.MOTHER) { retVal.setId("MOT"); } else if (prole == ParticipantRole.FATHER) { retVal.setId("FAT"); } else if (prole == ParticipantRole.INTERVIEWER) { retVal.setId("INT"); } else { retVal.setId("p" + (++pIdx)); } } retVal.setSES(part.getSES()); return retVal; }
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsNodeSyncImpl.java
/** * Set jcr:data property to a temporary binary for a rendition resource. * * @param resource Resource/*from w w w .j a v a 2 s . c om*/ * @param rawResponseLastModified String * @throws RepositoryException exception */ private void setNodeJcrDataProperty(final ResourceResolver remoteAssetsResolver, final Resource resource, final String rawResponseLastModified) throws RepositoryException { ValueMap resourceProperties = resource.adaptTo(ModifiableValueMap.class); // first checking to make sure existing resource has lastModified and jcr:data properties then seeing if binaries // should be updated based off of whether the resource's lastModified matches the JSON's lastModified if (resourceProperties.get(JcrConstants.JCR_LASTMODIFIED) != null && resourceProperties.get(JcrConstants.JCR_DATA) != null && StringUtils.isNotEmpty(rawResponseLastModified)) { String resourceLastModified = resourceProperties.get(JcrConstants.JCR_LASTMODIFIED, String.class); Calendar remoteLastModified = GregorianCalendar .from(ZonedDateTime.parse(rawResponseLastModified, DATE_TIME_FORMATTER)); ValueFactory valueFactory = remoteAssetsResolver.adaptTo(Session.class).getValueFactory(); if (resourceLastModified.equals(valueFactory.createValue(remoteLastModified).getString())) { LOG.debug("Not creating binary for resource '{}' because binary has not been updated.", resource.getPath()); return; } } InputStream inputStream = getRemoteAssetPlaceholder(resource); try { resourceProperties.put(JcrConstants.JCR_DATA, inputStream); LOG.debug("Binary added for resource '{}'.", resource.getPath()); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException ie) { LOG.error("IOException thrown {}", ie); } } }
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsNodeSyncImpl.java
/** * Set a simple resource property from the fetched JSON. * * @param value Object/*from www. j a va 2 s . c om*/ * @param key String * @param resource Resource * @throws RepositoryException exception */ private void setNodeSimpleProperty(final JsonPrimitive value, final String key, final Resource resource) throws RepositoryException { ValueMap resourceProperties = resource.adaptTo(ModifiableValueMap.class); if (value.isString() && DATE_REGEX.matcher(value.getAsString()).matches()) { try { resourceProperties.put(key, GregorianCalendar.from(ZonedDateTime.parse(value.getAsString(), DATE_TIME_FORMATTER))); } catch (DateTimeParseException e) { LOG.warn("Unable to parse date '{}' for property:resource '{}'.", value, key + ":" + resource.getPath()); } } else if (value.isString() && DECIMAL_REGEX.matcher(value.getAsString()).matches()) { resourceProperties.put(key, value.getAsBigDecimal()); } else if (value.isBoolean()) { resourceProperties.put(key, value.getAsBoolean()); } else if (value.isNumber()) { if (DECIMAL_REGEX.matcher(value.getAsString()).matches()) { resourceProperties.put(key, value.getAsBigDecimal()); } else { resourceProperties.put(key, value.getAsLong()); } } else if (value.isJsonNull()) { resourceProperties.remove(key); } else { resourceProperties.put(key, value.getAsString()); } LOG.trace("Property '{}' added for resource '{}'.", key, resource.getPath()); }