List of usage examples for java.time LocalDate atStartOfDay
public ZonedDateTime atStartOfDay(ZoneId zone)
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 v a 2s. c om*/ * @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:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
private Date convertToDate(LocalDate localDate) { return Date.from(localDate.atStartOfDay(ZONE_ID).toInstant()); }
From source file:nu.yona.server.analysis.service.ActivityService.java
private <T extends IntervalActivityDto> T getMissingInactivity(UUID userId, LocalDate date, UUID goalId, UserAnonymizedDto userAnonymized, ChronoUnit timeUnit, BiFunction<Goal, ZonedDateTime, T> inactivityEntitySupplier) { Goal goal = goalService.getGoalEntityForUserAnonymizedId(userAnonymized.getId(), goalId); ZonedDateTime dateAtStartOfInterval = date.atStartOfDay(userAnonymized.getTimeZone()); if (!goal.wasActiveAtInterval(dateAtStartOfInterval, timeUnit)) { throw ActivityServiceException.activityDateGoalMismatch(userId, date, goalId); }//from ww w .j a v a2 s .co m return inactivityEntitySupplier.apply(goal, dateAtStartOfInterval); }
From source file:org.pentaho.hadoop.shim.common.format.avro.AvroNestedReader.java
/** * Perform Kettle type conversions for the Avro leaf field value. * * @param fieldValue the leaf value from the Avro structure * @return an Object of the appropriate Kettle type * @throws KettleException if a problem occurs */// w w w . j a v a 2s. co m protected Object getKettleValue(AvroInputField avroInputField, Object fieldValue) throws KettleException { switch (avroInputField.getTempValueMeta().getType()) { case ValueMetaInterface.TYPE_BIGNUMBER: return avroInputField.getTempValueMeta().getBigNumber(fieldValue); case ValueMetaInterface.TYPE_BINARY: return avroInputField.getTempValueMeta().getBinary(fieldValue); case ValueMetaInterface.TYPE_BOOLEAN: return avroInputField.getTempValueMeta().getBoolean(fieldValue); case ValueMetaInterface.TYPE_DATE: if (avroInputField.getAvroType().getBaseType() == AvroSpec.DataType.INTEGER.getBaseType()) { LocalDate localDate = LocalDate.ofEpochDay(0).plusDays((Long) fieldValue); return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } else if (avroInputField.getAvroType().getBaseType() == AvroSpec.DataType.STRING.getBaseType()) { Object pentahoData = null; String dateFormatStr = avroInputField.getStringFormat(); if ((dateFormatStr == null) || (dateFormatStr.trim().length() == 0)) { dateFormatStr = ValueMetaBase.DEFAULT_DATE_FORMAT_MASK; } SimpleDateFormat datePattern = new SimpleDateFormat(dateFormatStr); try { return datePattern.parse(fieldValue.toString()); } catch (Exception e) { return null; } } return avroInputField.getTempValueMeta().getDate(fieldValue); case ValueMetaInterface.TYPE_TIMESTAMP: return new Timestamp((Long) fieldValue); case ValueMetaInterface.TYPE_INTEGER: return avroInputField.getTempValueMeta().getInteger(fieldValue); case ValueMetaInterface.TYPE_NUMBER: return avroInputField.getTempValueMeta().getNumber(fieldValue); case ValueMetaInterface.TYPE_STRING: return avroInputField.getTempValueMeta().getString(fieldValue); case ValueMetaInterface.TYPE_INET: try { return InetAddress.getByName(fieldValue.toString()); } catch (UnknownHostException ex) { return null; } default: return null; } }