List of usage examples for org.joda.time DateTime getSecondOfMinute
public int getSecondOfMinute()
From source file:controllers.Api.Statistic.java
License:Open Source License
public static Result getAccess() { // Variables/*w w w.j a v a2 s . com*/ Integer newValue, accessHour, yesterdayHour, index = 0; DateTime yesterdayDayTime, accessTime; // Yesterday Time Calc yesterdayDayTime = (new DateTime()).withZone(DateTimeZone.forID(session("timezone"))); //yesterdayDayTime = yesterdayDayTime.minusHours(24); yesterdayDayTime = yesterdayDayTime.minusHours(23).minusMinutes(yesterdayDayTime.getMinuteOfHour()) .minusSeconds(yesterdayDayTime.getSecondOfMinute()); yesterdayHour = yesterdayDayTime.getHourOfDay(); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); List<models.Access> accessDay = models.Access.find.where() .ge("timestamp", fmt.print(yesterdayDayTime.toDateTime(DateTimeZone.UTC))).order().asc("timestamp") .findList(); Iterator<models.Access> accessDayIterator = accessDay.iterator(); // 0 Liste initialisieren List<Integer> accessDayReturn = Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // Iterate List while (accessDayIterator.hasNext()) { models.Access access = accessDayIterator.next(); // Access Time Calc accessTime = access.timestamp; accessTime = accessTime.withZone(DateTimeZone.forID(session("timezone"))); accessHour = accessTime.getHourOfDay(); // Set value if (accessHour == yesterdayHour) { index = accessDayReturn.size() - 1; } else if (accessHour > yesterdayHour) { index = accessHour - yesterdayHour; } else if (accessHour < yesterdayHour) { index = (24 - (yesterdayHour - accessHour)) % 24; } newValue = accessDayReturn.get(index) + 1; accessDayReturn.set(index, newValue); } return ok(Json.toJson(accessDayReturn)); }
From source file:controllers.lib.Database.java
License:Open Source License
private static boolean executeCleanStatisticDay() throws Exception { // Early Date //Date checkDate = new Date(System.currentTimeMillis() - 25 * 3600 * 1000); DateTime checkDate = new DateTime(); checkDate = checkDate.minusHours(23).minusMinutes(checkDate.getMinuteOfHour()) .minusSeconds(checkDate.getSecondOfMinute()); List<StatisticDay> statisticDayList = StatisticDay.find.all(); Iterator<StatisticDay> statisticDayIterator = statisticDayList.iterator(); while (statisticDayIterator.hasNext()) { StatisticDay statisticDay = statisticDayIterator.next(); if (statisticDay.updateTime.isBefore(checkDate)) { statisticDay.delete();/* w ww . j a va 2 s . c o m*/ } } return true; }
From source file:course_generator.utils.Utils.java
License:Open Source License
/** * Compare two DateTime//from www .j ava 2s. co m * * @param t1 * First DateTime * @param t2 * Second DateTime * @return Return 0 if t1=t2 Return 1 if t1>t2 Return -1 if t1<t2 */ public static int CompareHMS(DateTime t1, DateTime t2) { int h1, h2, m1, m2, s1, s2; h1 = t1.getHourOfDay(); m1 = t1.getMinuteOfHour(); s1 = t1.getSecondOfMinute(); h2 = t2.getHourOfDay(); m2 = t2.getMinuteOfHour(); s2 = t2.getSecondOfMinute(); if ((h1 == h2) && (m1 == m2) && (s1 == s2)) return 0; if ((h1 > h2) || ((h1 == h2) && (m1 > m2)) || ((h1 == h2) && (m1 == m2) && (s1 > s2))) return 1; return -1; }
From source file:cron.DefaultCronExpression.java
License:Open Source License
@Override public boolean matches(DateTime t) { return second.contains(t.getSecondOfMinute()) && minute.contains(t.getMinuteOfHour()) && hour.contains(t.getHourOfDay()) && month.contains(t.getMonthOfYear()) && year.contains(t.getYear()) && dayOfWeek.matches(t) && dayOfMonth.matches(t); }
From source file:cz.muni.fi.pv168.frontend.EventForm.java
private Event getEventFromForm() { String eventName = jTextFieldFullname.getText(); if (eventName == null || eventName.isEmpty()) { warningMessageBox(Localization.getRbTexts().getString("name-null")); return null; }/*from ww w.j av a 2 s . co m*/ DateTime startDate = new DateTime(startDateDtp.getDate()); DateTime startDateTime = new DateTime(startDateSpinner.getValue()); LocalDateTime startTime = LocalDateTime.of(startDate.getYear(), startDate.getMonthOfYear(), startDate.getDayOfMonth(), startDateTime.getHourOfDay(), startDateTime.getMinuteOfHour(), startDateTime.getSecondOfMinute()); log.debug("SpinnerDateModel: " + startDateTime); DateTime endDate = new DateTime(endDateDtp.getDate()); DateTime endDateTime = new DateTime(endDateSpinner.getValue()); LocalDateTime endTime = LocalDateTime.of(endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth(), endDateTime.getHourOfDay(), endDateTime.getMinuteOfHour(), endDateTime.getSecondOfMinute()); log.debug("SpinnerDateModel: " + endDateTime); String description = jTextFieldDescription.getText(); if (description == null) { description = ""; } User user = context.getUserTableModel() .getUserByEmail((String) jComboBoxUsersInEventForm.getSelectedItem()); event.setEventName(eventName); event.setStartDate(startTime); event.setEndDate(endTime); event.setDescription(description); event.setUserId(user.getId()); log.debug("Category is" + (Category) jComboBoxCategory.getSelectedItem()); event.setCategory((Category) jComboBoxCategory.getSelectedItem()); return event; }
From source file:de.dmarcini.submatix.android4.full.gui.SPX42ExportLogFragment.java
License:Open Source License
/** * /* ww w. j av a 2 s.c om*/ * 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:divconq.lang.BigDateTime.java
License:Open Source License
/** * @param date translates into BigDateTime *///ww w . ja v a2 s. com 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: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 ww w.j a va 2 s.c om*/ 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//w ww. j a v a 2s .co m * @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; }
From source file:es.pode.adl.datamodels.datatypes.DateTimeValidator.java
License:Open Source License
/** * Compares two valid data model elements for equality. * //www. ja va 2s . co m * @param iFirst The first value being compared. * * @param iSecond The second value being compared. * * @param iDelimiters The common set of delimiters associated with the * values being compared. * * @return Returns <code>true</code> if the two values are equal, otherwise * <code>false</code>. */ public boolean compare(String iFirst, String iSecond, Vector iDelimiters) { boolean equal = true; DateTimeFormatter dtp = ISODateTimeFormat.dateTimeParser(); try { // Parse the first string and remove the sub-seconds DateTime dt1 = dtp.parseDateTime(iFirst); dt1 = new DateTime(dt1.getYear(), dt1.getMonthOfYear(), dt1.getDayOfMonth(), dt1.getHourOfDay(), dt1.getMinuteOfHour(), dt1.getSecondOfMinute(), 0); // Parse the second string and remove the sub-seconds DateTime dt2 = dtp.parseDateTime(iSecond); dt2 = new DateTime(dt2.getYear(), dt2.getMonthOfYear(), dt2.getDayOfMonth(), dt2.getHourOfDay(), dt2.getMinuteOfHour(), dt2.getSecondOfMinute(), 0); equal = dt1.equals(dt2); } catch (Exception e) { // String format error -- these cannot be equal equal = false; } return equal; }