List of usage examples for org.joda.time DateTime getHourOfDay
public int getHourOfDay()
From source file:de.dmarcini.submatix.android4.full.comm.BlueThoothComService.java
License:Open Source License
/** * /* w ww. j a va 2s . c o m*/ * schreibe Datum und Zeit in das Gert * * Project: SubmatixBTLoggerAndroid Package: de.dmarcini.submatix.android4.comm * * * Stand: 27.10.2013 * * @param cf * @param dTime * @throws FirmwareNotSupportetException * */ public void writeDateTimeToDevice( SPX42Config cf, DateTime dTime ) throws FirmwareNotSupportetException { String kdoString; // // if( !cf.isFirmwareSupported() ) { Log.e( TAG, "firmware not supportet for write settings!" ); throw new FirmwareNotSupportetException( "write datetime to device" ); } if( cf.canSetDateTime() ) { // // Setze das Zeit und Datum als Kommandostring zusammen // kdoString = String.format( "%s~%x:%02x:%02x:%02x:%02x:%02x%s", ProjectConst.STX, ProjectConst.SPX_DATETIME, dTime.getHourOfDay(), dTime.getMinuteOfHour(), dTime.getDayOfMonth(), dTime.getMonthOfYear(), dTime.getYearOfCentury(), ProjectConst.ETX ); { if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "writeDateTimeToDevice()...send <" + kdoString + "> (DATETIME)" ); } this.writeToDevice( kdoString ); } else { if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "writeDateTimeToDevice()...Firmware not support <set datetime> yet" ); } }
From source file:de.dmarcini.submatix.android4.full.gui.SPX42ExportLogFragment.java
License:Open Source License
/** * /*from w w w. jav a2 s.co m*/ * Exportiere einen Eintrag in eigenem Thread * * Project: SubmatixBTLoggerAndroid Package: de.dmarcini.submatix.android4.full.gui * * Stand: 09.01.2014 * * @param rlo */ private void exportLogItemsAsThread( final Vector<ReadLogItemObj> lItems, File _tempDir ) { final Vector<ReadLogItemObj> rlos = new Vector<ReadLogItemObj>( lItems ); final File tempDir = _tempDir; Thread exportThread = null; // exportThread = new Thread() { @Override public void run() { UDDFFileCreateClass uddfClass = null; String uddfFileName = null; // try { // erzeuge eine Klasse zum generieren der Exort-UDDF-Files uddfClass = new UDDFFileCreateClass(); // // Lass dir einen Namen einfallen // if( rlos.size() == 0 ) { Log.e( TAG, "exportThread: not selected divelog in parameters found! ABORT EXPORT!" ); mHandler.obtainMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR, new BtServiceMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR ) ).sendToTarget(); return; } if( rlos.size() == 1 ) { if( ApplicationDEBUG.DEBUG ) Log.i( TAG, String.format( "exportThread: export dive %d db-id: %d...", rlos.firstElement().numberOnSPX, rlos.firstElement().dbId ) ); DateTime st = new DateTime( rlos.firstElement().startTimeMilis ); uddfFileName = String.format( Locale.ENGLISH, "%s%sdive_%07d_at_%04d%02d%02d%02d%02d%02d.uddf", tempDir.getAbsolutePath(), File.separator, rlos.firstElement().numberOnSPX, st.getYear(), st.getMonthOfYear(), st.getDayOfMonth(), st.getHourOfDay(), st.getMinuteOfHour(), st.getSecondOfMinute() ); } else { if( ApplicationDEBUG.DEBUG ) Log.i( TAG, String.format( "exportThread: export %d dives ...", rlos.size() ) ); DateTime st = new DateTime( rlos.firstElement().startTimeMilis ); uddfFileName = String.format( Locale.ENGLISH, "%s%sdive_%07d_at_%04d%02d%02d%02d%02d%02d-plus-%03d.uddf", tempDir.getAbsolutePath(), File.separator, rlos.firstElement().numberOnSPX, st.getYear(), st.getMonthOfYear(), st.getDayOfMonth(), st.getHourOfDay(), st.getMinuteOfHour(), st.getSecondOfMinute(), rlos.size() ); } // // erzeuge die XML... // if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "create uddf-file: <" + uddfFileName + ">" ); uddfClass.createXML( new File( uddfFileName ), mHandler, rlos, isFileZipped ); // // melde das Ende an den UI-Thread // mHandler.obtainMessage( ProjectConst.MESSAGE_LOCAL_LOGEXPORTED, new BtServiceMessage( ProjectConst.MESSAGE_LOCAL_LOGEXPORTED ) ).sendToTarget(); } catch( ParserConfigurationException ex ) { theToast.showConnectionToastAlert( ex.getLocalizedMessage() ); Log.e( TAG, ex.getLocalizedMessage() ); mHandler.obtainMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR, new BtServiceMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR ) ).sendToTarget(); return; } catch( TransformerException ex ) { theToast.showConnectionToastAlert( ex.getLocalizedMessage() ); Log.e( TAG, ex.getLocalizedMessage() ); mHandler.obtainMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR, new BtServiceMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR ) ).sendToTarget(); return; } catch( TransformerFactoryConfigurationError ex ) { theToast.showConnectionToastAlert( ex.getLocalizedMessage() ); Log.e( TAG, ex.getLocalizedMessage() ); mHandler.obtainMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR, new BtServiceMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR ) ).sendToTarget(); return; } catch( XMLFileCreatorException ex ) { theToast.showConnectionToastAlert( ex.getLocalizedMessage() ); Log.e( TAG, ex.getLocalizedMessage() ); mHandler.obtainMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR, new BtServiceMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR ) ).sendToTarget(); return; } catch( DOMException ex ) { theToast.showConnectionToastAlert( runningActivity.getResources().getString( R.string.toast_export_internal_xml_error ) ); Log.e( TAG, ex.getLocalizedMessage() ); mHandler.obtainMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR, new BtServiceMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR ) ).sendToTarget(); return; } catch( NoXMLDataFileFoundException ex ) { theToast.showConnectionToastAlert( runningActivity.getResources().getString( R.string.toast_export_cant_find_xmldata ) ); Log.e( TAG, ex.getLocalizedMessage() ); mHandler.obtainMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR, new BtServiceMessage( ProjectConst.MESSAGE_LOCAL_EXPORTERR ) ).sendToTarget(); return; } } }; exportThread.setName( "log_export_thread" ); exportThread.start(); }
From source file:de.dmarcini.submatix.android4.full.utils.UDDFFileCreateClass.java
License:Open Source License
/** * //from ww w . j ava 2s. com * Tauchgang Teilbaum bauen * * Project: SubmatixXMLTest Package: de.dmarcini.bluethooth.submatix.xml * * @author Dirk Marciniak (dirk_marciniak@arcor.de) * * Stand: 25.10.2011 * @param doc * Document Objekt * @param diveNumber * Nummer des Tauchganges in der Datenbank * @return Teilbaum Tauchgang * * TODO Swasser/Salzwasser Dichte eintragen (Datenbankfeld einrichten) * @throws NoXMLDataFileFoundException * @throws DOMException */ private Node makeDiveNode( Document doc, ReadLogItemObj rlo ) throws DOMException, NoXMLDataFileFoundException { Element diveNode, dateNode, yNode, mNode, dNode; Element timeNode, hNode, minNode; Element dnNode, atNode, ltNode, gdNode, deNode, noNode, txNode; String year, month, day, hour, minute; String temperature, lowesttemp; String greatestdepth; String density; // DateTime startDateTime = new DateTime( rlo.startTimeMilis ); day = String.format( Locale.ENGLISH, "%02d", startDateTime.getDayOfMonth() ); month = String.format( Locale.ENGLISH, "%02d", startDateTime.getMonthOfYear() ); year = String.format( Locale.ENGLISH, "%04d", startDateTime.getYear() ); hour = String.format( Locale.ENGLISH, "02d", startDateTime.getHourOfDay() ); minute = String.format( Locale.ENGLISH, "%02d", startDateTime.getMinuteOfHour() ); temperature = String.format( Locale.ENGLISH, "%.1f", rlo.firstTemp + ProjectConst.KELVIN ); lowesttemp = String.format( Locale.ENGLISH, "%.1f", rlo.lowTemp + ProjectConst.KELVIN ); greatestdepth = String.format( Locale.ENGLISH, "%.1f", rlo.maxDepth / 10.0f ); density = "1034.0"; diveNode = doc.createElement( "dive" ); diveNode.setAttribute( "id", String.format( "%d", rlo.numberOnSPX ) ); // # date dateNode = doc.createElement( "date" ); // ## date -> year yNode = doc.createElement( "year" ); yNode.appendChild( doc.createTextNode( year ) ); dateNode.appendChild( yNode ); // ## date -> month mNode = doc.createElement( "month" ); mNode.appendChild( doc.createTextNode( month ) ); dateNode.appendChild( mNode ); // ## date -> day dNode = doc.createElement( "day" ); dNode.appendChild( doc.createTextNode( day ) ); dateNode.appendChild( dNode ); diveNode.appendChild( dateNode ); // # time timeNode = doc.createElement( "time" ); // ## time -> hour hNode = doc.createElement( "hour" ); hNode.appendChild( doc.createTextNode( hour ) ); timeNode.appendChild( hNode ); // ## time -> minute minNode = doc.createElement( "minute" ); minNode.appendChild( doc.createTextNode( minute ) ); timeNode.appendChild( minNode ); diveNode.appendChild( timeNode ); // # divenumber dnNode = doc.createElement( "divenumber" ); dnNode.appendChild( doc.createTextNode( String.format( "%d", rlo.numberOnSPX ) ) ); diveNode.appendChild( dnNode ); // # airtemp atNode = doc.createElement( "airtemperature" ); atNode.appendChild( doc.createTextNode( temperature ) ); diveNode.appendChild( atNode ); // # lowesttemp ltNode = doc.createElement( "lowesttemperature" ); ltNode.appendChild( doc.createTextNode( lowesttemp ) ); diveNode.appendChild( ltNode ); // # greatestdepth gdNode = doc.createElement( "greatestdepth" ); gdNode.appendChild( doc.createTextNode( greatestdepth ) ); diveNode.appendChild( gdNode ); // # density deNode = doc.createElement( "density" ); deNode.appendChild( doc.createTextNode( density ) ); diveNode.appendChild( deNode ); // # notes noNode = doc.createElement( "notes" ); txNode = doc.createElement( "text" ); txNode.appendChild( doc.createTextNode( rlo.notes ) ); noNode.appendChild( txNode ); diveNode.appendChild( noNode ); // Teilbaum einhngen diveNode.appendChild( makeSamplesForDive( doc, rlo ) ); return( diveNode ); }
From source file:de.dmarcini.submatix.pclogger.comm.BTCommunication.java
License:Open Source License
@Override public void writeDateTimeToDevice(DateTime dTime) { String kdoString;/*ww w .j a v a 2 s .c om*/ // if (isConnected) { // // Setze das Zeit und Datum als Kommandostring zusammen // kdoString = String.format("%s~%x:%02x:%02x:%02x:%02x:%02x%s", ProjectConst.STX, ProjectConst.SPX_DATETIME, dTime.getHourOfDay(), dTime.getMinuteOfHour(), dTime.getDayOfMonth(), dTime.getMonthOfYear(), dTime.getYearOfCentury(), ProjectConst.ETX); { lg.debug("writeDateTimeToDevice()...send <" + kdoString + "> (DATETIME)"); } this.writeToDevice(kdoString); } }
From source file:de.raion.xmppbot.schedule.ScheduledCommandExecutor.java
License:Apache License
/** * calculates the initial delay out of the given parameters * * @param currentTimeInMillis time in ms to use for the calculation * @param time LocalTime representing Hour and Minute only * @return the initial delay calculated in ms *///from ww w.ja va 2s. co m protected Long calculateInitialDelay(Long currentTimeInMillis, LocalTime time) { DateTime currentTime = new DateTime(currentTimeInMillis); Long initialDelay = 0L; int currentHour = currentTime.getHourOfDay(); DateTime initialTime = new DateTime(currentTimeInMillis).withHourOfDay(time.getHourOfDay()) .withMinuteOfHour(time.getMinuteOfHour()).withSecondOfMinute(0); // next day if (currentHour > time.getHourOfDay()) { initialTime = initialTime.plusDays(1); } initialDelay = initialTime.getMillis() - currentTime.getMillis(); return initialDelay; }
From source file:divconq.lang.BigDateTime.java
License:Open Source License
/** * @param date translates into BigDateTime *//*from ww w . java 2s.c om*/ public BigDateTime(DateTime date) { if (date == null) return; // make sure we are using ISO and UTC date = date.toDateTime(ISOChronology.getInstanceUTC()); //date = date.toDateTime(DateTimeZone.UTC); this.year = 50000000000L + date.getYear(); // ISO says 1 BCE = 0, 2 BCE = -1, etc this.month = date.getMonthOfYear(); this.day = date.getDayOfMonth(); this.hour = date.getHourOfDay(); this.minute = date.getMinuteOfHour(); this.second = date.getSecondOfMinute(); }
From source file:dk.nsi.haiba.lprimporter.rules.LPRDateTimeRule.java
License:Open Source License
@Override public LPRRule doProcessing(Statistics statistics) { List<Administration> adjustedContacts = new ArrayList<Administration>(); // sort list after inDate, if more contacts have same in datetime - then they are sorted after out datetime. Collections.sort(contacts, new AdministrationInDateComparator()); for (Administration contact : contacts) { // Increment counter for rule #4 statistics.rule4Counter += 1;// ww w . j a v a 2 s. c o m // AdmissionStartHour for the contact is default set to 0 if not applied in the database, adjust it with the default value from the propertiesfile DateTime admissionStart = new DateTime(contact.getIndlaeggelsesDatetime()); if (admissionStart.getHourOfDay() == 0 && defaultContactInHour != 0) { admissionStart = admissionStart.withHourOfDay(defaultContactInHour); contact.setIndlaeggelsesDatetime(admissionStart.toDate()); } // AdmissionEndtime must be adjusted, if it was set to 0 Date udskrivningsDatetime = contact.getUdskrivningsDatetime(); if (udskrivningsDatetime != null) { DateTime admissionEnd = new DateTime(udskrivningsDatetime.getTime()); if (admissionEnd.getHourOfDay() == 0) { // does a procedure exist on the same date, set the procedure hour as admission end hour int hourOfDay = 0; for (LPRProcedure procedure : contact.getLprProcedures()) { DateTime procedureTime = new DateTime(procedure.getProcedureDatetime()); if (admissionEnd.getYear() == procedureTime.getYear() && admissionEnd.getMonthOfYear() == procedureTime.getMonthOfYear() && admissionEnd.getDayOfMonth() == procedureTime.getDayOfMonth()) { // examine all procedures from the same day, and get the latest hour of day. if (procedureTime.getHourOfDay() > hourOfDay) { hourOfDay = procedureTime.getHourOfDay(); } } } admissionEnd = admissionEnd.withHourOfDay(hourOfDay); } // Then if admissionEnd still is 0, check the in date time is the same day if (admissionEnd.getHourOfDay() == 0) { if (admissionEnd.getYear() == admissionStart.getYear() && admissionEnd.getMonthOfYear() == admissionStart.getMonthOfYear() && admissionEnd.getDayOfMonth() == admissionStart.getDayOfMonth()) { // if same date, set end-datetime to in-datetime + defaultvalue admissionEnd = admissionEnd.withHourOfDay(admissionStart.getHourOfDay()) .plusHours(defaultContactOuthoursAddedInhours); } } // Then if admissionEnd still is 0, and the enddate is after indate set it to a configured defaultvalue if (admissionEnd.getHourOfDay() == 0) { admissionEnd = admissionEnd.withHourOfDay(defaultAdmissionEndHours); } contact.setUdskrivningsDatetime(admissionEnd.toDate()); List<LPRProcedure> processedProcedures = new ArrayList<LPRProcedure>(); for (LPRProcedure procedure : contact.getLprProcedures()) { // if procedure time is set to 0 - set it to 12 the same day Date procedureDatetime = procedure.getProcedureDatetime(); if (procedureDatetime != null) { DateTime procedureDate = new DateTime(procedureDatetime.getTime()); // if procedureDate is more than 24 hours after admissionEndDate it is an error if (procedureDate.isAfter(admissionEnd.plusHours(24))) { BusinessRuleError be = new BusinessRuleError(contact.getLprReference().getDbId(), contact.getRecordNumber(), resolver.getMessage( "rule.datetime.proceduredate.is.more.than.24hous.after.enddate"), resolver.getMessage("rule.datetime.name")); businessRuleErrorLog.log(be); // error, procedure is deleted from the contact. continue; } if (procedureDate.getHourOfDay() == 0) { procedureDate = procedureDate.withHourOfDay(defaultProcedureHours); procedure.setProcedureDatetime(procedureDate.toDate()); } processedProcedures.add(procedure); } else { BusinessRuleError error = new BusinessRuleError(contact.getLprReference().getDbId(), contact.getRecordNumber(), resolver.getMessage("rule.datetime.proceduredate.isempty"), resolver.getMessage("rule.datetime.name")); throw new RuleAbortedException("Rule aborted due to BusinessRuleError", error); } } contact.setLprProcedures(processedProcedures); } else { // patient is currently at the hospital contact.setCurrentPatient(true); log.debug("Admission End datetime is null for LPR ref: " + contact.getRecordNumber() + " patient is probably not discharged from hospital yet"); // if in-date is not more than 30 days older than now - set out-date to today at 24:00 DateTime now = new DateTime(); DateTime in = new DateTime(contact.getIndlaeggelsesDatetime()); if (in.isAfter(now.minusDays(currentPatientDefaultInterval))) { DateTime out = in.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0) .plusHours(currentPatientHoursIfLessThanInterval); contact.setUdskrivningsDatetime(out.toDate()); } else { // else set out-date to in-date + 30 days DateTime out = in.plusDays(currentPatientDaysIfGreaterThanInterval); contact.setUdskrivningsDatetime(out.toDate()); } } // Rule #6 in time is after out time DateTime in = new DateTime(contact.getIndlaeggelsesDatetime()); DateTime out = new DateTime(contact.getUdskrivningsDatetime()); if (in.isAfter(out)) { // Increment counter for rule #6 statistics.rule6Counter += 1; // log the error and ignore the contact. BusinessRuleError be = new BusinessRuleError(contact.getLprReference().getDbId(), contact.getRecordNumber(), resolver.getMessage("rule.datetime.indate.isafter.outdate"), resolver.getMessage("rule.datetime.name")); businessRuleErrorLog.log(be); // Increment count for contacts with errors statistics.contactErrorCounter += 1; lprDao.updateImportTime(contact.getLprReference(), Outcome.FAILURE); continue; } adjustedContacts.add(contact); } // set this for unittesting purpose contacts = adjustedContacts; if (contacts.size() == 0) { log.debug("all contacts were prone to error, abort the flow"); return null; } // setup the next rule in the chain removeIdenticalContactsRule.setContacts(contacts); return removeIdenticalContactsRule; }
From source file:dk.teachus.backend.domain.impl.BookingsImpl.java
License:Apache License
public Booking getBooking(Period period, DateTime time) { Booking booking = null;//from w ww . j a v a 2 s .c om for (Booking foundBooking : bookings) { if (foundBooking.getPeriod().getId().equals(period.getId())) { DateTime dt1 = foundBooking.getDate(); DateTime dt2 = time; if (dt1.toDateMidnight().equals(dt2.toDateMidnight())) { if (dt1.getHourOfDay() == dt2.getHourOfDay() && dt1.getMinuteOfHour() == dt2.getMinuteOfHour()) { booking = foundBooking; break; } } } } return booking; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo.java
License:Open Source License
/** * This produces a map for use in the template. Will be using this b/c *///from w w w. jav a 2 s .c o m public Map getMapForTemplate(EditConfigurationVTwo editConfig, MultiValueEditSubmission editSub) { Map<String, Object> map = new HashMap<String, Object>(); //always need the fieldName, required precision, and constants map.put("fieldName", getFieldName()); addPrecisionConstants(map); map.put("minimumPrecision", minimumPrecision.uri()); map.put("requiredLevel", displayRequiredLevel.uri()); //Still expecting single precision uri not multiple String precisionUri = getPrecision(editConfig, editSub); VitroVocabulary.Precision existingPrec = toPrecision(precisionUri); if (precisionUri != null && !"".equals(precisionUri) && existingPrec == null) { if (!BLANK_SENTINEL.equals(precisionUri)) { log.debug("field " + getFieldName() + ": existing precision uri was " + "'" + precisionUri + "' but could not convert to Precision object"); } } if (precisionUri == null || precisionUri.isEmpty() || existingPrec == null) { map.put("existingPrecision", ""); /* no precision so there should also be no datetime */ DateTime value = getTimeValue(editConfig, editSub); if (value != null) log.debug("Unexpected state: Precision for " + getFieldName() + " was '" + precisionUri + "' but date time was " + value); map.put("year", ""); map.put("month", ""); map.put("day", ""); map.put("hour", ""); map.put("minute", ""); map.put("second", ""); } else if (VitroVocabulary.Precision.NONE.uri().equals(precisionUri)) { //bdc34: not sure what to do with the NONE precision map.put("existingPrecision", precisionUri); map.put("year", ""); map.put("month", ""); map.put("day", ""); map.put("hour", ""); map.put("minute", ""); map.put("second", ""); } else { map.put("existingPrecision", precisionUri); DateTime value = getTimeValue(editConfig, editSub); /* This is the case where there is a precision so there should be a datetime */ if (value == null) { //If there is no value, then this is an error condition log.error("Field " + getFieldName() + " has precision " + precisionUri + " but the date time value is null "); map.put("year", ""); map.put("month", ""); map.put("day", ""); map.put("hour", ""); map.put("minute", ""); map.put("second", ""); } else { /* only put the values in the map for ones which are significant based on the precision */ if (existingPrec.ordinal() >= VitroVocabulary.Precision.SECOND.ordinal()) map.put("second", Integer.toString(value.getSecondOfMinute())); else map.put("second", ""); if (existingPrec.ordinal() >= VitroVocabulary.Precision.MINUTE.ordinal()) map.put("minute", Integer.toString(value.getMinuteOfHour())); else map.put("minute", ""); if (existingPrec.ordinal() >= VitroVocabulary.Precision.HOUR.ordinal()) map.put("hour", Integer.toString(value.getHourOfDay())); else map.put("hour", ""); if (existingPrec.ordinal() >= VitroVocabulary.Precision.DAY.ordinal()) map.put("day", Integer.toString(value.getDayOfMonth())); else map.put("day", ""); if (existingPrec.ordinal() >= VitroVocabulary.Precision.MONTH.ordinal()) map.put("month", Integer.toString(value.getMonthOfYear())); else map.put("month", ""); if (existingPrec.ordinal() >= VitroVocabulary.Precision.YEAR.ordinal()) map.put("year", Integer.toString(value.getYear())); else map.put("year", ""); } } return map; }
From source file:edu.illinois.cs.cogcomp.temporal.normalizer.main.timex2interval.Period.java
License:Open Source License
/** * This function deals with a period of time with format the xxth day/month, etc * @param start the anchor time// ww w.j a v a 2 s . c om * @param temporalPhrase * @return */ public static TimexChunk Periodrule(DateTime start, TemporalPhrase temporalPhrase) { int year; DateTime finish; String temp1; String temp2; Interval interval; interval = new Interval(start, start); String phrase = temporalPhrase.getPhrase(); phrase = phrase.toLowerCase(); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd"); int modiword = 0;// 0 :no modified words 1:early,ealier 2:late,later // Handle some special cases TimexChunk tc = new TimexChunk(); tc.addAttribute(TimexNames.type, TimexNames.DATE); if (phrase.contains("now") || phrase.contains("currently") || phrase.contains("current") || phrase.contains("today")) { DateTime virtualStart = interval.getStart(); virtualStart = new DateTime(virtualStart.getYear(), virtualStart.getMonthOfYear(), virtualStart.getDayOfMonth(), virtualStart.getHourOfDay(), virtualStart.getMinuteOfHour(), virtualStart.getSecondOfMinute(), virtualStart.getMillisOfSecond() + 1); tc.addAttribute(TimexNames.value, TimexNames.PRESENT_REF); return tc; } if (phrase.contains("early") || phrase.contains("earlier")) { modiword = 1; } if (phrase.contains("late") || phrase.contains("later")) { modiword = 2; } String units = ""; for (String unitStr : dateUnitSet) { units = units + unitStr + "|"; } units += "s$"; String patternStr = "(?:the)?\\s*(\\d{1,4})(?:th|nd|st|rd)\\s*(" + units + ")\\s*"; Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(phrase); boolean matchFound = matcher.find(); if (matchFound) { temp1 = matcher.group(1); temp2 = matcher.group(2); String residual = StringUtils.difference(matcher.group(0), phrase); String anchorStr = ""; if (residual.length() > 0) { TemporalPhrase anchorPhrase = new TemporalPhrase(residual, temporalPhrase.getTense()); TimexChunk anchorTimex = TimexNormalizer.normalize(anchorPhrase); if (anchorTimex != null) { anchorStr = anchorTimex.getAttribute(TimexNames.value); } } if (temp2.equals("century")) { year = (Integer.parseInt(temp1) - 1) * 100; start = new DateTime(year, 1, 1, 0, 0, 0, 0); finish = new DateTime(year + 99, 12, 31, 23, 59, 59, 59); tc.addAttribute(TimexNames.value, String.valueOf(finish.getCenturyOfEra())); return tc; } else if (temp2.equals("decade")) { // e.g.: 3rd decade (of this century) // first we get this century is 20, then the 3rd decade is 203 int anchorCentury = start.getCenturyOfEra(); String val = String.valueOf(anchorCentury * 10 + temp1); tc.addAttribute(TimexNames.value, String.valueOf(val)); return tc; } else if (temp2.equals("year")) { int anchorCentury = start.getCenturyOfEra(); String val = String.valueOf(anchorCentury * 100 + temp1); tc.addAttribute(TimexNames.value, String.valueOf(val)); return tc; } else if (temp2.equals("quarter")) { int anchorYear = start.getYear(); String val = String.valueOf(anchorYear) + "-Q" + temp1; tc.addAttribute(TimexNames.value, String.valueOf(val)); return tc; } else if (temp2.equals("month")) { int anchorYear = start.getYear(); String monthStr = Integer.parseInt(temp1) < 10 ? "0" + temp1 : temp1; String val = String.valueOf(anchorYear) + "-" + monthStr; tc.addAttribute(TimexNames.value, String.valueOf(val)); return tc; } else if (temp2.equals("day")) { String val = ""; if (anchorStr.length() > 0) { List<String> normTimexList = Period.normTimexToList(anchorStr); String anchorYear = normTimexList.get(0); String anchorDate; String anchorMonth; if (normTimexList.size() == 1 || Integer.parseInt(temp1) > 31) { anchorMonth = "01"; } else { anchorMonth = normTimexList.get(1); } DateTime normDateTime = new DateTime(Integer.parseInt(anchorYear), Integer.parseInt(anchorMonth), 1, 0, 0); normDateTime = normDateTime.minusDays(-1 * Integer.parseInt(temp1)); anchorYear = String.valueOf(normDateTime.getYear()); anchorMonth = String.valueOf(normDateTime.getMonthOfYear()); anchorDate = String.valueOf(normDateTime.getDayOfMonth()); anchorMonth = anchorMonth.length() == 1 ? "0" + anchorMonth : anchorMonth; anchorDate = anchorDate.length() == 1 ? "0" + anchorDate : anchorDate; val = anchorYear + "-" + anchorMonth + "-" + anchorDate; } else { int month = Integer.parseInt(temp1) > 31 ? 1 : start.getMonthOfYear(); DateTime normDateTime = new DateTime(start.getYear(), month, 1, 0, 0); normDateTime = normDateTime.minusDays(-1 * Integer.parseInt(temp1)); String anchorYear = String.valueOf(normDateTime.getYear()); String anchorMonth = String.valueOf(normDateTime.getMonthOfYear()); String anchorDate = String.valueOf(normDateTime.getDayOfMonth()); anchorMonth = anchorMonth.length() == 1 ? "0" + anchorMonth : anchorMonth; anchorDate = anchorDate.length() == 1 ? "0" + anchorDate : anchorDate; val = String.valueOf(anchorYear) + "-" + anchorMonth + "-" + anchorDate; } tc.addAttribute(TimexNames.value, String.valueOf(val)); return tc; } else if (temp2.equals("s")) { if (Integer.parseInt(temp1) < 100) { year = start.getCenturyOfEra(); year = year * 100 + Integer.parseInt(temp1); if (modiword == 0) { tc.addAttribute(TimexNames.value, String.valueOf(year / 10)); } else if (modiword == 1) { tc.addAttribute(TimexNames.value, String.valueOf(year / 10)); tc.addAttribute(TimexNames.mod, TimexNames.START); } else if (modiword == 2) { tc.addAttribute(TimexNames.value, String.valueOf(year / 10)); tc.addAttribute(TimexNames.mod, TimexNames.END); } return tc; } else { if (modiword == 0) { start = new DateTime(Integer.parseInt(temp1), 1, 1, 0, 0, 0, 0); finish = new DateTime(Integer.parseInt(temp1) + 9, 12, 31, 23, 59, 59, 59); tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10)); } else if (modiword == 1) { start = new DateTime(Integer.parseInt(temp1), 1, 1, 0, 0, 0, 0); finish = new DateTime(Integer.parseInt(temp1) + 3, 12, 31, 23, 59, 59, 59); tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10)); tc.addAttribute(TimexNames.mod, TimexNames.START); } else if (modiword == 2) { start = new DateTime(Integer.parseInt(temp1) + 7, 1, 1, 0, 0, 0, 0); finish = new DateTime(Integer.parseInt(temp1) + 9, 12, 31, 23, 59, 59, 59); tc.addAttribute(TimexNames.value, String.valueOf(finish.getYear() / 10)); tc.addAttribute(TimexNames.mod, TimexNames.END); } return tc; } } } return null; }